binary-husky/gpt_academic · error · Exception
用户代理或助理代理未定义
Error message
用户代理或助理代理未定义
What it means
AutoGenGeneral.exe_autogen() builds agents from define_agents() and recognizes the required agents by the exact names 'user_proxy' and 'assistant'. If either variable is still None after the loop, this Exception is raised, converted to a traceback, and sent back through the pipe.
Source
Thrown at crazy_functions/agent_fns/general.py:90
assistant = None
for agent_kwargs in agents:
agent_cls = agent_kwargs.pop('cls')
kwargs = {
'llm_config':self.llm_kwargs,
'code_execution_config':code_execution_config
}
kwargs.update(agent_kwargs)
agent_handle = agent_cls(**kwargs)
agent_handle._print_received_message = lambda a,b: self.gpt_academic_print_override(agent_kwargs, a, b)
for d in agent_handle._reply_func_list:
if hasattr(d['reply_func'],'__name__') and d['reply_func'].__name__ == 'generate_oai_reply':
d['reply_func'] = gpt_academic_generate_oai_reply
if agent_kwargs['name'] == 'user_proxy':
agent_handle.get_human_input = lambda a: self.gpt_academic_get_human_input(user_proxy, a)
user_proxy = agent_handle
if agent_kwargs['name'] == 'assistant': assistant = agent_handle
try:
if user_proxy is None or assistant is None: raise Exception("用户代理或助理代理未定义")
with ProxyNetworkActivate("AutoGen"):
user_proxy.initiate_chat(assistant, message=input)
except Exception as e:
tb_str = '```\n' + trimmed_format_exc() + '```'
self.child_conn.send(PipeCom("done", "AutoGen 执行失败: \n\n" + tb_str))
def subprocess_worker(self, child_conn):
# ⭐⭐ run in subprocess
self.child_conn = child_conn
while True:
msg = self.child_conn.recv() # PipeCom
self.exe_autogen(msg)
class AutoGenGroupChat(AutoGenGeneral):
def exe_autogen(self, input):
# ⭐⭐ run in subprocess
import autogenView on GitHub (pinned to d6bde0fa54)
Solutions
- Make define_agents() return one agent dict with name='user_proxy' and one with name='assistant'.
- Check the dict keys before initiate_chat and fail with the names that were found.
- Use exact lowercase strings; do not include whitespace or labels.
- Keep the agent class under 'cls' and do not consume the name key before this loop.
- Write a unit test for define_agents()' returned names.
Example fix
# before
agents = self.define_agents()
for agent_kwargs in agents:
...
if user_proxy is None or assistant is None:
raise Exception("用户代理或助理代理未定义")
# after
agents = self.define_agents()
names = {a.get("name") for a in agents}
missing = {"user_proxy", "assistant"} - names
if missing:
raise ValueError(f"Missing required agents {missing}; found {names}")
Defensive patterns
Strategy: validation
Validate before calling
required = {"user_proxy", "assistant"}
names = {agent.get("name") for agent in self.define_agents()}
missing = required - names
if missing:
raise ValueError(f"define_agents() is missing required names: {sorted(missing)}")
Type guard
def has_required_two_agent_names(agents) -> bool:
names = {a.get("name") for a in agents if isinstance(a, dict)}
return {"user_proxy", "assistant"}.issubset(names)
Try / catch
try:
...initiate_chat...
except Exception as e:
if "用户代理或助理代理未定义" in str(e):
fix_agent_configuration()
else:
raise
Prevention
- Treat define_agents() as a contract with exact role names.
- Validate required names in subclass tests.
- Avoid display-only renames of framework roles.
- Check both cls and name keys before runtime.
When it happens
Trigger: A subclass's define_agents() returns no list entry with name exactly 'user_proxy' or 'assistant', renames them to values such as 'user proxy', 'proxy', or 'coder', or returns an empty list.
Common situations: Writing a custom agent plugin without following the base-class contract; changing names for display purposes; copying a group-chat configuration into the two-agent runner; conditionally removing an agent.
Related errors
- user_proxy is not defined
- 模型覆盖参数 '{model_override}' 指向一个暂不支持的模型,请检查配置文件。
- Endpoint不正确, 请检查AZURE_ENDPOINT的配置! 当前的Endpoint为:{endpoint}
- APIKEY为空,请检查配置文件的{APIKEY}
- 不支持的检索类型
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/7dd656a04cebe23e.
Report an issue: GitHub.