MS Autogen问题:已注册的complaint_filer执行函数未触发
问题排查:收集投诉信息后
file_complaint函数未调用 场景描述
在群聊中配置了两个Agent实现GUI投诉提交流程:
- UserProxyAgent:负责通过GUI获取用户输入
- ComplaintFiler Agent:负责收集信息并提交投诉
- 配套模拟REST调用的
file_complaint函数
用户输入“我要提交投诉”后,系统能正常询问姓名、地址和建筑类型,但收集完所有信息后,file_complaint函数始终未被调用。
相关代码
UserProxyAgent代码
class UserProxy(UserProxyAgent): def __init__(self, question_setter, input_forwarder): super().__init__( name='UserProxyAgent', llm_config=False, human_input_mode='ALWAYS', code_execution_config={'use_docker': False} ) self._input_forwarder = input_forwarder self._system_question_setter = question_setter self.register_for_execution(name='complaint_filer')(file_complaint) def get_human_input(self, prompt: str) -> str: message = self.last_message()['content'] ic(f"### User Proxy get_human_input called - question: {message}") self._system_question_setter(message) ic(f"### User Proxy get_human_input - system question set, calling input forwarder") return self._input_forwarder()
ComplaintFiler Agent代码
class ComplaintFiler(ConversableAgent): def __init__(self): super().__init__( name="ComplaintFiler", system_message=""" You are an assistant that can file a complaint. Before attempting to file a complain, make sure to get all required information. If you need to ask questions to the user, you must ask the UserProxyAgent to do that for you. Once you have all information, you can call the file_complaint function to finalize your work, and pass the returned value back to the chat manager. """, llm_config=llm_config ) self.register_for_llm( name="complaint_filer", description="A way to file a complaint." )(file_complaint)
模拟REST调用函数
def file_complaint(name: str, address: str, building_type: Annotated[BuildingType, 'building_type'] ) -> str: ic('FILE COMPLAINT: Simulating a rest call') ic(name, address, building_type) return f"Reference number: 12345"
可能的原因及解决方法
1. 系统提示词未明确强制函数调用
当前ComplaintFiler的系统提示词仅模糊说明“收集完信息后可以调用函数”,LLM无法精准判断触发节点,也没有明确要求必须使用工具调用格式。
解决方法:修改系统提示词,明确必填字段和强制调用要求:
You are an assistant that can file a complaint. Before attempting to file a complaint, make sure to get all required information: name, address, building_type. If you need to ask questions to the user, you must ask the UserProxyAgent to do that for you. Once you have ALL of name, address, building_type, you MUST call the `complaint_filer` function with these three parameters to finalize your work. Do not respond with natural language; strictly use the required function call format.
2. UserProxyAgent的human_input_mode阻断流程
UserProxyAgent设置了human_input_mode='ALWAYS',这会强制每个交互节点都等待人类输入,包括ComplaintFiler准备调用函数的阶段,导致函数无法自动执行。
解决方法:调整human_input_mode为适合自动化流程的取值:
super().__init__( name='UserProxyAgent', llm_config=False, human_input_mode='NEVER', # 完全不等待人工输入,适合全自动化流程 # 或选择'TERMINATE':仅在收到终止信号时等待人工输入 code_execution_config={'use_docker': False} )
3. LLM配置不支持工具调用
如果llm_config未正确配置工具调用参数,或使用的LLM模型不支持函数调用能力,会导致无法生成正确的函数调用指令。
解决方法:确认llm_config包含工具调用配置,且选用支持函数调用的模型(如gpt-3.5-turbo-1106、gpt-4等),示例配置:
llm_config = { "model": "gpt-3.5-turbo-1106", "tools": [{"name": "complaint_filer", "description": "A way to file a complaint."}], "temperature": 0.1 # 降低温度减少随机性,提升指令执行稳定性 }
4. 群聊交互流程未允许函数调用触发
需确认群聊管理器的运行逻辑,确保ComplaintFiler在收集完信息后能主动发起函数调用请求,且UserProxyAgent能正确接收并执行该调用。
验证方法:在ComplaintFiler的消息处理逻辑中添加日志,确认是否生成了函数调用指令;检查UserProxyAgent是否能接收到该指令并触发file_complaint函数。
内容的提问来源于stack exchange,提问作者Al Ant
相关产品推荐
相关产品推荐

