From 23ff786c92a559e7d1aae7c13c3a1483ae679bb4 Mon Sep 17 00:00:00 2001 From: ymq Date: Tue, 11 Aug 2026 13:11:17 +0800 Subject: [PATCH] feat: push LLM to continue after 1-2 tool calls --- pipeline_service/agent_loop_v2.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pipeline_service/agent_loop_v2.py b/pipeline_service/agent_loop_v2.py index be1a251..716852b 100644 --- a/pipeline_service/agent_loop_v2.py +++ b/pipeline_service/agent_loop_v2.py @@ -138,7 +138,6 @@ class AgentExecutor: if action_type == "reply": # 任何轮次,只要没成功调过工具就 reply → 强制注入工具调用 if self._tool_call_count == 0: - # 根据用户输入推断合适的工具 hint_tool = "diagnose_project" if any(kw in user_input.lower() for kw in ["任务", "task", "list"]): hint_tool = "list_tasks" @@ -147,14 +146,18 @@ class AgentExecutor: yield json.dumps({ "type": "auto_tool", "message": f"未调工具,自动注入 {hint_tool}", }, ensure_ascii=False) + "\n" - self._msgs.append({ - "role": "assistant", - "content": f"已调用 {hint_tool}", - }) - self._msgs.append({ - "role": "user", - "content": f"请调用 {hint_tool} 工具,只输出 {{\"action\":\"tool_call\",\"tool\":\"{hint_tool}\",\"params\":{{}}}}", - }) + self._msgs.append({"role": "assistant", "content": f"已调用 {hint_tool}"}) + self._msgs.append({"role": "user", "content": f"请调用 {hint_tool} 工具,只输出 {{\"action\":\"tool_call\",\"tool\":\"{hint_tool}\",\"params\":{{}}}}"}) + continue + + # 调了工具但太少(1-2次),LLM 想停 → 推它继续深入 + if self._tool_call_count <= 2 and self._turn_count < self.config.max_turns - 2: + hint = "请继续:查看失败任务的详情(task_detail),查看待回答问题(list_questions),或启动agent(start_agents)" + yield json.dumps({ + "type": "auto_tool", "message": f"已调{self._tool_call_count}次工具,继续深入", + }, ensure_ascii=False) + "\n" + self._msgs.append({"role": "assistant", "content": "继续分析"}) + self._msgs.append({"role": "user", "content": hint}) continue final_reply = act.get("message", "")