Open
【Bug】Agent 承载模式下 assemble_agent_result.py 未装 requests 时无法启动:planner.py 顶层导入 llm 导致 ModuleNotFoundError,与「不调用 llm.py」自述矛盾 #162
gcw_SCZlHohJAdd on  3 days ago
gcw_SCZlHohJ
gcw_SCZlHohJ
3 days ago Create

问题描述:
在未安装 requests 的全新 Python 环境中,按 README「形态 ② Agent 承载」操作,运行 python scripts/assemble_agent_result.py --help(或 --input/--output)直接崩溃:
Traceback (most recent call last):
File "scripts/assemble_agent_result.py", line 22, in
from planner import ...
File "scripts/planner.py", line 16, in
from llm import LLMClient
File "scripts/llm.py", line 6, in
import requests
ModuleNotFoundError: No module named 'requests'

复现步骤:

  1. git clone https://gitcode.com/agent-best-practices/scenario-planner.git(2026-11-30 验证,commit b0053343);
  2. 不执行 pip install -r requirements.txt(Python 3.11,未装 requests);
  3. 运行 python3 scripts/assemble_agent_result.py --help。

原因分析:

  • assemble_agent_result.py 第 22 行只从 planner 导入数据结构,其第 7 行自述「无需配置 LLM_BASE_URL / LLM_API_KEY / LLM_MODEL,也不调用 scripts/llm.py」;
  • 但 planner.py 第 16 行顶层 from llm import LLMClient,LLMClient 在 planner.py 中仅出现在第 185 行函数参数类型注解(llm: LLMClient),装配器本身并不调用 LLM;
  • llm.py 第 6 行 import requests,于是装配器在未装 requests 时连启动都做不到;
  • README「形态 ②」全程未提及 pip install -r requirements.txt(该步骤只出现在形态 ①),因此按 Agent 模式文档操作的用户必定撞上此错误;
  • 对照:pip install requests 后同一条 --help 正常输出 usage,证明 requests 是唯一缺失项。

建议:

  • 首选:将 planner.py 对 LLMClient 的导入改为惰性导入(TYPE_CHECKING + 字符串注解,或函数内导入),使装配器路径真正不依赖 requests;
  • 或在 README「形态 ②」中补上 pip install -r requirements.txt 前置步骤。

环境:2026-11-30,Python 3.11,华为云 DevSpace 免费体验版容器,未安装 requests。

likedislike