快速结论:该报错通常出现在 AutoGen 对话任务完成或助手返回内容后,UserProxyAgent 仍尝试走 LLM 回复链路时;优先检查是否为 UserProxyAgent 误传了 llm_config。Issue 中提问者按维护者建议移除该参数后,报错消失。
适用环境:Issue 中可见的环境线索为 Windows(路径位于 C:\Users\...)、Anaconda 环境(anaconda3\envs\auto_gen),使用 AutoGen 的 UserProxyAgent、initiate_chat 与 code_execution_config。Issue 未提供 Python、CUDA、显卡等版本信息,无需据此排查。
最快修复方案:若 UserProxyAgent 不需要基于 LLM 的回复,移除其构造函数中的 llm_config。Issue 中原提问者确认该方法生效:报错消失。
注意事项:Issue 中另一位用户尝试把 default_reply 设为非空字符串,但未解决问题;原提问者实际仍使用 default_auto_reply。移除 llm_config 后,UserProxy 不再生成 LLM 回复;当收到的消息里没有代码时,它会使用 default_auto_reply。原提问者移除后还遇到了两个助手相互发送相同代码的循环,需要另行约束对话或终止条件。
问题场景
用户在 AutoGen 中通过 user_proxy.initiate_chat(...) 发起任务,并给 UserProxyAgent 配置了 llm_config、code_execution_config 和 default_auto_reply。有时在助手尚未完成任务、正在写 Python 代码时触发;有时任务已经完成并返回结果后触发该错误。Issue 中可见的复现任务是用 UserProxy 向 assistant 请求 5 个 SMMA 获客相关的公司名。
报错原文
AttributeError: 'str' object has no attribute 'get' after the task is finished
调用栈关键片段如下:
File "...\autogen\agentchat\conversable_agent.py", line 781, in generate_reply
final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
File "...\autogen\agentchat\conversable_agent.py", line 606, in generate_oai_reply
response = oai.ChatCompletion.create(
...
File "...\openai\api_requestor.py", line 428, in handle_error_response
error_code=error_data.get("code"),
^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'
原因分析
从调用栈看,异常最终发生在 OpenAI 请求/响应错误处理路径:代码对 error_data 调用了 .get("code"),但此时该对象是字符串,因此抛出 AttributeError: 'str' object has no attribute 'get'。
结合 Issue 讨论,更直接的配置诱因是:UserProxyAgent 被传入了 llm_config,从而可能进入 LLM 回复路径。维护者询问“是否打算让 user proxy agent 使用基于 LLM 的回复”,并明确建议:如果不是,请从其构造参数中移除 llm_config。原提问者验证移除后报错消失。至于底层为何把错误数据当成字符串处理,Issue 中未给出进一步源码结论,这里不展开推测。
环境排查
- 确认是否在
UserProxyAgent(...)中传入了llm_config;这是本 Issue 的核心排查点。 - 确认该 AutoGen 版本中
conversable_agent.py的generate_reply、generate_oai_reply及oai/completion.py调用路径,与 Issue 调用栈是否一致。 - 检查 OpenAI 请求是否实际失败并进入错误处理分支;调用栈显示异常发生在
handle_error_response,但 Issue 未给出上游 HTTP 状态或错误体内容。 - 确认实际有效的自动回复参数是
default_auto_reply还是default_reply。Issue 中维护者提到的是default_reply,但原提问者的代码和最终回复中使用的是default_auto_reply。 - Issue 未提供可依赖的 Python、CUDA、PyTorch、显卡或依赖版本信息,无法按版本匹配已知缺陷。
解决步骤
- 打开创建
user_proxy的代码,检查UserProxyAgent构造函数。 - 如果不需要 UserProxy 用 LLM 生成回复,删除
llm_config=llm_config这一项。 - 保留与代码执行和自动回复相关的配置。Issue 中提问者的配置包含
human_input_mode="NEVER"、default_auto_reply="default_auto_reply"、max_consecutive_auto_reply=10、code_execution_config={"work_dir": "result"}。 - 重新运行原先会报错的
initiate_chat任务。 - 如果移除后出现两个助手反复发送相同代码的情况,这是 Issue 中确认会出现的后续现象,需要检查对话终止条件、最大自动回复次数,或调整谁负责执行代码。
验证方法
在相同任务下重新运行,确认任务完成后不再出现 AttributeError: 'str' object has no attribute 'get'。Issue 中原提问者在移除 UserProxyAgent 的 llm_config 后确认“the error is gone”。同时观察 UserProxy 是否按预期使用 default_auto_reply,而不是继续走 LLM 回复。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。
![[bug]: makeHrefToId returns the base path as a page id for the homepage link under a deployment base](https://www.chat-gpts.plus/wp-content/uploads/2026/11/10255-a795918a-768x403.jpg)

