Back to series
· 14 min read

Multi-Agent Role Division and Communication


I. Why Role Division and Communication Are Needed

A single Agent usually needs to simultaneously handle responsibilities such as task understanding, information retrieval, analytical reasoning, tool invocation, result verification, and content generation. As task complexity continues to increase, a single Agent is prone to issues such as context overload, blurred responsibilities, degraded reasoning quality, and insufficient execution efficiency.

A Multi-Agent system divides a complex task into multiple relatively independent subtasks through the collaboration of multiple Agents with different responsibilities.

For example, building a technical research report system can be divided into:

  • Planner Agent: responsible for understanding goals, formulating plans, and breaking down tasks.
  • Researcher Agent: responsible for retrieving materials and collecting evidence.
  • Analyst Agent: responsible for analyzing data and distilling conclusions.
  • Writer Agent: responsible for organizing content and generating reports.
  • Reviewer Agent: responsible for checking facts, logic, and format.
  • Coordinator Agent: responsible for scheduling Agents, managing state, and coordinating execution.

The core of Multi-Agent collaboration is not simply increasing the number of models, but establishing clear responsibility boundaries, collaboration rules, and communication mechanisms.

1.1 Three Core Issues of Multi-Agent Systems

Core Issue What Needs to Be Addressed
Role division What each Agent is responsible for and what it is not responsible for
Task collaboration How Agents exchange tasks, share results, and handle dependencies
Communication mechanism How Agents send messages, pass context, and feed back status

These three issues are interrelated.

Role division determines collaboration boundaries, the collaboration mechanism determines how tasks are executed, and the communication mechanism provides the infrastructure for collaboration.

II. Agent Role Design

Role design is the foundation of a Multi-Agent system. A reasonable role should have clear goals, responsibilities, inputs, outputs, and permissions.

2.1 Basic Structure of a Role

An Agent role usually consists of the following parts:

Component Description
Role Role name and identity positioning
Goal The goal the role needs to accomplish
Responsibility Specific tasks the role is responsible for
Input Data and context received
Output Data structure output
Tools Tools that can be used
Constraints Behavioral constraints and permission boundaries
Handoff Task handoff conditions

For example, a Researcher Agent can be defined as:

researcher = {
    "name": "Researcher",
    "goal": "收集与研究主题相关的可靠资料",
    "responsibilities": [
        "理解研究问题",
        "检索相关资料",
        "筛选可信来源",
        "整理证据和引用"
    ],
    "input": {
        "research_topic": "研究主题",
        "search_scope": "检索范围"
    },
    "output": {
        "summary": "资料摘要",
        "sources": [],
        "evidence": []
    },
    "tools": [
        "web_search",
        "document_reader"
    ],
    "constraints": [
        "不得编造来源",
        "必须区分事实与推测",
        "保留来源引用"
    ]
}

Role definition is not only a Prompt description; it should also be implemented in system interfaces, tool permissions, and output validation.

2.2 Common Agent Roles

Planning Agent (Planner)

Responsible for breaking down user goals into executable tasks.

Main responsibilities:

  • Analyze task goals.
  • Identify task dependencies.
  • Determine execution order.
  • Assign tasks to other Agents.
  • Adjust plans based on execution results.

A Planner does not necessarily complete all tasks personally; its core value is to establish a global execution plan.

Execution Agent (Executor)

Responsible for completing specific subtasks.

For example:

  • Invoke search tools.
  • Execute Python code.
  • Query databases.
  • Read files.
  • Call external APIs.

An Executor should focus on specific execution and should not undertake too many global scheduling responsibilities.

Specialist Agent (Specialist)

Responsible for professional analysis in a specific domain.

For example:

  • Data analysis Agent.
  • Legal analysis Agent.
  • Financial analysis Agent.
  • Programming Agent.
  • Security review Agent.

Specialist Agents usually have dedicated system prompts, tool sets, and domain knowledge.

Reviewer Agent

Responsible for checking the outputs of other Agents.

Common review items:

  • Whether facts are accurate.
  • Whether reasoning is complete.
  • Whether data is consistent.
  • Whether task requirements are met.
  • Whether there are security risks.

A Reviewer should not merely regenerate content; it should validate against explicit quality standards.

Coordinator Agent

