一键导入
agent-teams
多 Agent 协作机制,持久 agent + 异步通信 + 团队管理。 使用此 skill 当你需要: - 理解 Agent Teams 的工作方式 - 使用 MessageBus 进行 agent 间通信 - 使用 TeammateManager 管理持久 agent 线程
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
多 Agent 协作机制,持久 agent + 异步通信 + 团队管理。 使用此 skill 当你需要: - 理解 Agent Teams 的工作方式 - 使用 MessageBus 进行 agent 间通信 - 使用 TeammateManager 管理持久 agent 线程
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
AgentLoop 是整个 Agent Harness 的心脏。使用此 skill 当你需要: - 构建新的 Agent 系统 - 理解 Model + Harness 的关系 - 使用 chat() 快捷函数进行单轮对话
Agent Team 通信协议 FSM:shutdown / plan_approval。 使用此 skill 当你需要: - 实现优雅关闭协议 - 实现计划审批协议 - 理解 s10 Team Protocols 的状态机设计
3层 Context 压缩策略,支持无限长度会话。 使用此 skill 当你需要: - 理解 Context 压缩的原理 - 实现消息历史摘要 - 处理超长对话导致 context overflow
基于文件的 TaskManager,任务持久化 + 依赖图。 使用此 skill 当你需要: - 创建跨会话持久化的任务 - 管理任务间的 blockedBy/blocks 依赖关系 - 理解 s07 TaskSystem 的文件格式
工具注册与分发机制。使用此 skill 当你需要: - 注册新的 tool handler - 理解工具定义(tools list)和工具执行(handlers dict)的分离 - 使用 make_default_dispatcher 快速创建默认工具集
| name | agent-teams |
| description | 多 Agent 协作机制,持久 agent + 异步通信 + 团队管理。 使用此 skill 当你需要: - 理解 Agent Teams 的工作方式 - 使用 MessageBus 进行 agent 间通信 - 使用 TeammateManager 管理持久 agent 线程 |
Subagent (一次性):
spawn → execute → return summary → destroyed
Teammate (持久):
spawn → work → idle → work → ... → shutdown
Subagent 适合独立子任务。 Teammate 适合需要持续工作、等待指令的助手。
每个 teammate 有一个 JSONL 文件作为收件箱:
.team/inbox/
alice.jsonl ← alice 的消息
bob.jsonl ← bob 的消息
lead.jsonl ← lead(主 agent)的消息
发消息 = 追加到文件(append-only,不丢消息) 读消息 = 读取并清空文件
from pathlib import Path
from agent_core import MessageBus
bus = MessageBus(Path(".team/inbox"))
# 发消息
bus.send("lead", "alice", "please fix the login bug")
bus.send("lead", "bob", "review alice's PR")
# 读自己的收件箱(lead)
messages = bus.read_inbox("lead")
# [{'type': 'message', 'from': 'alice', 'content': 'login bug fixed', ...}, ...]
# 广播
bus.broadcast("lead", "all devs: meeting in 5 min", teammates=["alice", "bob", "carol"])
from pathlib import Path
from agent_core import TeammateManager, make_default_dispatcher
tm = TeammateManager(
team_dir=Path(".team"),
inbox_dir=Path(".team/inbox"),
model="claude-sonnet-4-20250514",
system_base="你是一个代码审查 agent。",
)
dispatcher = make_default_dispatcher(workdir=Path.cwd())
tm.spawn(
name="reviewer",
role="code_reviewer",
prompt="审查 apps/api/auth.py 的安全性,给出改进建议。",
tools=dispatcher.get_tool_definitions(),
)
# → Spawned 'reviewer' (role: code_reviewer)
reviewer agent 在独立线程运行,有自己的 inbox,可以接收 lead 的消息。
| 类型 | 用途 | 方向 |
|---|---|---|
message | 普通文本消息 | any → any |
broadcast | 广播 | lead → all |
shutdown_request | 请求关闭 | lead → teammate |
shutdown_response | 同意/拒绝关闭 | teammate → lead |
plan_approval_request | 请求批准计划 | teammate → lead |
plan_approval_response | 同意/拒绝计划 | lead → teammate |
lead ──shutdown_request──→ alice
alice: 停止接单,完成当前任务
alice ──shutdown_response(approved)──→ lead
# lead 请求关闭
tm.shutdown("alice")
# alice 的线程收到 shutdown_request
# → 完成当前任务 → 状态改为 idle
# 检查 team 状态
print(tm.list_all())
# Team: default
# reviewer (code_reviewer): idle
# tester (qa): idle
适合 Team 模式:
不适合:
bus.send("lead", "alice", "PR #42 已创建,请审查")
bus.send("alice", "lead", "审查完成,发现3个安全问题")
bus.broadcast("lead", "meeting cancelled", teammates=["alice", "bob"])
# → 发送到 alice.jsonl 和 bob.jsonl
# lead 发送关闭请求
tm.shutdown("alice")
# alice 线程内部处理:
# if msg["type"] == "shutdown_request":
# bus.send("alice", "lead", "approved", "shutdown_response")
# return # 退出 loop
# alice 发计划给 lead 审批
bus.send("alice", "lead",
"我计划重构 auth.py,拆分成 auth/jwt.py 和 auth/oauth.py",
"plan_approval_request")
# lead 审批
bus.send("lead", "alice", "approved: 可以开始", "plan_approval_response")