Skip to content

feat: inter-agent communication (Phase 4 of Agent Teams)#136

Open
LeoLin990405 wants to merge 5 commits intobfly123:mainfrom
LeoLin990405:feat/agent-comm
Open

feat: inter-agent communication (Phase 4 of Agent Teams)#136
LeoLin990405 wants to merge 5 commits intobfly123:mainfrom
LeoLin990405:feat/agent-comm

Conversation

@LeoLin990405
Copy link
Contributor

Summary / 概述

Phase 4 of Agent Teams (#81): 添加 Agent 间通信,支持定向消息、任务链和广播。
Adds inter-agent communication with directed messages, task chains, and broadcast.

依赖 / Depends on: #133 (Phase 1), #134 (Phase 2), #135 (Phase 3)

新文件 / New Files

  • lib/agent_comm.py (196 行) — 消息封装、广播、链式解析、agent 名称解析
  • test/test_agent_comm.py (258 行) — 30 个测试覆盖所有通信路径

修改 / Modified

  • bin/ask — 新增 --to--broadcast 标志

使用方式 / Usage

1. 定向消息 / Directed Message (--to)

从一个 agent 向另一个发送消息,带发送者元数据:
Send message from one agent to another, with sender metadata:

# 用 provider 名称
ask codex --to gemini "请分析这个前端架构"
# [TO] codex → gemini (gemini)

# 用 team agent 名称
ask coder --to reviewer "请审查这段代码"
# [TO] coder → reviewer (claude)

# 用别名
ask a --to b "需要你帮忙"
# [TO] codex → b (gemini)

接收方收到的消息格式 / Receiving agent sees:

[CCB_FROM agent=codex]
请分析这个前端架构

2. 广播 / Broadcast (--broadcast)

向所有 team agent 发送通知(需要 team 配置):
Send notification to all team agents (requires team config):

ask codex --broadcast "任务已完成,请同步"
# [BROADCAST] → gemini
# [BROADCAST] → claude
# [BROADCAST] Sent to 2 agents

3. 任务链 / Task Chain (lib API)

通过 parse_chain_spec + build_chain_messages 构建顺序执行链:
Build sequential execution chains via the library API:

from agent_comm import parse_chain_spec, build_chain_messages

chain = parse_chain_spec("gemini:research topic | codex:implement | claude:review")
messages = build_chain_messages(chain)
# messages[0]: user → gemini "research topic"
# messages[1]: gemini → codex "implement"
# messages[2]: codex → claude "review"

消息格式 / Message Format

[CCB_FROM agent=<sender>]
[CCB_CONTEXT]
<previous agent's output>
[/CCB_CONTEXT]
<message content>

设计要点 / Design

特性 说明
--to 解析 支持 team agent 名、别名、直接 provider
--broadcast 排除 默认排除发送者自身
消息封装 [CCB_FROM] + [CCB_CONTEXT] 标签
链式解析 parse_chain_spec("a:t1 | b:t2") → 步骤列表
自动 sender 推导 链中每步的 sender = 上一步的 receiver
Daemon 零改动 通信完全通过已有的 ask 基础设施

阶段路线图 / Phased Roadmap

Phase 内容 / Content 状态 / Status
1 Agent 别名 / Agent aliases #133
2 Team 配置 + 角色 / Team config + roles #134
3 任务分发 + 智能路由 / Task distribution + smart routing #135
4 Agent 间通信 / Inter-agent communication (this PR)

所有 4 个阶段已完成!/ All 4 phases complete! 🎉

Closes #81

测试计划 / Test plan

  • pytest test/test_agent_comm.py -v — 30/30 passed
  • pytest test/test_task_router.py -v — 46/46 passed
  • pytest test/test_team_config.py -v — 38/38 passed
  • pytest test/test_aliases.py -v — 22/22 passed
  • 全量回归 / Full regression — 162/162 passed (零回归)
  • 手动测试:ask codex --to gemini "hello" 验证消息封装
  • 手动测试:ask codex --broadcast "通知" 验证广播
  • 手动测试:所有已有功能不受影响

Add a/b/c/d... shorthand aliases for providers so users can type
`ask a "hello"` instead of `ask codex "hello"`.

- New lib/aliases.py: 3-layer config (defaults < ~/.ccb/ < .ccb/)
- Updated bin/ask: alias resolution before parse_qualified_provider
- New test/test_aliases.py: 22 tests covering all paths

Relates to bfly123#81
…ly123#81)

Add team configuration system allowing named agents with provider,
model, role, and skills. Team agent names override aliases.

- New lib/team_config.py: team config loading from .ccb/team.json
- Updated bin/ask: team agent resolution (priority over aliases)
- New test/test_team_config.py: 38 tests covering all paths

Example .ccb/team.json:
{
  "name": "dev-team",
  "strategy": "skill_based",
  "agents": [
    {"name": "researcher", "provider": "gemini", "model": "3f", "role": "research"},
    {"name": "coder", "provider": "codex", "model": "o3", "role": "implementation"}
  ]
}

Usage: ask researcher "hello" → routes to gemini

Relates to bfly123#81
…fly123#81)

Add smart task routing that auto-selects the best provider based on
message content analysis using keyword matching and team skill matching.

- New lib/task_router.py: keyword rules, team skill matching, auto_route
- Updated bin/ask: --auto flag for automatic provider selection
- New test/test_task_router.py: 46 tests covering all routing paths

Usage:
  ask --auto "帮我写一个 React 前端组件"  → gemini (keywords: react, 前端)
  ask --auto "分析算法复杂度"             → codex (keywords: 算法, 复杂度)
  ask --auto "翻译这段话"                 → kimi (keywords: 翻译)

With team config, team skill matching takes priority over keywords.

Relates to bfly123#81
Add inter-agent messaging with three communication patterns:
directed messages, task chains, and broadcast.

- New lib/agent_comm.py: message wrapping, broadcast, chain parsing
- Updated bin/ask: --to and --broadcast flags
- New test/test_agent_comm.py: 30 tests covering all comm paths

Usage:
  ask codex --to reviewer "请审查这段代码"
  ask codex --broadcast "任务完成通知"

Relates to bfly123#81
- Add --chain flag for sequential multi-agent pipelines:
  ask --chain "gemini:research | codex:implement | claude:review"
- Fix --broadcast: use stdin pipe instead of position args
- Chain passes previous output as [CCB_CONTEXT] to next step
- Add 3 chain integration tests

Relates to bfly123#81
@LeoLin990405 LeoLin990405 mentioned this pull request Mar 11, 2026
@bfly123
Copy link
Owner

bfly123 commented Mar 11, 2026

这个兼容吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

结合Agent Teams

2 participants