Responsible for managing the collaboration process among multiple Agents.

Main responsibilities:

  • Manage Agent registration information.
  • Receive task requests.
  • Maintain task status.
  • Route messages.
  • Handle timeouts and failures.
  • Aggregate execution results.

In engineering implementations, the Coordinator is often handled by a deterministic scheduling service rather than necessarily by another large-model Agent.

2.3 Design Principles for Role Division

Principle 1: Single responsibility.

Each Agent should have a clear primary objective, avoiding multiple Agents being responsible for the same work without clear boundaries.

Principle 2: Clear responsibility boundaries.

For example, the Researcher collects evidence, the Analyst interprets evidence, and the Writer organizes the expression. Each Agent must not re-retrieve, re-analyze, and regenerate all content.

Principle 3: Standardized inputs and outputs.

Agents should pass structured data between them rather than relying on implicit information in natural language.

Principle 4: Least privilege.

Different roles should be granted only the tool and data permissions necessary to complete their tasks.

Principle 5: Moderate number of roles.

Increasing the number of Agents brings communication overhead, context costs, scheduling complexity, and the risk of error propagation. Roles are worth splitting only when tasks have clear professional boundaries or parallel benefits.

3. Multi-Agent Collaboration Organization Patterns

Once role division is determined, it is still necessary to decide how Agents are organized and collaborate.

Different organization patterns suit different task structures.

3.1 Hierarchical Collaboration

Hierarchical collaboration uses a tree structure, in which upper-level Agents handle planning and scheduling, and lower-level Agents handle execution.

flowchart TD
    A["User task"]
    B["Manager Agent"]
    C["Research Agent"]
    D["Analysis Agent"]
    E["Writing Agent"]
    F["Review Agent"]
    G["Final result"]

    A --> B
    B --> C
    B --> D
    B --> E
    B --> F
    C --> B
    D --> B
    E --> B
    F --> B
    B --> G

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#EAF3EC,stroke:#83A995,color:#315D49
    style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Characteristics:

  • Unified task entry point.
  • Clear scheduling relationships.
  • Easy to centrally manage state.
  • Suitable for decomposing complex tasks.
  • The Manager may become a performance bottleneck.

Applicable scenarios: research report generation, complex business processes, and office automation.

3.2 Sequential Collaboration

Multiple Agents execute in a predefined order, with the output of the previous Agent becoming the input of the next Agent.

flowchart TD
    A["Task input"]
    B["Researcher"]
    C["Analyst"]
    D["Writer"]
    E["Reviewer"]
    F["Final output"]

    A --> B
    B --> C
    C --> D
    D --> E
    E --> F

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Characteristics:

  • Clear execution order.
  • Simple to implement.
  • Easy to track task status.
  • Failure of an upstream task may block subsequent tasks.
  • Not suitable for parallel execution of many independent tasks.

Applicable scenarios: content production, code generation and review, and data processing pipelines.

3.3 Parallel Collaboration

Multiple Agents process independent tasks simultaneously, and an aggregator Agent finally merges the results.

flowchart TD
    A["Task Input"]
    B["Coordinator"]
    C["Agent A: Technical Research"]
    D["Agent B: Market Research"]
    E["Agent C: Competitive Analysis"]
    F["Result Aggregator"]
    G["Aggregated Result"]

    A --> B
    B --> C
    B --> D
    B --> E
    C --> F
    D --> F
    E --> F
    F --> G

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Characteristics:

  • Can use concurrency to improve execution efficiency.
  • Different Agents can approach a problem from different perspectives.
  • The aggregation stage needs to resolve conflicts between results.
  • Concurrent calls increase resource consumption.
  • Must handle cases where some tasks fail.

Applicable scenarios: multi-source information retrieval, independent data analysis, and solution comparison.

3.4 Peer-to-Peer Collaboration

Multiple Agents are in a relatively equal position and can exchange information directly according to task needs.

flowchart TD
    A["Agent A"]
    B["Agent B"]
    C["Agent C"]
    D["Agent D"]
    E["Shared Task State"]

    A <--> B
    B <--> C
    C <--> D
    D <--> A
    A <--> C
    B <--> D

    A <--> E
    B <--> E
    C <--> E
    D <--> E

    style A fill:#EAF3EC,stroke:#83A995,color:#315D49
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Characteristics:

  • Agents have a relatively high degree of autonomy.
  • They can engage in dynamic negotiation.
  • Suitable for multi-party discussion and comparison of viewpoints.
  • Communication relationships are complex.
  • Prone to circular discussions and duplicated work.

