Skip to content
Snow leopard edited this page Jul 16, 2026 · 1 revision

Agent Cluster

Multi-Agent Collaboration and Orchestration

多智能体协作与编排


CogitoAgent supports sub-agent creation and management, enabling multi-agent collaboration for complex tasks. The orchestration system allows you to spawn specialized agents, delegate tasks, run parallel executions, and facilitate panel discussions.

CogitoAgent 支持子智能体的创建和管理,实现多智能体协作以完成复杂任务。编排系统允许您生成专用 Agent、委派任务、并行执行以及促进圆桌讨论。


Cluster Architecture | 集群架构

flowchart TB
    subgraph MASTER["Master Agent | 主智能体"]
        ORCH["Orchestrator<br/>orchestrator.ts"]
        AGENT["Agent.ts<br/>Think Cycle"]
    end

    subgraph SUB["Sub-Agents | 子智能体"]
        AG1["Sub-Agent 1<br/>子智能体 1"]
        AG2["Sub-Agent 2<br/>子智能体 2"]
        AG3["Sub-Agent N<br/>子智能体 N"]
    end

    subgraph FEATURES["Collaboration Modes | 协作模式"]
        PARALLEL["Parallel Execute<br/>并行执行"]
        PANEL["Panel Discussion<br/>圆桌讨论"]
        PIPELINE["Pipeline<br/>流水线"]
        VOTING["Voting<br/>投票"]
    end

    ORCH --> AG1
    ORCH --> AG2
    ORCH --> AG3
    ORCH --> FEATURES

    AG1 --> PARALLEL
    AG2 --> PARALLEL
    AG3 --> PARALLEL

    AG1 --> PANEL
    AG2 --> PANEL
    AG3 --> PANEL

    AG1 --> PIPELINE
    AG2 --> PIPELINE
    AG3 --> PIPELINE

    AG1 --> VOTING
    AG2 --> VOTING
    AG3 --> VOTING

    classDef master fill:#1a2332,stroke:#5eead4,color:#5eead4
    classDef sub fill:#1a2332,stroke:#38bdf8,color:#38bdf8
    classDef features fill:#1a2332,stroke:#fbbf24,color:#fbbf24

    class ORCH,AGENT master
    class AG1,AG2,AG3 sub
    class PARALLEL,PANEL,PIPELINE,VOTING features
Loading

Sub-Agent Lifecycle | 子智能体生命周期

stateDiagram-v2
    [*] --> IDLE: spawnAgent()<br/>生成

    IDLE --> THINKING: delegateTask()<br/>委派任务
    IDLE --> [*]: stopAgent()<br/>停止

    THINKING --> TOOL_EXECUTING: Tool call<br/>工具调用
    THINKING --> DONE: No more tools<br/>无需更多工具
    THINKING --> ERROR: Error<br/>错误

    TOOL_EXECUTING --> THINKING: Tool result<br/>工具结果
    TOOL_EXECUTING --> ERROR: Tool error<br/>工具错误

    DONE --> [*]: stopAgent()<br/>停止

    ERROR --> [*]: stopAgent()<br/>停止

    classDef idle fill:#94a3b8,color:#0b0e14
    classDef thinking fill:#fbbf24,color:#0b0e14
    classDef exec fill:#38bdf8,color:#0b0e14
    classDef done fill:#5eead4,color:#0b0e14
    classDef error fill:#f87171,color:#0b0e14

    class IDLE idle
    class THINKING thinking
    class TOOL_EXECUTING exec
    class DONE done
    class ERROR error
Loading

State Descriptions | 状态说明

State Description 说明
IDLE Waiting for task assignment 等待任务分配
THINKING Actively reasoning and planning 正在推理和规划
TOOL_EXECUTING Executing a tool 正在执行工具
DONE Task completed successfully 任务成功完成
ERROR Task failed with error 任务失败

Core Operations | 核心操作

