【多智能体cooragent】CoorAgent 系统中 5 个核心系统组件分析
一、介绍
本文是基于cooragent 的一个说明文章。
原项目的github链接:
https://github.com/LeapLabTHU/cooragenthttps://github.com/LeapLabTHU/cooragent
本文分析 CoorAgent 系统中的 5 个核心系统组件,判断它们是否符合"智能体"的定义标准,并详细说明其实现机制和功能特点。
二、智能体判定标准
基于代码分析,我们将"智能体"定义为具备以下特征的组件:
- 独立的LLM支持 - 拥有专属的大语言模型实例
- 专门的prompt模板 - 具有定义其行为的专用提示词
- 自主思考决策能力 - 能够基于输入进行推理和决策
- 结构化的工作流程 - 有明确的执行步骤和输出格式
三、详细分析结果
1、智能体组件 (4个)
(1)coordinator - 协调者智能体
智能体特征确认:
- LLM配置:
AGENT_LLM_MAP["coordinator"] = "basic"
- 专用prompt:
src/prompts/coordinator.md
- 核心职责: 分析用户请求,决定处理路径
实现机制:
messages = apply_prompt_template("coordinator", state)
response = await get_llm_by_type(AGENT_LLM_MAP["coordinator"]).ainvoke(messages)
智能决策能力:
- 分类用户请求类型(直接回复 vs 任务移交)
- 输出
handover_to_planner()
或直接答案 - 支持多语言一致性处理
工作流程:
用户输入 → 请求分析 → 分类判断 → 路由决策 → 输出结果
(2)planner - 规划者智能体
智能体特征确认:
- LLM配置:
AGENT_LLM_MAP["planner"] = "reasoning"
(推理模型) - 专用 prompt:
src/prompts/planner.md
- 核心职责: 复杂任务分解和执行规划
实现机制:
messages = apply_prompt_template("planner", state)
llm = get_llm_by_type(AGENT_LLM_MAP["planner"])
if state.get("deep_thinking_mode"):llm = get_llm_by_type("reasoning")
智能决策能力:
- 分析复杂任务需求
- 选择合适的执行代理组合
- 决定是否需要创建新代理
- 生成详细的分步执行计划
特殊功能:
- 支持搜索增强规划 (
search_before_planning
) - 深度思考模式 (
deep_thinking_mode
)
(3)publisher - 发布者智能体
智能体特征确认:
- LLM配置:
AGENT_LLM_MAP["publisher"] = "basic"
- 专用prompt:
src/prompts/publisher.md
- 核心职责: 基于计划决定下一个执行代理
实现机制:
messages = apply_prompt_template("publisher", state)
response = await (get_llm_by_type(AGENT_LLM_MAP["publisher"]).with_structured_output(Router) # 结构化输出.ainvoke(messages)
)
智能决策能力:
- 解析执行计划中的步骤序列
- 跟踪当前执行进度
- 决定下一个执行代理或结束流程
- 输出标准化的路由格式
{"next": "agent_name"}
或{"next": "FINISH"}
决策逻辑:
检查步骤列表 → 定位当前位置 → 判断是否最后步骤 → 返回下一代理/结束
(4)agent_factory - 代理工厂智能体 ⭐
智能体特征确认:
- LLM配置:
AGENT_LLM_MAP["agent_factory"] = "basic"
- 专用prompt:
src/prompts/agent_factory.md
(146行详细规范) - 核心职责: 动态创建专用智能体
实现机制:
messages = apply_prompt_template("agent_factory", state)
agent_spec = await (get_llm_by_type(AGENT_LLM_MAP["agent_factory"]).with_structured_output(AgentBuilder).ainvoke(messages)
)
高级智能能力:
- 元认知能力: 设计其他AI代理的AI
- 架构思维: 创建通用、可复用的代理
- 工具选择专家: 基于"最小权限原则"精确选择工具
- prompt工程师: 为新代理编写完整的行为指导
创建流程:
需求分析 → LLM类型选择 → 工具筛选 → prompt构建 → 代理实例化
输出标准: AgentBuilder
接口
interface AgentBuilder {agent_name: string;agent_description: string;thought: string;llm_type: string;selected_tools: Tool[];prompt: string;
}
2、非智能体组件 (1个)
(5)agent_proxy - 代理调用器
非智能体特征:
- 无独立LLM: 不使用自己的语言模型
- 无专用prompt: 没有独立的思考逻辑
- 功能定位: 代理执行的"中介"或"调用器"
实际功能:
_agent = agent_manager.available_agents[state["next"]]
agent = create_react_agent(get_llm_by_type(_agent.llm_type), # 使用目标代理的LLMtools=[agent_manager.available_tools[tool.name] for tool in _agent.selected_tools],prompt=apply_prompt(state, _agent.prompt), # 使用目标代理的prompt
)
response = await agent.ainvoke(state, config=config)
角色定位:
- 根据
state["next"]
获取真正的执行代理 - 创建 ReAct 代理实例
- 调用实际的执行代理(如 researcher, coder, browser)
- 相当于"代理的代理"或"执行代理器"
四、系统架构总结
1、组件分类
CoorAgent 系统组件分类:
├── 🧠 系统智能体 (4个)
│ ├── coordinator [基础LLM + 协调prompt] - 请求路由
│ ├── planner [推理LLM + 规划prompt] - 任务规划
│ ├── publisher [基础LLM + 发布prompt] - 执行调度
│ └── agent_factory [基础LLM + 构建prompt] - 代理创建 ⭐
└── 🔧 调用器组件 (1个)└── agent_proxy [无LLM,调用执行代理] - 代理调用
2、智能体层次结构
-
系统智能体: 负责工作流控制和决策
- 具备独立思考能力
- 有专门的AI模型和提示词
- 承担系统级的协调、规划、调度任务
-
执行智能体: 负责具体任务执行
- researcher, coder, browser, reporter 等
- 通过 agent_proxy 调用
-
元智能体:
- agent_factory 是特殊的"元智能体"
- 具备创造其他智能体的能力
- 体现了AI系统的自我扩展特性
3、工作流程
用户请求 → coordinator → planner → publisher → [agent_factory] → agent_proxy → 执行代理
五、结论
在 CoorAgent 的5个核心系统组件中:
- 4个是智能体: coordinator, planner, publisher, agent_factory
- 1个是调用器: agent_proxy
其中,agent_factory 是最特殊的"元智能体",它不仅具备完整的AI能力,还能创造其他智能体,体现了系统的动态扩展和自我进化能力。
这种设计体现了 CoorAgent 系统的核心理念:通过多个专业化的智能体协作,实现复杂任务的自动化分解、规划和执行。