用途
Dynamic Router 是一个指挥者/子智能体(conductor/subagent)路由系统,用于根据任务复杂度和意图,将任务分派给合适的模型。它跨多个运行环境(harness)工作,包括 Anthropic、Cursor、OpenCode、Codex/OpenAI 和 Pi,采用共享核心加适配器(shared core + adapter)的模式。
其核心原则是:使用能胜任工作的最便宜模型。指挥者(conductor)评估任务,适配器(adapter)将其映射到当前运行环境的合适模型。
架构
整体流程为:用户任务 → 指挥者(核心,评估复杂度与意图并构建执行计划)→ 模型家族配置(每个运行环境的角色到模型映射)→ 适配器分派。
各运行环境对应的模型如下:
- anthropic:claude-haiku-4-5 / sonnet-4-6 / opus-4-8
- cursor:composer-mini / composer-2.5
- opencode:haiku / sonnet-4 / opus-4
- codex:gpt-5.4-mini / gpt-5.4 / gpt-5.5
- pi:haiku / sonnet-4 / opus-4
模型家族
Anthropic(默认)
| 角色 | 模型 | 用途 |
|---|---|---|
| LookupAgent | claude-haiku-4-5-20251001 | 文件扫描、快速查找 |
| WorkAgent | claude-sonnet-4-6 | 实现、标准编码 |
| PlannerAgent | claude-opus-4-8 | 架构、规划、难题 |
| DebuggerAgent | claude-sonnet-4-6 | 调试、根因分析 |
| RefactorAgent | claude-opus-4-8 | 重构、设计改进 |
Cursor
| 角色 | 模型 | 用途 |
|---|---|---|
| LookupAgent | composer-mini | 快速扫描、查找 |
| WorkAgent | composer-2.5 | 标准编码任务 |
| PlannerAgent | composer-2.5 | 架构、规划 |
| DebuggerAgent | composer-2.5 | 调试 |
| RefactorAgent | composer-2.5 | 重构 |
OpenCode(Kimi + OpenAI 混合)
来源:Kimi API(api.moonshot.cn/v1,兼容 OpenAI)、OpenAI API。
| 角色 | 模型 | 用途 |
|---|---|---|
| LookupAgent | kimi-k2.6 | 快速扫描(成本高效) |
| WorkAgent | kimi-k2.6 | 标准编码(成本高效) |
| PlannerAgent | gpt-5.5 | 架构、规划 |
| DebuggerAgent | kimi-k2.6 | 调试(成本高效) |
| RefactorAgent | gpt-5.5 | 重构 |
可通过环境变量按角色覆盖:OPENCODE_MODEL_LOOKUP、OPENCODE_MODEL_WORK 等。
Codex(OpenAI)
| 角色 | 模型 | 用途 |
|---|---|---|
| LookupAgent | gpt-5.4-mini | 快速扫描 |
| WorkAgent | gpt-5.4 | 标准编码 |
| PlannerAgent | gpt-5.5 | 架构、规划 |
| DebuggerAgent | gpt-5.4 | 调试 |
| RefactorAgent | gpt-5.5 | 重构 |
可通过环境变量按角色覆盖:OPENAI_MODEL_LOOKUP、OPENAI_MODEL_WORK 等。
Pi(Kimi + OpenAI 混合)
来源:Kimi API(api.moonshot.cn/v1,兼容 OpenAI)、OpenAI API。
| 角色 | 模型 | 用途 |
|---|---|---|
| LookupAgent | kimi-k2.6 | 快速扫描(成本高效) |
| WorkAgent | kimi-k2.6 | 标准编码(成本高效) |
| PlannerAgent | gpt-5.5 | 架构、规划 |
| DebuggerAgent | kimi-k2.6 | 调试(成本高效) |
| RefactorAgent | gpt-5.5 | 重构 |
可通过环境变量按角色覆盖:PI_MODEL_LOOKUP、PI_MODEL_WORK 等。
路由逻辑
指挥者将任务分为三个复杂度层级:
| 复杂度 | 信号 | 示例 |
|---|---|---|
| 简单(Trivial) | find、scan、search、list、quick、show | “find all files with TODO” |
| 中等(Moderate) | implement、fix、write、add、update、test | “implement user signup endpoint” |
| 复杂(Complex) | architect、design、plan、migrate、evaluate | “design a real-time notification system” |
意图类别包括:查找(Lookup)、实现(Implementation)、规划(Planning)、调试(Debugging)、重构(Refactoring)。
同时包含规划与实现的任务会自动串联为多步计划。
使用方式
CLI 命令
# 默认使用 Anthropic 适配器
/dynamic-task "find all TypeScript files in the project"
# 指定运行环境
/dynamic-task --harness cursor "implement a new REST endpoint"
/dynamic-task --harness codex "design a real-time notification system"
编程调用
import { conduct, routeTask, planTask } from "./src/agents/claude-router";
// 默认(Anthropic)
const result = await conduct({ task: "fix the auth bug" });
// 指定运行环境
const result = await conduct({ task: "fix the auth bug" }, "cursor");
const result = await conduct({ task: "fix the auth bug" }, "codex");
// 快速路由
const decision = routeTask("design a new architecture", "codex");
// → { role: "planner", model: "gpt-5.5" }
// 构建计划
const plan = planTask("plan and implement a feature", "cursor");
// → { isChained: true, steps: [planner, work] }
自定义适配器
import { RouterAdapter, SubagentRole, route } from "./src/agents/claude-router";
const myAdapter: RouterAdapter = {
name: "custom",
models: {
[SubagentRole.LOOKUP]: "my-fast-model",
[SubagentRole.WORK]: "my-balanced-model",
[SubagentRole.PLANNER]: "my-strongest-model",
[SubagentRole.DEBUGGER]: "my-balanced-model",
[SubagentRole.REFACTORER]: "my-strongest-model",
},
async execute(decision, prompt) {
// Call your custom API
},
};
const decision = route("implement auth", myAdapter.models);
文件结构
src/agents/claude-router/
├── core/
│ ├── types.ts # Harness-neutral types, ModelFamily, RouterAdapter
│ ├── router.ts # assessComplexity, detectIntent, selectRole, route, buildPlan
│ └── index.ts # Core exports
├── adapters/
│ ├── anthropic.ts # Claude models (haiku, sonnet, opus)
│ ├── cursor.ts # Cursor SDK models (composer-mini, composer-2.5)
│ ├── opencode.ts # Hybrid Kimi (kimi-k2.6) + OpenAI (gpt-5.5)
│ ├── codex.ts # OpenAI models (gpt-5.4-mini, gpt-5.4, gpt-5.5)
│ ├── pi.ts # Hybrid Kimi (kimi-k2.6) + OpenAI (gpt-5.5)
│ ├── shared.ts # Adapter helpers
│ └── index.ts # Adapter registry
├── conductor.ts # High-level API (conduct, routeTask, planTask)
├── index.ts # Public API exports
└── __tests__/
└── conductor.test.ts
与 v1 的区别
v1 仅支持 Anthropic,且模型常量为硬编码。v2 将以下部分分离:
- 核心路由(复杂度/意图/角色选择)——运行环境中立,不导入 SDK
- 模型家族(角色到模型 ID 映射)——每个运行环境一份
- 适配器(执行)——每个运行环境一份,实现 RouterAdapter 接口
这与现有代码库中 agents/runner-shared/drivers/ 的工作方式一致。
适用场景与限制
适用场景:需要在多个运行环境之间按任务复杂度与意图自动选择模型、以控制成本并匹配任务难度的编码与开发工作流。
限制:资料未提供安装命令、收费与价格信息、具体平台支持细节及实际效果数据,暂未提供。