Skip to content

3. 多 Agent 系统架构

3.1 核心架构图

┌─────────────────────────────────────────────────────────────────────────────┐
│                          Manus Multi-Agent System                            │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐          │
│  │    Planner      │───▶│    Executor     │───▶│    Verifier     │          │
│  │   (任务规划)     │    │   (任务执行)     │    │   (结果验证)     │          │
│  └────────┬────────┘    └────────┬────────┘    └────────┬────────┘          │
│           │                      │                      │                    │
│           │    ┌─────────────────┴─────────────────┐    │                    │
│           │    │                                   │    │                    │
│           ▼    ▼                                   ▼    ▼                    │
│  ┌─────────────────────────────────────────────────────────────┐            │
│  │                    Tool Router (工具路由)                     │            │
│  └─────────────────────────────────────────────────────────────┘            │
│           │              │              │              │                     │
│           ▼              ▼              ▼              ▼                     │
│  ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐        │
│  │   Browser    │ │  FileSystem  │ │    Shell     │ │Communication │        │
│  │    Agent     │ │    Agent     │ │    Agent     │ │    Agent     │        │
│  └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘        │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────┐            │
│  │              Knowledge Retriever (知识检索)                   │            │
│  │         Memory / Context / External Knowledge Base           │            │
│  └─────────────────────────────────────────────────────────────┘            │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────┐            │
│  │                  Sandbox VM (隔离沙盒环境)                    │            │
│  │              Linux Container / Virtual Machine               │            │
│  └─────────────────────────────────────────────────────────────┘            │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

3.2 核心 Agent 组件

typescript
// Planner Agent - 任务规划
interface PlannerAgent {
  // 将用户需求转化为结构化任务
  async planTask(userRequest: string, context: Context): Promise<TaskPlan>;
  
  // 动态调整计划
  async replan(currentState: State, obstacle: Obstacle): Promise<TaskPlan>;
}

// Executor Agent - 任务执行  
interface ExecutorAgent {
  // 执行单个步骤
  async executeStep(step: TaskStep, tools: ToolSet): Promise<StepResult>;
  
  // 错误恢复
  async recover(error: ExecutionError): Promise<RecoveryResult>;
}

// Knowledge Retriever - 知识检索
interface KnowledgeRetriever {
  // 检索相关知识
  async retrieve(query: string): Promise<Knowledge[]>;
  
  // 存储新知识
  async store(knowledge: Knowledge): Promise<void>;
}

3.3 任务规划器实现

typescript
class TaskPlanner {
  private llm: LLMClient;
  
  async plan(userRequest: string, context: Context): Promise<TaskPlan> {
    const response = await this.llm.chat({
      messages: [{
        role: "system",
        content: PLANNER_SYSTEM_PROMPT
      }, {
        role: "user",
        content: `
User Request: ${userRequest}

Current Context:
- Working Directory: ${context.cwd}
- Available Tools: ${context.tools.join(', ')}
- Previous Actions: ${context.history.slice(-5).join(' → ')}
- Current Time: ${new Date().toISOString()}

Create a detailed execution plan with concrete, verifiable steps.
Output as JSON.`
      }]
    });
    
    return JSON.parse(response.content);
  }
}

const PLANNER_SYSTEM_PROMPT = `You are a task planner for an AI agent system.

Your job is to:
1. Understand the user's goal
2. Break it down into concrete, executable steps  
3. Identify which tools are needed for each step
4. Define success criteria for each step
5. Anticipate potential issues and plan fallbacks

Output format:
{
  "goal": "Clear statement of the overall objective",
  "steps": [
    {
      "id": 1,
      "description": "What to do",
      "tool": "Which tool to use",
      "params": { "key": "value" },
      "success_criteria": "How to verify this step succeeded",
      "fallback": "What to try if this fails"
    }
  ],
  "estimated_time": "How long this might take",
  "deliverables": ["List of expected outputs"]
}`;

前端面试知识库