Applicable scenarios: multi-perspective problem analysis, negotiated decision-making, and complex simulation.

3.5 Hybrid Collaboration

Real production systems usually do not adopt only one pattern; instead, they combine multiple patterns according to the task structure.

For example:

  • The Planner uses hierarchical scheduling.
  • Independent retrieval tasks use parallel execution.
  • Data analysis and report generation use sequential execution.
  • A feedback loop is used between the Reviewer and the Writer.

The hybrid pattern offers greater flexibility but requires more robust task state management and communication protocols.

4. How Agents Communicate

Communication is the foundation of multi-Agent collaboration.

Agents should not rely solely on each other's conversation history for collaboration; instead, they should pass tasks, context, and execution results through an explicit message structure.

4.1 Basic Components of Communication

A complete Agent message usually contains the following information:

Field Purpose
message_id Unique message identifier
conversation_id Conversation it belongs to
task_id Associated task
sender Sender Agent
receiver Receiver Agent
message_type Message type
payload Message body
timestamp Message creation time
correlation_id Correlates requests and responses
trace_id Trace identifier for cross-Agent calls
metadata Extended information such as priority and version

A simple message structure:

```json { "message_id": "msg-1001", "conversation_id": "conv-001", "task_id": "task-101", "sender": "planner", "receiver": "researcher", "message_type": "task.assign", "correlation_id": "req-1001", "trace_id": "trace-001", "timestamp": "2026-11-20T10:00:00Z", "payload": { "objective": "Research multi-agent communication mechanisms", "requirements": [ "Compile communication protocols", "Analyze message routing", "Provide engineering recommendations" ] }, "metadata": { "priority": "high", "schema_version": "1.0" } } ```

Where:

  • message_id identifies an individual message.
  • task_id associates the message with a business task.
  • correlation_id matches requests with responses.
  • trace_id traces the entire distributed execution path.

These identifiers must not be conflated.

For example, a single task may produce multiple messages, and a single message may also trigger new subtasks.

4.2 Common Message Types

It is recommended to design message types as a finite, well-defined set of protocols.

Message Type Meaning
task.assign Assign a task
task.accept Accept a task
task.reject Reject a task
task.progress Report progress
task.result Return execution results
task.failed Task execution failed
task.cancel Cancel a task
message.request General request
message.response General response
context.update Update the shared context
review.feedback Review feedback
agent.handoff Hand off a task

By unifying message types, the Coordinator can apply different processing logic according to message semantics.

For example:

  • On receiving task.assign, create or start the task.
  • On receiving task.progress, update the task status.
  • On receiving task.result, store the result and check downstream dependencies.
  • On receiving task.failed, enter the failure-handling flow.

5. Agent Communication Patterns

Communication between agents differs not only in message format but also in interaction style.

5.1 Request-Response Mode

One agent sends a request to another agent and waits for the other party to return a result.

For example, the Planner asks the Researcher to gather materials.

sequenceDiagram
    participant P as Planner
    participant R as Researcher

    P->>R: task.assign
    R-->>P: task.accept
    R-->>P: task.progress
    R->>R: Perform data retrieval
    R-->>P: task.result

Suited to:

  • Tasks that require an explicit result.
  • Tool calls with a predictable execution time.
  • Synchronous collaboration between agents.

The drawback is that the caller may have to wait. If the downstream agent takes a long time to execute, synchronous waiting ties up connection and execution resources.

5.2 Asynchronous Messaging Mode

The sender returns immediately after submitting the task and does not need to wait for execution to finish.

The receiver processes the task asynchronously through a message queue or event system, and sends the result once it is complete.

flowchart TD
    A["Planner Submits Task"]
    B["Message Queue"]
    C["Researcher Consumes Messages"]
    D["Execute Retrieval"]
    E["Send Result Event"]
    F["Coordinator Receives Result"]
    G["Update Task Status"]

    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    F --> G

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#EAF3EC,stroke:#83A995,color:#315D49
    style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Advantages:

  • The sender and receiver are decoupled.
  • Supports long-running tasks.
  • It is easier to scale concurrent execution.
  • It can use message queues to smooth peak loads.

