binary-husky/gpt_academic · error · Exception

user_proxy is not defined

Error message

user_proxy is not defined

What it means

AutoGenGroupChat.exe_autogen()同样 requires an agent whose name is exactly 'user_proxy'. The intended custom Exception is raised when user_proxy is None. Because this override does not initialize user_proxy before the loop, a completely missing agent usually causes UnboundLocalError first; the surrounding except still reports an AutoGen failure.

Source

Thrown at crazy_functions/agent_fns/general.py:131

            agents = self.define_agents()
            agents_instances = []
            for agent_kwargs in agents:
                agent_cls = agent_kwargs.pop("cls")
                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)
                agents_instances.append(agent_handle)
                if agent_kwargs["name"] == "user_proxy":
                    user_proxy = agent_handle
                    user_proxy.get_human_input = lambda a: self.gpt_academic_get_human_input(user_proxy, a)
            try:
                groupchat = autogen.GroupChat(agents=agents_instances, messages=[], max_round=50)
                manager = autogen.GroupChatManager(groupchat=groupchat, **self.define_group_chat_manager_config())
                manager._print_received_message = lambda a, b: self.gpt_academic_print_override(agent_kwargs, a, b)
                manager.get_human_input = lambda a: self.gpt_academic_get_human_input(manager, a)
                if user_proxy is None:
                    raise Exception("user_proxy is not defined")
                user_proxy.initiate_chat(manager, message=input)
            except Exception:
                tb_str = "```\n" + trimmed_format_exc() + "```"
                self.child_conn.send(PipeCom("done", "AutoGen exe failed: \n\n" + tb_str))

    def define_group_chat_manager_config(self):
        raise NotImplementedError

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Ensure define_agents() contains {'name': 'user_proxy', 'cls': ...}.
  2. Initialize user_proxy = None before iterating so the intended error is reachable and testable.
  3. Validate agent names before constructing the GroupChat.
  4. Use exact lowercase names for all framework-recognized roles.
  5. Add a unit test covering missing, renamed, and present proxy configurations.

Example fix

# before
agents_instances = []
for agent_kwargs in agents:
    ...
    if agent_kwargs["name"] == "user_proxy":
        user_proxy = agent_handle

# after
user_proxy = None
agents_instances = []
for agent_kwargs in agents:
    ...
    if agent_kwargs["name"] == "user_proxy":
        user_proxy = agent_handle
Defensive patterns

Strategy: validation

Validate before calling

agent_names = [a.get("name") for a in self.define_agents()]
if "user_proxy" not in agent_names:
    raise ValueError(f"define_agents() must include name='user_proxy'; got {agent_names}")

Type guard

def has_group_chat_user_proxy(agents) -> bool:
    return any(isinstance(a, dict) and a.get("name") == "user_proxy" for a in agents)

Try / catch

try:
    ...initiate_chat(manager, message=input)...
except Exception as e:
    if "user_proxy is not defined" in str(e) or "user_proxy" in str(e):
        validate_group_chat_agents()
    raise

Prevention

When it happens

Trigger: define_agents() omits an entry with name='user_proxy', renames it, or the key is not the exact lowercase string checked at line 122.

Common situations: A custom group-chat plugin copies agent names such as 'Admin' or 'Executor'; a conditional configuration filters out the proxy; the name field is accidentally named agent_name; tests use a stub list without the proxy.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/56ae099ccc65aa23. Report an issue: GitHub.