feat: push LLM to continue after 1-2 tool calls

This commit is contained in:
ymq 2026-08-11 13:11:17 +08:00
parent 92af7603e0
commit 23ff786c92

View File

@ -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", "")