Disadvantages:

  • Message backlog needs to be managed.
  • Duplicate delivery needs to be handled.
  • Task timeouts and result correlation need to be managed.
  • System state is eventually consistent and may not be synchronized immediately.

5.3 Publish–Subscribe Pattern

Publishers send events to a topic, and subscribers receive events according to their subscriptions.

For example, after completing retrieval, the Researcher publishes the research.completed event, and multiple Agents can subscribe separately:

  • The Analyst is responsible for analyzing materials.
  • The Writer is responsible for preparing content.
  • The Audit Agent is responsible for checking citation sources.
flowchart TD
    A["Researcher"]
    B["research.completed Event"]
    C["Message Topic"]
    D["Analyst"]
    E["Writer"]
    F["Audit Agent"]

    A --> B
    B --> C
    C --> D
    C --> E
    C --> F

    style A fill:#EAF3EC,stroke:#83A995,color:#315D49
    style B fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#EAF3EC,stroke:#83A995,color:#315D49
    style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D

The publish–subscribe pattern is suitable for event-driven architectures, but attention must be paid to event idempotency, subscription relationships, and event versioning.

5.4 Direct Agent-to-Agent Communication

In some systems, an Agent can send messages directly to other Agents without going through a central coordinator.

For example:

  • The Analyst requests additional evidence from the Researcher.
  • The Reviewer sends revision comments to the Writer.
  • The Coding Agent requests testing from the Testing Agent.

Direct communication can reduce the pressure on central scheduling, but it also increases coupling between Agents.

In engineering practice, the scope of direct communication usually needs to be limited to avoid forming complex, untraceable message networks.

6. Shared Context and Message Passing

In multi-Agent systems, an important question is: how do multiple Agents share task information?

Common approaches include message passing, shared state, and hybrid modes.

6.1 Pure Message Passing

Each Agent receives only the data required for the task through messages.

For example:

{
  "sender": "researcher",
  "receiver": "analyst",
  "message_type": "task.result",
  "payload": {
    "research_summary": "研究摘要",
    "evidence": [
      {
        "content": "证据内容",
        "source": "来源地址"
      }
    ]
  }
}

Advantages:

  • Responsibility boundaries are clear.
  • Data transfer paths are clear.
  • Permission control is easy.
  • It does not rely on shared storage.

Disadvantages:

  • Messages may carry a large amount of duplicate data.
  • Multi-round collaboration tends to create redundant context.
  • The cost of managing messages for large tasks is relatively high.

6.2 Shared State

Multiple Agents access the same task state store.

For example:

task_state = {
    "task_id": "task-101",
    "status": "running",
    "research": {
        "status": "completed",
        "result": "研究结果"
    },
    "analysis": {
        "status": "pending",
        "result": None
    },
    "writing": {
        "status": "pending",
        "result": None
    }
}

Each agent only needs to read and update the state fields it is responsible for.

Advantages:

  • Reduces duplicated message transmission.
  • Makes it easy to share results across agents.
  • Suits complex workflows.
  • Supports task recovery and status inspection.

Disadvantages:

  • Requires solving concurrent write problems.
  • Prone to state overwrites.
  • Requires designing permissions and data isolation.
  • Shared state can become a system bottleneck.

6.3 Hybrid Context Management

Production systems usually adopt a hybrid model:

  • Messages carry task instructions and events.
  • Shared storage holds large task results.
  • Agents receive only the context relevant to the current task.
  • When necessary, the full data is retrieved via a reference ID.

For example:

{
  "message_type": "task.result",
  "task_id": "task-101",
  "payload": {
    "result_id": "result-2001",
    "summary": "检索任务已经完成",
    "storage_uri": "memory://task-101/research"
  }
}

The message carries only a summary and a result reference, while the full content is kept in shared storage.

This avoids repeatedly transferring large amounts of data between agents.

7. Task Handoff and Transfer of Control (Handoff)

Handoff is a key mechanism in multi-agent systems.

It means that after the current agent has completed its own responsibilities, it hands control of the task to another agent.

