From 3eec18b8a961250051f8755532cbc6500dc7fca2 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Sat, 15 Nov 2025 16:40:01 +0800 Subject: [PATCH] fix: per conversation sub agent limit and todo hints --- core/main_terminal.py | 10 +++++++++- modules/sub_agent_manager.py | 13 +++++++++++++ modules/todo_manager.py | 10 ++++++++-- sub_agent/modules/todo_manager.py | 10 ++++++++-- sub_agent/prompts/todo_guidelines.txt | 2 +- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/core/main_terminal.py b/core/main_terminal.py index f9ed3ce..1edb9c2 100644 --- a/core/main_terminal.py +++ b/core/main_terminal.py @@ -1976,10 +1976,18 @@ class MainTerminal: ) elif tool_name == "wait_sub_agent": + wait_timeout = arguments.get("timeout_seconds") + if not wait_timeout: + task_ref = self.sub_agent_manager.lookup_task( + task_id=arguments.get("task_id"), + agent_id=arguments.get("agent_id") + ) + if task_ref: + wait_timeout = task_ref.get("timeout_seconds") result = self.sub_agent_manager.wait_for_completion( task_id=arguments.get("task_id"), agent_id=arguments.get("agent_id"), - timeout_seconds=arguments.get("timeout_seconds") + timeout_seconds=wait_timeout ) self._record_sub_agent_message(result.get("system_message"), result.get("task_id"), inline=False) diff --git a/modules/sub_agent_manager.py b/modules/sub_agent_manager.py index 85cb1ba..e805d5f 100644 --- a/modules/sub_agent_manager.py +++ b/modules/sub_agent_manager.py @@ -317,6 +317,19 @@ class SubAgentManager: return candidates[0] return None + def lookup_task(self, *, task_id: Optional[str] = None, agent_id: Optional[int] = None) -> Optional[Dict]: + """只读查询任务信息,供 wait_sub_agent 自动调整超时时间。""" + task = self._select_task(task_id, agent_id) + if not task: + return None + return { + "task_id": task.get("task_id"), + "agent_id": task.get("agent_id"), + "status": task.get("status"), + "timeout_seconds": task.get("timeout_seconds"), + "conversation_id": task.get("conversation_id"), + } + def poll_updates(self) -> List[Dict]: """检查运行中的子智能体任务,返回新完成的结果。""" updates: List[Dict] = [] diff --git a/modules/todo_manager.py b/modules/todo_manager.py index a198444..4831d8f 100644 --- a/modules/todo_manager.py +++ b/modules/todo_manager.py @@ -68,7 +68,10 @@ class TodoManager: overview = (overview or "").strip() if not overview: - return {"success": False, "error": "任务概述不能为空。"} + return { + "success": False, + "error": "任务概述不能为空。请用一句话概括清单目标,例如“整理比亚迪新能源销量数据”。" + } if len(overview) > self.MAX_OVERVIEW_LENGTH: return { "success": False, @@ -77,7 +80,10 @@ class TodoManager: normalized_tasks = self._normalize_tasks(tasks or []) if not normalized_tasks: - return {"success": False, "error": "需要至少提供一个任务。"} + return { + "success": False, + "error": "需要至少提供一个任务。每个任务应是可执行的步骤,如“收集车型销量数据”而不是“处理”这类模糊词。" + } if len(tasks or []) > self.MAX_TASKS: return { "success": False, diff --git a/sub_agent/modules/todo_manager.py b/sub_agent/modules/todo_manager.py index a198444..9f274e8 100644 --- a/sub_agent/modules/todo_manager.py +++ b/sub_agent/modules/todo_manager.py @@ -68,7 +68,10 @@ class TodoManager: overview = (overview or "").strip() if not overview: - return {"success": False, "error": "任务概述不能为空。"} + return { + "success": False, + "error": "任务概述不能为空。请用一句话概括清单目标,例如“整理车型销量”或“编写 result.md”。" + } if len(overview) > self.MAX_OVERVIEW_LENGTH: return { "success": False, @@ -77,7 +80,10 @@ class TodoManager: normalized_tasks = self._normalize_tasks(tasks or []) if not normalized_tasks: - return {"success": False, "error": "需要至少提供一个任务。"} + return { + "success": False, + "error": "需要至少提供一个任务。请把计划分成可执行的小步骤,例如“读取文件”“整理总结”等。" + } if len(tasks or []) > self.MAX_TASKS: return { "success": False, diff --git a/sub_agent/prompts/todo_guidelines.txt b/sub_agent/prompts/todo_guidelines.txt index ea53888..2f346cc 100644 --- a/sub_agent/prompts/todo_guidelines.txt +++ b/sub_agent/prompts/todo_guidelines.txt @@ -14,7 +14,7 @@ ## 使用流程 1. **先规划**:在创建清单前,用自然语言写下你准备执行的流程,让自己确认无遗漏。 -2. **todo_create**:把概述与任务数组一次性写对,创建后尽量不要反复删除重建。 +2. **todo_create**:把概述与任务数组一次性写对,创建后尽量不要反复删除重建。概述 ≤ 50 字,直接写清“我要做什么”;任务数组列出 2~4 条动词+对象的步骤,例如“读取 physics_problems.txt”“整理 result.md 结论”。 3. **todo_update_task**:每完成一项立刻勾选;若步骤发生变化,先写明原因再修改对应任务。 4. **todo_finish**:所有任务完成后调用。若仍有未完项但必须停止,先调用 `todo_finish`,再用 `todo_finish_confirm` 说明原因与后续建议。