fix: aliases, questions SQL, limit auto-inject to 3

This commit is contained in:
ymq 2026-08-11 13:57:25 +08:00
parent e558bad2c9
commit d8f810bf8d

View File

@ -69,6 +69,7 @@ class AgentExecutor:
self._msgs: List[dict] = [] # LLM 消息数组 self._msgs: List[dict] = [] # LLM 消息数组
self._turn_count: int = 0 self._turn_count: int = 0
self._tool_call_count: int = 0 self._tool_call_count: int = 0
self._auto_push_count: int = 0 # 限制 auto-inject 次数
self._session_id: str = "" self._session_id: str = ""
self._started_at: float = 0.0 self._started_at: float = 0.0
@ -150,11 +151,12 @@ class AgentExecutor:
self._msgs.append({"role": "user", "content": f"请调用 {hint_tool} 工具,只输出 {{\"action\":\"tool_call\",\"tool\":\"{hint_tool}\",\"params\":{{}}}}"}) self._msgs.append({"role": "user", "content": f"请调用 {hint_tool} 工具,只输出 {{\"action\":\"tool_call\",\"tool\":\"{hint_tool}\",\"params\":{{}}}}"})
continue continue
# 调了工具但太少(1-2次),LLM 想停 → 推它继续深入 # 调了工具但太少(1-2次),LLM 想停 → 推它继续深入(最多3次)
if self._tool_call_count <= 2 and self._turn_count < self.config.max_turns - 2: if self._tool_call_count <= 2 and self._auto_push_count < 3:
self._auto_push_count += 1
hint = "请继续:查看失败任务的详情(task_detail),查看待回答问题(list_questions),或启动agent(start_agents)" hint = "请继续:查看失败任务的详情(task_detail),查看待回答问题(list_questions),或启动agent(start_agents)"
yield json.dumps({ yield json.dumps({
"type": "auto_tool", "message": f"已调{self._tool_call_count}次工具,继续深入", "type": "auto_tool", "message": f"已调{self._tool_call_count}次工具,继续深入({self._auto_push_count}/3)",
}, ensure_ascii=False) + "\n" }, ensure_ascii=False) + "\n"
self._msgs.append({"role": "assistant", "content": "继续分析"}) self._msgs.append({"role": "assistant", "content": "继续分析"})
self._msgs.append({"role": "user", "content": hint}) self._msgs.append({"role": "user", "content": hint})
@ -477,9 +479,11 @@ class AgentExecutor:
"create_project": self._t_create_project, "create_project": self._t_create_project,
"create_task": self._t_create_task, "create_task": self._t_create_task,
"list_tasks": self._t_list_tasks, "list_tasks": self._t_list_tasks,
"get_task_list": self._t_list_tasks, # 别名 "get_task_list": self._t_list_tasks,
"get_tasks": self._t_list_tasks, # 别名
"task_detail": self._t_task_detail, "task_detail": self._t_task_detail,
"get_task": self._t_task_detail, # 别名 "get_task": self._t_task_detail,
"get_task_detail": self._t_task_detail, # 别名
"start_agents": self._t_start_agents, "start_agents": self._t_start_agents,
"diagnose_project": self._t_diagnose_project, "diagnose_project": self._t_diagnose_project,
"list_deliverables": self._t_list_deliverables, "list_deliverables": self._t_list_deliverables,
@ -732,10 +736,20 @@ class AgentExecutor:
if not pid: if not pid:
return "请先切换到项目" return "请先切换到项目"
recs = await sor.sqlExe( try:
"SELECT id, question, answer_source FROM pipeline_agent_questions " recs = await sor.sqlExe(
"WHERE tenant_id=${pid}$ AND answered IS NULL ORDER BY created_at DESC LIMIT 10", "SELECT id, question, answer_source FROM pipeline_agent_questions "
{"pid": pid}) "WHERE tenant_id=${pid}$ AND answered IS NULL ORDER BY created_at DESC LIMIT 10",
{"pid": pid})
except Exception:
# 兼容无 answered 列的情况
try:
recs = await sor.sqlExe(
"SELECT id, question, answer_source FROM pipeline_agent_questions "
"WHERE tenant_id=${pid}$ ORDER BY created_at DESC LIMIT 10",
{"pid": pid})
except Exception:
return "暂无问题数据"
if not recs: if not recs:
return "没有待回答问题" return "没有待回答问题"