For example:

  • The Planner hands the retrieval task to the Researcher.
  • The Researcher hands the evidence to the Analyst.
  • The Analyst hands the analysis results to the Writer.
  • The Writer hands the first draft to the Reviewer.

7.1 Core Information of a Handoff

A task handoff must at minimum make clear:

  1. The current executor.
  2. The next executor.
  3. The reason for the handoff.
  4. The current task status.
  5. The work already completed.
  6. The remaining tasks.
  7. The context that needs to be passed along.
  8. Whether the original executor retains control.

For example:

{
  "message_type": "agent.handoff",
  "task_id": "task-101",
  "sender": "researcher",
  "receiver": "analyst",
  "payload": {
    "reason": "research_completed",
    "completed_work": [
      "收集相关资料",
      "筛选可靠来源",
      "整理关键证据"
    ],
    "next_action": "分析证据并提炼结论",
    "result_id": "result-2001"
  }
}

7.2 Handoff Execution Flow

flowchart TD
    A["Current Agent executes task"]
    B{"Are handoff conditions met?"}
    C["Continue current task"]
    D["Organize execution results"]
    E["Construct Handoff message"]
    F["Coordinator verifies handoff"]
    G{"Is target Agent available?"}
    H["Assign to target Agent"]
    I["Update task ownership"]
    J["Target Agent starts execution"]
    K["Handle handoff failure"]

    A --> B
    B -->|"No"| C
    C --> A
    B -->|"Yes"| D
    D --> E
    E --> F
    F --> G
    G -->|"Yes"| H
    H --> I
    I --> J
    G -->|"No"| K

    style A fill:#EAF3EC,stroke:#83A995,color:#315D49
    style B fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style K fill:#F7EAE7,stroke:#C98D7C,color:#754438

7.3 Differences Between Handoff and Regular Messages

Regular messages are mainly used to convey information and do not necessarily change the task executor.

A Handoff, by contrast, means that task control or execution responsibility changes.

Aspect Regular message Handoff
Main purpose Exchange information Transfer execution responsibility
Whether it changes the executor Not necessarily Usually yes
Whether task status updates are required Depends on the situation Usually required
Whether permission checks are involved Depends on the situation Should be checked
Whether context handoff is required Not necessarily Must ensure that the necessary context is complete

Without explicit Handoff semantics, the system is prone to problems such as two Agents executing the same task at the same time, or no one being responsible for the task.

8. Communication Protocols and Standardization

As the number of Agents increases, the system needs a unified communication protocol.

Otherwise, if each Agent uses its own message structure and invocation method, it will lead to a large amount of adaptation code.

8.1 Why Communication Protocols Are Needed

Communication protocols mainly address the following:

  • How Agents discover other Agents.
  • How to describe an Agent's capabilities.
  • How to send task requests.
  • How to pass task results.
  • How to perform identity authentication.
  • How to handle errors and timeouts.
  • How to negotiate message formats.

The protocol should abstract communication behavior from specific model implementations.

8.2 Agent Capability Description

The Coordinator needs to know what each Agent can do in order to route tasks correctly.

An Agent can be described using a structure similar to the following:

{
  "agent_id": "researcher-001",
  "name": "Researcher",
  "description": "Responsible for information retrieval and document organization",
  "capabilities": [
    "web_search",
    "document_retrieval",
    "source_validation"
  ],
  "input_schema": {
    "topic": "string",
    "scope": "string"
  },
  "output_schema": {
    "summary": "string",
    "sources": "array"
  },
  "endpoint": "agent://researcher-001",
  "status": "available"
}

Capability descriptions can be used for task routing, service discovery, and permission validation.

8.3 Common Agent Communication Protocols and Standards

MCP (Model Context Protocol)

MCP is mainly used to standardize the interaction between models and external tools and data sources.

It can help agents access tools and contextual resources, but it is not directly equivalent to a complete multi-agent orchestration protocol.

A2A (Agent2Agent Protocol)

A2A targets collaboration between different agents, focusing on agent capability discovery, task interaction, messaging, and task status.

It suits scenarios that require cross-agent and cross-system collaboration.

ACP (Agent Communication Protocol)

ACP is a protocol family designed around agent interoperability and communication. When making an actual choice, you need to verify the maintenance status, compatibility, and ecosystem support of the implementation you adopt; you cannot judge its suitability by the protocol name alone.