Spawning an Agent | 生成智能体

The spawnAgent tool creates a new sub-agent with a specific persona and instruction.

spawnAgent 工具创建一个具有特定人设和指令的新子智能体。

[TOOL] spawnAgent("Critic", "CodeReviewer", "You review code quality and provide constructive feedback") [/TOOL]

Parameters | 参数

Parameter Description 说明
persona Persona name (e.g., "Critic", "Programmer") 人设名称(如 "Critic"、"Programmer")
name Agent display name 智能体显示名称
instruction Role instruction / task description 角色指令/任务描述

Response | 响应

{
  "success": true,
  "data": {
    "id": "agent_1",
    "name": "CodeReviewer",
    "persona": "Critic",
    "instruction": "You review code quality...",
    "createdAt": "2026-07-16T10:30:00.000Z"
  }
}

Delegating a Task | 委派任务

The delegateTask tool assigns a task to a specific sub-agent.

delegateTask 工具将任务分配给特定的子智能体。

[TOOL] delegateTask("agent_1", "Review the function calculateTotal() in src/math.ts") [/TOOL]

Parameters | 参数

Parameter Description 说明
agentId Agent ID from spawnAgent 来自 spawnAgent 的智能体 ID
task Task description 任务描述

Collaboration Modes | 协作模式

1. Parallel Execution | 并行执行

Execute multiple tasks simultaneously using different agents.

使用不同的智能体同时执行多个任务。

[TOOL] parallelExecute("[{\"agentId\":\"agent_1\",\"task\":\"Write a function to add two numbers\"},{\"agentId\":\"agent_2\",\"task\":\"Write a function to multiply two numbers\"}]") [/TOOL]

Flow | 流程

flowchart LR
    START["Start | 开始"] --> SPLIT["Split tasks<br/>拆分任务"]

    SPLIT --> A1["Agent 1<br/>Task A"]
    SPLIT --> A2["Agent 2<br/>Task B"]
    SPLIT --> A3["Agent N<br/>Task N"]

    A1 --> JOIN["Join results<br/>合并结果"]
    A2 --> JOIN
    A3 --> JOIN

    JOIN --> DONE["Done | 完成"]

    classDef start fill:#1a2332,stroke:#5eead4,color:#5eead4
    classDef agents fill:#1a2332,stroke:#38bdf8,color:#38bdf8
    classDef join fill:#1a2332,stroke:#fbbf24,color:#fbbf24

    class START,SPLIT start
    class A1,A2,A3 agents
    class JOIN,DONE join
Loading

2. Panel Discussion | 圆桌讨论

Multiple agents discuss a topic, each providing their perspective.

多个智能体就某个主题进行讨论,各自提供观点。

[TOOL] panelDiscussion("AI safety and ethics", "[\"agent_1\", \"agent_2\", \"agent_3\"]", "Please provide balanced perspectives") [/TOOL]

Flow | 流程

flowchart LR
    TOPIC["Topic: AI Ethics<br/>主题:AI 伦理"] --> A1["Agent 1<br/>观点 A"]
    TOPIC --> A2["Agent 2<br/>观点 B"]
    TOPIC --> A3["Agent 3<br/>观点 C"]

    A1 --> COLLECT["Collect opinions<br/>收集观点"]
    A2 --> COLLECT
    A3 --> COLLECT

    COLLECT --> SUMMARY["Summary<br/>总结"]

    classDef topic fill:#1a2332,stroke:#5eead4,color:#5eead4
    classDef agents fill:#1a2332,stroke:#38bdf8,color:#38bdf8
    classDef output fill:#1a2332,stroke:#fbbf24,color:#fbbf24

    class TOPIC topic
    class A1,A2,A3 agents
    class COLLECT,SUMMARY output
Loading

3. Pipeline | 流水线

Agents work sequentially, where one agent's output becomes the next agent's input.

智能体顺序工作,前一个智能体的输出成为下一个智能体的输入。

