{"record":{"id":"7dd656a04cebe23e","repo":"binary-husky/gpt_academic","slug":"error-7dd656","errorCode":null,"errorMessage":"用户代理或助理代理未定义","messagePattern":"用户代理或助理代理未定义","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"crazy_functions/agent_fns/general.py","lineNumber":90,"sourceCode":"        assistant = None\n        for agent_kwargs in agents:\n            agent_cls = agent_kwargs.pop('cls')\n            kwargs = {\n                'llm_config':self.llm_kwargs,\n                'code_execution_config':code_execution_config\n            }\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            for d in agent_handle._reply_func_list:\n                if hasattr(d['reply_func'],'__name__') and d['reply_func'].__name__ == 'generate_oai_reply':\n                    d['reply_func'] = gpt_academic_generate_oai_reply\n            if agent_kwargs['name'] == 'user_proxy':\n                agent_handle.get_human_input = lambda a: self.gpt_academic_get_human_input(user_proxy, a)\n                user_proxy = agent_handle\n            if agent_kwargs['name'] == 'assistant': assistant = agent_handle\n        try:\n            if user_proxy is None or assistant is None: raise Exception(\"用户代理或助理代理未定义\")\n            with ProxyNetworkActivate(\"AutoGen\"):\n                user_proxy.initiate_chat(assistant, message=input)\n        except Exception as e:\n            tb_str = '```\\n' + trimmed_format_exc() + '```'\n            self.child_conn.send(PipeCom(\"done\", \"AutoGen 执行失败: \\n\\n\" + tb_str))\n\n    def subprocess_worker(self, child_conn):\n        # ⭐⭐ run in subprocess\n        self.child_conn = child_conn\n        while True:\n            msg = self.child_conn.recv()  # PipeCom\n            self.exe_autogen(msg)\n\n\nclass AutoGenGroupChat(AutoGenGeneral):\n    def exe_autogen(self, input):\n        # ⭐⭐ run in subprocess\n        import autogen","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/agent_fns/general.py#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nagents = self.define_agents()\nfor agent_kwargs in agents:\n    ...\nif user_proxy is None or assistant is None:\n    raise Exception(\"用户代理或助理代理未定义\")\n\n# after\nagents = self.define_agents()\nnames = {a.get(\"name\") for a in agents}\nmissing = {\"user_proxy\", \"assistant\"} - names\nif missing:\n    raise ValueError(f\"Missing required agents {missing}; found {names}\")\n","handlingStrategy":"validation","validationCode":"required = {\"user_proxy\", \"assistant\"}\nnames = {agent.get(\"name\") for agent in self.define_agents()}\nmissing = required - names\nif missing:\n    raise ValueError(f\"define_agents() is missing required names: {sorted(missing)}\")\n","typeGuard":"def has_required_two_agent_names(agents) -> bool:\n    names = {a.get(\"name\") for a in agents if isinstance(a, dict)}\n    return {\"user_proxy\", \"assistant\"}.issubset(names)\n","tryCatchPattern":"try:\n    ...initiate_chat...\nexcept Exception as e:\n    if \"用户代理或助理代理未定义\" in str(e):\n        fix_agent_configuration()\n    else:\n        raise\n","preventionTips":["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."],"tags":["autogen","configuration","agents","validation"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}