{"record":{"id":"56ae099ccc65aa23","repo":"binary-husky/gpt_academic","slug":"user-proxy-is-not-defined","errorCode":null,"errorMessage":"user_proxy is not defined","messagePattern":"user_proxy is not defined","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"crazy_functions/agent_fns/general.py","lineNumber":131,"sourceCode":"            agents = self.define_agents()\n            agents_instances = []\n            for agent_kwargs in agents:\n                agent_cls = agent_kwargs.pop(\"cls\")\n                kwargs = {\"code_execution_config\": code_execution_config}\n                kwargs.update(agent_kwargs)\n                agent_handle = agent_cls(**kwargs)\n                agent_handle._print_received_message = lambda a, b: self.gpt_academic_print_override(agent_kwargs, a, b)\n                agents_instances.append(agent_handle)\n                if agent_kwargs[\"name\"] == \"user_proxy\":\n                    user_proxy = agent_handle\n                    user_proxy.get_human_input = lambda a: self.gpt_academic_get_human_input(user_proxy, a)\n            try:\n                groupchat = autogen.GroupChat(agents=agents_instances, messages=[], max_round=50)\n                manager = autogen.GroupChatManager(groupchat=groupchat, **self.define_group_chat_manager_config())\n                manager._print_received_message = lambda a, b: self.gpt_academic_print_override(agent_kwargs, a, b)\n                manager.get_human_input = lambda a: self.gpt_academic_get_human_input(manager, a)\n                if user_proxy is None:\n                    raise Exception(\"user_proxy is not defined\")\n                user_proxy.initiate_chat(manager, message=input)\n            except Exception:\n                tb_str = \"```\\n\" + trimmed_format_exc() + \"```\"\n                self.child_conn.send(PipeCom(\"done\", \"AutoGen exe failed: \\n\\n\" + tb_str))\n\n    def define_group_chat_manager_config(self):\n        raise NotImplementedError\n","sourceCodeStart":113,"sourceCodeEnd":139,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/agent_fns/general.py#L113-L139","documentation":"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.","triggerScenarios":"define_agents() omits an entry with name='user_proxy', renames it, or the key is not the exact lowercase string checked at line 122.","commonSituations":"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.","solutions":["Ensure define_agents() contains {'name': 'user_proxy', 'cls': ...}.","Initialize user_proxy = None before iterating so the intended error is reachable and testable.","Validate agent names before constructing the GroupChat.","Use exact lowercase names for all framework-recognized roles.","Add a unit test covering missing, renamed, and present proxy configurations."],"exampleFix":"# before\nagents_instances = []\nfor agent_kwargs in agents:\n    ...\n    if agent_kwargs[\"name\"] == \"user_proxy\":\n        user_proxy = agent_handle\n\n# after\nuser_proxy = None\nagents_instances = []\nfor agent_kwargs in agents:\n    ...\n    if agent_kwargs[\"name\"] == \"user_proxy\":\n        user_proxy = agent_handle\n","handlingStrategy":"validation","validationCode":"agent_names = [a.get(\"name\") for a in self.define_agents()]\nif \"user_proxy\" not in agent_names:\n    raise ValueError(f\"define_agents() must include name='user_proxy'; got {agent_names}\")\n","typeGuard":"def has_group_chat_user_proxy(agents) -> bool:\n    return any(isinstance(a, dict) and a.get(\"name\") == \"user_proxy\" for a in agents)\n","tryCatchPattern":"try:\n    ...initiate_chat(manager, message=input)...\nexcept Exception as e:\n    if \"user_proxy is not defined\" in str(e) or \"user_proxy\" in str(e):\n        validate_group_chat_agents()\n    raise\n","preventionTips":["Always return an exact user_proxy entry from define_agents().","Initialize user_proxy = None before iterating to avoid UnboundLocalError.","Validate names before constructing GroupChat.","Cover missing-role cases in plugin unit tests."],"tags":["autogen","group-chat","configuration","agents"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}