[TOOL] pipeline("[{\"agentId\":\"agent_1\",\"task\":\"Write a function to calculate factorial\",\"name\":\"Write Code\"},{\"agentId\":\"agent_2\",\"task\":\"Review the code from previous step\",\"name\":\"Review Code\"}]") [/TOOL]

Flow | 流程

flowchart LR
    A1["Agent 1<br/>Write Code<br/>写代码"] -->|"Output<br/>输出"| A2["Agent 2<br/>Review Code<br/>审查代码"]
    A2 -->|"Output<br/>输出"| A3["Agent 3<br/>Test Code<br/>测试代码"]
    A3 -->|"Final Output<br/>最终输出"| DONE["Done<br/>完成"]

    classDef agents fill:#1a2332,stroke:#38bdf8,color:#38bdf8
    classDef done fill:#1a2332,stroke:#5eead4,color:#5eead4

    class A1,A2,A3 agents
    class DONE done
Loading

4. Voting | 投票

Multiple agents vote on a question or decision.

多个智能体对某个问题或决策进行投票。

[TOOL] voting("Should we use React or Vue for this project?", "[\"agent_1\", \"agent_2\", \"agent_3\"]", "[\"React\", \"Vue\"]") [/TOOL]

Flow | 流程

flowchart LR
    QUESTION["Question<br/>问题"] --> A1["Agent 1<br/>Vote: React"]
    QUESTION --> A2["Agent 2<br/>Vote: Vue"]
    QUESTION --> A3["Agent 3<br/>Vote: React"]

    A1 --> TALLY["Tally votes<br/>统计票数"]
    A2 --> TALLY
    A3 --> TALLY

    TALLY --> RESULT["Result: React wins<br/>结果:React 胜出"]

    classDef question fill:#1a2332,stroke:#5eead4,color:#5eead4
    classDef agents fill:#1a2332,stroke:#38bdf8,color:#38bdf8
    classDef result fill:#1a2332,stroke:#fbbf24,color:#fbbf24

    class QUESTION question
    class A1,A2,A3 agents
    class TALLY,RESULT result
Loading

Cluster Commands | 集群命令

CLI Commands | 命令行命令

Command Description 说明
/agents Show cluster status 显示集群状态
/cluster Show cluster status 显示集群状态
/spawn <persona> <name> <instruction> Spawn a sub-agent 生成子智能体
/delegate <agentId> <task> Delegate a task 委派任务
/stop-agent <agentId> Stop a sub-agent 停止子智能体
/stop-all-agents Stop all sub-agents 停止所有子智能体

Tool Commands | 工具命令

Tool Description 说明
spawnAgent(persona, name, instruction) Create a sub-agent 创建子智能体
delegateTask(agentId, task) Delegate a task 委派任务
getClusterStatus() Get cluster status 获取集群状态
getAgent(agentId) Get agent details 获取智能体详情
stopAgent(agentId) Stop a sub-agent 停止子智能体
stopAllAgents() Stop all sub-agents 停止所有子智能体
parallelExecute(tasks) Execute tasks in parallel 并行执行任务
panelDiscussion(topic, agentIds, moderatorInstruction) Panel discussion 圆桌讨论
pipeline(steps) Sequential pipeline 流水线执行
voting(question, agentIds, options) Multi-agent voting 多智能体投票

Monitoring the Cluster | 监控集群

The monitoring dashboard provides real-time visualization of the agent cluster.

监控面板提供智能体集群的实时可视化。

Cluster Status | 集群状态

/cluster

Output | 输出

