agent-Specialization/SUB_AGENT_FIXES_SUMMARY.md

118 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 子智能体问题修复总结
## 已修复的问题
### 1. 前端子智能体显示问题 ✅
- **问题**:创建子智能体后不显示,只在完成后突然显示
- **原因**`get_overview` 方法中调用了旧的 `_call_service`HTTP 模式),但新实现是子进程模式
- **修复**:移除 `_call_service` 调用,改为直接检查进程状态
### 2. 暗色模式适配 ✅
- **问题**:子智能体卡片没有暗色模式样式
- **修复**:在 `static/src/styles/components/panels/_left-panel.scss` 中添加暗色模式样式
### 3. deliverables_dir 参数问题 ✅
- **问题**:模型每次调用时都忘了提供这个参数
- **修复**:将 `deliverables_dir` 改为必需参数(在 `required` 数组中)
### 4. 后台运行时的 system 消息插入 ✅
- **状态**:已经实现
- **位置**`server/chat_flow_task_support.py` 中的 `process_sub_agent_updates` 函数
- **调用**:在 `server/chat_flow_tool_loop.py``execute_tool_calls` 中每次工具执行后调用
## 还需要实现的功能
### 空闲期间的 user 消息自动发送 ⏳
**需求**
- 当主智能体完成任务进入空闲状态时
- 如果还有子智能体在后台运行
- 需要轮询等待子智能体完成
- 完成后自动发送 user 消息触发新一轮对话
**实现位置**
需要在主对话循环结束时添加检查逻辑,可能的位置:
1. `server/chat_flow_stream_loop.py` - 流式循环结束时
2. `server/chat_flow_task_main.py` - 主任务完成时
**实现逻辑**
```python
# 在对话循环结束时
async def check_background_sub_agents(web_terminal, messages, sender):
manager = getattr(web_terminal, "sub_agent_manager", None)
if not manager:
return False
# 检查是否有运行中的子智能体
running_tasks = [
task for task in manager.tasks.values()
if task.get("status") not in {"completed", "failed", "timeout", "terminated"}
and task.get("run_in_background")
]
if not running_tasks:
return False
# 设置对话状态:有子智能体运行中
# 前端显示警告:切换对话会终止子智能体
# 轮询等待完成
while running_tasks:
await asyncio.sleep(5)
updates = manager.poll_updates()
for update in updates:
# 发送 user 消息触发新一轮
user_message = build_completion_user_message(update)
messages.append({
"role": "user",
"content": user_message,
"metadata": {"sub_agent_completion": True}
})
# 触发新一轮 API 调用
sender('user_message', {'content': user_message})
return True # 表示需要继续对话
# 重新检查运行中的任务
running_tasks = [
task for task in manager.tasks.values()
if task.get("status") not in {"completed", "failed", "timeout", "terminated"}
and task.get("run_in_background")
]
return False
```
**user 消息格式**
```python
def build_completion_user_message(update):
agent_id = update.get("agent_id")
summary = update.get("summary")
result_summary = update.get("result_summary")
deliverables_dir = update.get("deliverables_dir")
return f"""子智能体{agent_id} ({summary}) 已完成任务。
{result_summary}
交付目录:{deliverables_dir}"""
```
## 测试清单
- [x] 创建子智能体后立即在前端显示
- [x] 暗色模式下子智能体卡片样式正确
- [x] deliverables_dir 必须提供,否则报错
- [x] 后台运行时工具执行后插入 system 消息
- [ ] 空闲期间子智能体完成后自动发送 user 消息
- [ ] 切换对话时提示会终止子智能体
- [ ] 强制切换对话时终止所有子智能体
## 下一步
1. 实现空闲期间的 user 消息自动发送
2. 添加对话状态管理(标记有子智能体运行中)
3. 前端添加警告提示(切换对话会终止子智能体)
4. 测试完整流程