Skip to content

feat: task distribution + smart routing (Phase 3 of Agent Teams)#135

Open
LeoLin990405 wants to merge 3 commits intobfly123:mainfrom
LeoLin990405:feat/task-router
Open

feat: task distribution + smart routing (Phase 3 of Agent Teams)#135
LeoLin990405 wants to merge 3 commits intobfly123:mainfrom
LeoLin990405:feat/task-router

Conversation

@LeoLin990405
Copy link
Contributor

Summary / 概述

Phase 3 of Agent Teams (#81): 添加智能任务路由,根据消息内容自动选择最佳 provider。
Adds smart task routing that auto-selects the best provider based on message content.

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

新文件 / New Files

  • lib/task_router.py (210 行) — 关键词匹配、team 技能匹配、统一路由入口
  • test/test_task_router.py (278 行) — 46 个测试覆盖所有路由路径

修改 / Modified

  • bin/ask — 新增 --auto 标志,重构参数解析以支持自动模式

使用方式 / Usage

# 自动模式:根据消息内容选择 provider
ask --auto "帮我写一个 React 前端组件"
# [AUTO] → gemini (keywords: react, 前端)

ask --auto "分析这个算法的时间复杂度"
# [AUTO] → codex (keywords: 算法, 复杂度)

ask --auto "翻译这段话成英文"
# [AUTO] → kimi (keywords: 翻译)

ask --auto "用 Python 实现快排"
# [AUTO] → qwen (keywords: python, 实现)

ask --auto "请审查这段代码"
# [AUTO] → codex (keywords: 审查)

ask --auto "帮我重构架构"
# [AUTO] → claude (keywords: 重构, 架构)

# 配合 team 配置使用:team 技能匹配优先于关键词
# With team config: team skill matching takes priority
ask --auto "build react frontend"
# [AUTO] → team:fe (react, frontend)  ← team skill match wins

# 其他模式不受影响 / Other modes unchanged
ask codex "hello"         # 直接指定 provider
ask a "hello"             # 别名
ask researcher "hello"    # team agent 名称

路由规则 / Routing Rules

关键词 → Provider 映射 / Keyword → Provider mapping:

关键词 / Keywords Provider Model 权重 / Weight
frontend, 前端, react, vue, css, ui, 设计 gemini 3f 1.5
algorithm, 算法, math, 数学, 推理, logic codex o3 1.5
review, 审查, audit, security, 安全 codex o3 1.5
python, 编程, code, sql, database, 数据库 qwen - 1.0
中文, 翻译, translate, 写作, 文档, 总结 kimi thinking 1.0
explain, 解释, shell, bash, 运维 kimi - 0.8
architecture, 架构, 重构, refactor claude - 1.0

路由优先级 / Resolution order:

  1. Team 技能匹配(如果有 team 配置)/ Team skill matching (if team config exists)
  2. 关键词匹配(默认规则)/ Keyword matching (default rules)
  3. 默认 fallback (kimi) / Default fallback

设计要点 / Design

特性 说明
加权评分 / Weighted scoring 匹配数 × 权重,最高分胜出
中英文关键词 / CN+EN keywords 同时支持中文和英文关键词匹配
Team 优先 / Team priority 有 team 配置时,技能匹配优先于通用关键词
可扩展规则 / Extensible rules route_by_keywords() 接受自定义 rules 和 fallback
Daemon 零改动 / Zero daemon changes 路由完全在 bin/ask 客户端完成
[AUTO] 日志 / [AUTO] logging 自动模式在 stderr 输出选择结果和原因

阶段路线图 / Phased Roadmap

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

Relates to #81

测试计划 / Test plan

  • 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 — 132/132 passed (零回归)
  • 手动测试:ask --auto "React 前端" → gemini
  • 手动测试:ask --auto "算法分析" → codex
  • 手动测试:ask --auto "翻译" → kimi
  • 手动测试:配合 team.json 验证技能匹配优先

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
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.

1 participant