╔══════════════════════════════════════════════════════════════╗
║  🤖 Agent Cluster (3 agents)                                ║
╠══════════════════════════════════════════════════════════════╣
║                                                              ║
║  State overview: idle: 1, thinking: 1, done: 1              ║
║                                                              ║
║  🟢 CodeReviewer (agent_1)                                  ║
║      Persona: Critic                                        ║
║      State: done                                            ║
║      Tool calls: 5                                          ║
║      Iterations: 3                                          ║
║                                                              ║
║  🟡 Writer (agent_2)                                        ║
║      Persona: Programmer                                    ║
║      State: thinking                                        ║
║      Tool calls: 2                                          ║
║      Iterations: 1                                          ║
║                                                              ║
║  ⚪ Tester (agent_3)                                         ║
║      Persona: Explorer                                      ║
║      State: idle                                            ║
║      Tool calls: 0                                          ║
║      Iterations: 0                                          ║
║                                                              ║
╚══════════════════════════════════════════════════════════════╝

Cluster Topology | 集群拓扑

The monitoring dashboard visualizes the cluster as a topology graph:

监控面板将集群可视化为拓扑图:

flowchart TB
    subgraph TOPOLOGY["Cluster Topology | 集群拓扑"]
        MASTER["🟢 Master Agent<br/>主智能体"]
        A1["🔵 CodeReviewer<br/>(Critic) done"]
        A2["🟡 Writer<br/>(Programmer) thinking"]
        A3["⚪ Tester<br/>(Explorer) idle"]
    end

    MASTER -->|"delegates"| A1
    MASTER -->|"delegates"| A2
    MASTER -->|"delegates"| A3

    classDef master fill:#1a2332,stroke:#5eead4,color:#5eead4
    classDef done fill:#1a2332,stroke:#5eead4,color:#5eead4
    classDef thinking fill:#1a2332,stroke:#fbbf24,color:#fbbf24
    classDef idle fill:#1a2332,stroke:#94a3b8,color:#94a3b8

    class MASTER master
    class A1 done
    class A2 thinking
    class A3 idle
Loading

Use Cases | 使用场景

Code Review Pipeline | 代码审查流水线

flowchart LR
    WRITE["Write Code<br/>Programmer"] --> REVIEW["Review Code<br/>Critic"]
    REVIEW --> REFINE["Refine Code<br/>Programmer"]
    REFINE --> TEST["Test Code<br/>Explorer"]
    TEST --> DONE["Ready to Merge<br/>准备合并"]

    classDef step fill:#1a2332,stroke:#38bdf8,color:#38bdf8
    classDef done fill:#1a2332,stroke:#5eead4,color:#5eead4

    class WRITE,REVIEW,REFINE,TEST step
    class DONE done
Loading
[TOOL] pipeline("[{\"agentId\":\"programmer\",\"task\":\"Write a function to sort an array\"},{\"agentId\":\"critic\",\"task\":\"Review the code and suggest improvements\"},{\"agentId\":\"explorer\",\"task\":\"Test the function with edge cases\"}]") [/TOOL]

Decision Voting | 决策投票

[TOOL] voting("Which database should we use?", "[\"agent_1\", \"agent_2\", \"agent_3\"]", "[\"PostgreSQL\", \"MongoDB\", \"SQLite\"]") [/TOOL]

Parallel Research | 并行研究

[TOOL] parallelExecute("[{\"agentId\":\"researcher1\",\"task\":\"Research AI trends in North America\"},{\"agentId\":\"researcher2\",\"task\":\"Research AI trends in Europe\"},{\"agentId\":\"researcher3\",\"task\":\"Research AI trends in Asia\"}]") [/TOOL]

Configuration | 配置

Parameter Default Description
maxIterations 5 Maximum thinking iterations per agent
maxToolOutput 5000 Maximum tool output size for sub-agents
personaPath personas/ Directory containing personas
参数 默认值 说明
maxIterations 5 每个智能体的最大思考迭代次数
maxToolOutput 5000 子智能体的最大工具输出大小
personaPath personas/ 人设文件所在目录

Next Steps | 下一步


Previous: Extensions →

Next: WeChat Integration →

上一篇: 扩展功能 →

下一篇: 微信集成 →

Clone this wiki locally