Custom Communication Protocols

For internal systems with clearly defined boundaries, you can also design your own message protocol.

But you need to standardize:

  • Message format.
  • Message version.
  • Error codes.
  • Authentication.
  • Task status.
  • Timeouts and retries.
  • Idempotency rules.

When choosing a protocol, focus on system boundaries and interoperability requirements, rather than adding unnecessary complexity just for the sake of using a particular protocol.

IX. Message Routing and Task Scheduling

In a multi-agent system, sending a message does not mean the target agent is necessarily able to execute the task.

The system also needs to determine:

  • Which agent has the required capability?
  • Which agent is currently available?
  • Which agent has a lower load?
  • Does the task have prerequisite dependencies?
  • Does it need to be dispatched in parallel?
  • Does the task need to be reassigned?

9.1 Capability-Based Routing

The Coordinator can match agents based on the capabilities required by the task.

For example:

agents = [
    {
        "name": "researcher",
        "capabilities": ["web_search", "document_retrieval"]
    },
    {
        "name": "analyst",
        "capabilities": ["data_analysis", "reasoning"]
    },
    {
        "name": "writer",
        "capabilities": ["content_generation"]
    }
]


def find_agents(required_capabilities):
    matches = []

    for agent in agents:
        capabilities = set(agent["capabilities"])

        if set(required_capabilities).issubset(capabilities):
            matches.append(agent)

    return matches


result = find_agents(["web_search", "document_retrieval"])
print(result)

This is a simple capability-matching example.

A production system also needs to consider agent status, load, task priority, and tenant isolation.

9.2 Common Routing Strategies

Routing strategy Description Applicable scenario
Fixed routing Tasks are sent directly to a specified agent Fixed workflows
Capability routing Agents are matched by capability Specialized division of labor
Load routing Assignment based on current load High-concurrency systems
Priority routing Assignment based on task priority Multi-level tasks
Dynamic routing Target adjusted based on execution results Complex tasks
Broadcast routing Sent to multiple agents at the same time Parallel analysis

9.3 Task Dependency Management

When multiple tasks depend on one another, the Coordinator needs to maintain the task dependencies.

For example:

  • Research A and Research B can run in parallel.
  • Analysis must wait for Research A and Research B to complete.
  • Writing must wait for Analysis to complete.
  • Review must wait for Writing to complete.

A directed acyclic graph (DAG) can be used to describe task dependencies.

flowchart TD
    A["Start"]
    B["Research A"]
    C["Research B"]
    D["Analysis"]
    E["Writing"]
    F["Review"]
    G["End"]

    A --> B
    A --> C
    B --> D
    C --> D
    D --> E
    E --> F
    F --> G

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F

A DAG can support:

  • Parallel task execution.
  • Dependency checks.
  • Locating failed tasks.
  • Partial retry.
  • Task recovery.
  • Execution progress statistics.

If there is a cycle in task dependencies, ordinary DAG scheduling cannot be used directly. Instead, the cycle must be modeled as an explicit iterative workflow, with termination conditions and a maximum number of iterations set.

10. Exception Handling in Communication

Communication in multi-agent systems involves networks, message queues, model calls, and external services, so various exceptions must be considered.

10.1 Common Communication Exceptions

Exception Possible Cause Handling Method
Agent unavailable Service offline, instance crash Reroute
Message send failure Network error, connection interruption Limited retries
Duplicate messages Duplicate delivery by message queue Idempotent processing
Message loss Consumption acknowledgment failure Persistence and compensation
Response timeout Agent execution too slow Timeout control
Output format error Model did not follow protocol Schema validation
Task deadlock Circular dependency, resource waiting Timeout and deadlock detection
Result conflict Inconsistent output among multiple agents Arbitration and validation

10.2 Message Reliability

Messaging systems generally cannot simply guarantee absolute once-only execution at the business level.

Common delivery semantics:

  • At-most-once: delivered at most once; messages may be lost.
  • At-least-once: delivered at least once; messages may be duplicated.
  • Exactly-once: usually requires specific mechanisms in the messaging system and business storage; a message queue alone cannot guarantee that the complete business chain is executed exactly once.

A common engineering choice is At-least-once plus business-level idempotency.

For example: