Back to series
· 17 min read

Multi-Agent Systems: Architectures, Collaboration Mechanisms, and Engineering Practices


I. What Is a Multi-Agent System

A Multi-Agent System (MAS) is a collaborative system composed of multiple Agents. Each Agent can have its own role definition, task goals, context, tool permissions, and decision-making capabilities, and together they complete complex tasks through communication and coordination mechanisms.

A traditional single-Agent system usually has one Agent responsible for understanding the task, making plans, calling tools, and generating results.

As task complexity increases, a single Agent is prone to the following problems:

  • The context becomes too long, making it difficult to manage large amounts of task information.
  • One Agent takes on multiple roles at the same time, which can easily lead to confused responsibilities.
  • Multiple tasks cannot be fully executed in parallel.
  • There is no independent review mechanism, making self-evaluation bias likely.
  • A single Agent has boundaries in its tools and professional capabilities.
  • Long tasks have complex execution processes and difficult state management.

Multi-Agent systems divide complex tasks among multiple specialized Agents through responsibility separation and collaboration mechanisms.

For example, to develop a complete software system, you can set up:

Agent Responsibility
Coordinator Agent Responsible for overall task coordination
Planner Agent Responsible for requirements analysis and task planning
Architect Agent Responsible for system architecture design
Developer Agent Responsible for code implementation
Tester Agent Responsible for testing and quality verification
Reviewer Agent Responsible for code review
Documentation Agent Responsible for technical documentation writing

Each Agent only needs to focus on the tasks it is responsible for, and the entire project is completed through collaboration.

1.1 Differences Between Agent and Multi-Agent

Dimension Single-Agent Multi-Agent
Executor One Agent Multiple Agents
Task allocation Handled by one Agent on its own Allocated by a coordination mechanism
Specialization Relies on the context and prompts of a single Agent Different Agents take on different roles
Parallel capability Limited Supports parallel tasks
Context management Centralized in one executor Can be isolated by role
Collaboration method Internal reasoning and tool calls Communication and collaboration between Agents
Quality control Mainly relies on self-verification Independent reviewers can be introduced
System complexity Relatively low Relatively high
Operating cost Usually low Usually high

Note: Multi-Agent does not necessarily mean it is stronger than single-Agent.

If the task itself is simple, communication, coordination, and result integration among multiple Agents may introduce additional costs.

Multi-Agent is truly suitable for tasks with clear division of labor, complex dependencies, room for parallelism, or independent review requirements.

1.2 Core Features of Multi-Agent

1. Autonomy

Each Agent can make independent decisions based on its own goals and context.

2. Specialization

Different Agents can take on tasks in different domains, such as research, programming, testing, and review.

3. Collaboration

Agents collaborate through messages, shared state, or task handoff.

4. Parallelism

Mutually independent subtasks can be executed simultaneously, improving overall efficiency.

5. Distributed Decision-Making

The system can have multiple Agents make local decisions separately and then form an overall plan through coordination mechanisms.

6. Scalability

New Agents, tools, and specialized capabilities can be added according to business needs.


II. Overall Architecture of a Multi-Agent System

A multi-agent system is not simply creating multiple LLM instances; it requires establishing a complete collaboration infrastructure.

2.1 Core Architecture

A typical Multi-Agent system can be divided into six layers:

Layer Core Module Main Responsibilities
Task Entry Layer Task Interface Receive user tasks and constraints
Coordination Control Layer Coordinator, Orchestrator Task decomposition, allocation, scheduling, and termination
Agent Execution Layer Specialized Agents Independently complete specialized tasks
Communication and Collaboration Layer Message Bus, Protocol Message passing among Agents
Shared State Layer Shared State, Memory Manage task state and shared information
Infrastructure Layer LLM, Tools, Storage Provide models, tools, and persistence capabilities

Overall architecture:

flowchart TB
    A["User Task"] --> B["Task Entry Layer"]
    B --> C["Coordination Control Layer"]
    C --> D["Agent Execution Layer"]
    D --> E["Communication and Collaboration Layer"]
    E --> D
    D --> F["Shared State and Memory Layer"]
    F --> D
    D --> G["Infrastructure Layer"]
    G --> D
    C --> H["Result Aggregation and Quality Control"]
    H --> I["Final Result"]

    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:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F

2.2 Coordinator: Coordinator

Coordinator is the core control role in a multi-agent system and is responsible for managing task collaboration among Agents.

Main responsibilities:

  • Receive and understand user tasks.
  • Split complex tasks into multiple subtasks.
  • Select suitable Agents.
  • Assign execution order and dependencies.
  • Manage Agent execution status.
  • Collect and consolidate execution results.
  • Handle failures, timeouts, and retries.
  • Determine whether the task is complete.

Coordinator can be driven by an LLM or controlled by a traditional program.

Two implementation approaches:

LLM-driven coordinator

Use models to understand tasks, select Agents, and dynamically adjust execution plans.

Its advantage is flexibility, making it suitable for complex and uncertain tasks.

Its disadvantage is that decision results have a certain degree of randomness, and execution costs are relatively high.

Rule-driven coordinator

Control Agents through predefined processes, state machines, and conditional judgments.

Its advantages are predictability, ease of debugging, and low execution cost.

Its disadvantage is limited flexibility, and task processes need to be designed in advance.

Production environments usually adopt a hybrid architecture:

  • The LLM is responsible for complex task understanding and dynamic decision-making.
  • The program is responsible for state management, permission control, and process execution.
  • Rules are responsible for key condition judgments and security constraints.

2.3 Specialized Agent: Specialized Agent

Each Agent should have clear responsibility boundaries.

An Agent usually consists of the following components:

Component Function
Role Define the Agent's identity and responsibilities
Goal Define the goal to be completed
System Prompt Constrain behavior and output requirements
LLM Provide reasoning and generation capabilities
Tools Provide external operation capabilities
Memory Store current or historical context
State Maintain current task state
Output Schema Standardize output format

For example, a Research Agent:

Role:
    You are a technical research Agent.

Goal:
    Collect reliable materials in the specified technical field.

Responsibilities:
    1. Search relevant technical documents.
    2. Compare different technical solutions.
    3. Verify important facts.
    4. Organize key conclusions.
    5. Provide sources and evidence.

Constraints:
    1. Do not fabricate sources.
    2. Uncertain information must be clearly marked.
    3. Do not take responsibility for the overall decision-making of the final report.
    4. Output must conform to the agreed data structure.

The clearer an agent's responsibilities are, the easier it is to control task boundaries during collaboration.


3. Role Design and Organizational Patterns for Multi-Agent Systems

The design of a multi-agent system first requires clarity on how agents are organized, who is responsible for coordination, and how tasks are allocated.

3.1 Manager-Worker Pattern

Manager-Worker is the most common way to organize multiple agents.

A Manager is responsible for task planning and allocation, while multiple Workers execute subtasks separately.

For example, a technical research task:

  • Manager: breaks down the research topic.
  • Researcher A: studies the technical principles.
  • Researcher B: studies the architecture design.
  • Researcher C: studies engineering practices.
  • Reviewer: reviews the research results.

Execution flow:

flowchart TD
    A["User research task"] --> B["Manager Agent"]
    B --> C["Task breakdown"]
    C --> D["Researcher A"]
    C --> E["Researcher B"]
    C --> F["Researcher C"]
    D --> G["Result aggregation"]
    E --> G
    F --> G
    G --> H["Reviewer Agent"]
    H --> I["Final research report"]

    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:#EAE8FA,stroke:#A49BD5,color:#51477D
    style F fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Advantages:

  • Clear organizational structure.
  • Centralized task allocation.
  • Easy to monitor overall progress.
  • Suitable for breaking down complex tasks and parallel processing.

Disadvantages:

  • The Manager can easily become a performance bottleneck.
  • A poor decision by the Manager can affect all Workers.
  • Workers usually lack the ability to collaborate directly with one another.

Use cases: research analysis, content generation, software development, and data processing.

3.2 Hierarchical: Hierarchical Collaboration

A hierarchical structure usually has multiple levels of management.

For example:

  • The Master Coordinator Agent is responsible for the overall goal.
  • The Technical Lead Agent is responsible for technical tasks.
  • The Product Lead Agent is responsible for requirements tasks.
  • Specific Execution Agents are responsible for the actual work.
flowchart TD
    A["Master Coordinator"] --> B["Technical Lead Agent"]
    A --> C["Product Lead Agent"]
    A --> D["Quality Lead Agent"]
    B --> E["Development Agent"]
    B --> F["Architecture Agent"]
    C --> G["Requirements Analysis Agent"]
    C --> H["Documentation Agent"]
    D --> I["Testing Agent"]
    D --> J["Review Agent"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style F fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style G fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style H fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style J fill:#EAE8FA,stroke:#A49BD5,color:#51477D

Advantages:

  • Suitable for large, complex tasks.
  • Can manage responsibilities by layer.
  • Supports independent planning across different domains.
  • Reduces the management burden on a single coordinator.

Disadvantages:

  • There are more layers, so communication costs are higher.
  • Information loss can occur between upper and lower layers.
  • Fault localization and state management are more complex.

3.3 Peer-to-Peer: Peer Collaboration

In the Peer-to-Peer pattern, there is no fixed central manager among agents; they can exchange information and negotiate directly.

For example, multiple research Agents each analyze a technical proposal:

  • Agent A is responsible for performance.
  • Agent B is responsible for security.
  • Agent C is responsible for cost.
  • Agent D is responsible for compatibility.

They can discuss with each other, exchange evidence, and form a joint conclusion.

flowchart TD
    A["Agent A Performance Analysis"] <--> B["Agent B Security Analysis"]
    B <--> C["Agent C Cost Analysis"]
    C <--> D["Agent D Compatibility Analysis"]
    D <--> A
    A <--> C
    B <--> D
    A --> E["Joint Decision"]
    B --> E
    C --> E
    D --> E

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

Advantages:

  • There is no single coordinator bottleneck.
  • Agents can directly exchange specialized information.
  • Suitable for problems that require multi-party negotiation.

Disadvantages:

  • The number of messages may grow rapidly.
  • It is prone to opinion conflicts.
  • Consensus and termination mechanisms need to be designed.
  • It is difficult to uniformly control execution state.

If there are N Agents using fully connected communication, the potential number of bidirectional connections is:

E = \frac{N(N-1)}{2}

Therefore, as the number of Agents increases, communication and coordination costs may rise rapidly.

3.4 Pipeline: Pipeline Collaboration

The Pipeline pattern splits a complex task into a series of processing stages with sequential dependencies.

Each Agent is responsible for one of the stages, and the output of the previous Agent becomes the input of the next Agent.

For example, content production:

  1. The Research Agent collects materials.
  2. The Analyst Agent analyzes the materials.
  3. The Writer Agent writes the article.
  4. The Reviewer Agent reviews the content.
  5. The Editor Agent completes revisions.
flowchart LR
    A["Research Agent"] --> B["Analyst Agent"]
    B --> C["Writer Agent"]
    C --> D["Reviewer Agent"]
    D --> E["Editor Agent"]
    E --> F["Final Article"]

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

Advantages:

  • Task stages are clear.
  • It is easy to track execution status.
  • Each stage can be tested independently.
  • Suitable for standardized processing workflows.

Disadvantages:

  • There are dependencies between upstream and downstream stages.
  • Errors upstream may propagate downstream.
  • A blockage in one stage can affect the entire pipeline.

3.5 Debate: Debate Collaboration

The Debate pattern has multiple Agents analyze the same problem from different positions, then form a conclusion through cross-review and arbitration.

For example, technology selection:

  • Agent A supports microservices architecture.
  • Agent B supports a modular monolith architecture.
  • Agent C is responsible for reviewing the evidence from both sides.
  • The Judge Agent is responsible for the final decision.
flowchart TD
    A["Input technical decision problem"] --> B["Pro Agent"]
    A --> C["Con Agent"]
    B --> D["Cross-examination"]
    C --> D
    D --> E["Reviewer Agent"]
    E --> F["Judge Agent"]
    F --> G["Final decision"]

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

Advantages:

  • It can uncover issues that are easily missed from a single perspective.
  • It supports comparison of multiple solutions.
  • It is suitable for complex decision-making and risk assessment.

Disadvantages:

  • Multi-round discussions are costly.
  • Agents may merely restate different viewpoints.
  • The majority opinion does not necessarily represent the correct conclusion.
  • The Judge may still make biased judgments.

Therefore, the debate mechanism should require each Agent to provide evidence, constraints, and verifiable arguments, rather than merely comparing their expressiveness.

3.6 Hybrid Collaboration Mode

Real production systems usually do not adopt just one fixed topology.

For example, a software development system can use:

  • A top-level Manager-Worker structure handles overall task allocation.
  • A Pipeline is used within the development team.
  • Debate is used for technical solutions.
  • Testing and development use parallel collaboration.
  • A Reviewer independently reviews the final result.

A hybrid mode can choose an appropriate collaboration structure based on task characteristics, but it also requires more complex coordination and state management.


4. Task Decomposition and Scheduling in Multi-Agent Systems

Task decomposition is one of the most important foundational capabilities of multi-agent systems.

If tasks are not split reasonably, even if each Agent has strong capabilities, the overall result may still be poor.

4.1 Task Decomposition

The Coordinator must first understand the user's goal and then convert it into multiple executable subtasks.

A qualified subtask should satisfy the following as much as possible:

  • A clear objective.
  • Complete input information.
  • Verifiable output results.
  • Clear execution responsibilities.
  • Explicit dependencies.
  • A reasonable workload.

For example, the user requests:

Design an online shopping mall system, including:
1. User management.
2. Product management.
3. Order management.
4. Payment system.
5. Database design.
6. System testing.

It can be split into:

Subtask Responsible Agent Dependencies
User management design User Agent Basic requirements
Product management design Product Agent Basic requirements
Order management design Order Agent User and product design
Payment system design Payment Agent Order design
Database design Database Agent Domain model
System testing Tester Agent Interfaces of each module

Task splitting cannot be based only on evenly distributing by quantity; dependencies and workload must also be considered.

4.2 DAG Task Dependencies

Complex tasks usually have dependencies, which can be represented using a directed acyclic graph (DAG).

For example:

flowchart TD
    A["Requirements Analysis"] --> B["User Module Design"]
    A --> C["Product Module Design"]
    B --> D["Order Module Design"]
    C --> D
    D --> E["Payment Module Design"]
    B --> F["Database Design"]
    C --> F
    D --> F
    E --> G["System Integration"]
    F --> G
    G --> H["System Testing"]
    H --> I["Final Delivery"]

    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:#EAE8FA,stroke:#A49BD5,color:#51477D
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F

In a DAG:

  • Nodes represent tasks.
  • Directed edges represent task dependencies.
  • Tasks without dependencies can be executed in parallel.
  • Subsequent tasks can start only after all preceding tasks are completed.

A DAG can be topologically sorted to obtain a valid execution order.

4.3 Parallel Task Scheduling

If multiple tasks are independent of one another, they can be assigned to different agents at the same time.

For example:

flowchart TD
    A["Task Planning"] --> B["Task A"]
    A --> C["Task B"]
    A --> D["Task C"]
    B --> E["Wait for Result Aggregation"]
    C --> E
    D --> E
    E --> F["Execute Next Stage"]

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

Parallel execution can shorten total elapsed time, but it does not mean that more agents are always better.

Consider:

  • Number of parallelizable tasks.
  • Agent startup and scheduling costs.
  • LLM API concurrency limits.
  • Tool and database connection limits.
  • Result aggregation costs.
  • Competition for shared resources.

4.4 Task Scheduling Strategies

Common scheduling methods:

Scheduling Strategy Principle Applicable Scenarios
Round Robin Assign tasks in a round-robin manner Agents have similar capabilities
Least Loaded Assign to the agent with the lowest load Uneven workloads
Capability Based Match agents based on capability Clear specialized roles
Priority Based Prioritize high-priority tasks Tasks have priorities
Dependency Based Schedule based on dependencies DAG workflows
Dynamic Scheduling Dynamically adjust based on execution feedback Tasks with high uncertainty

Production systems usually need to schedule tasks by considering task capabilities, priorities, load, resource budgets, and dependencies together.


5. Multi-Agent Communication Mechanisms

Multiple agents need to exchange tasks, information, and execution results through communication.

Communication mechanisms determine the collaboration efficiency, scalability, and reliability of multi-agent systems.

5.1 Basic Types of Communication

1. Direct Message

One agent sends a message to a specified agent.

Suitable for clear task handovers and targeted collaboration.

2. Broadcast

One agent sends a message to multiple agents.

Suitable for publishing public task information, status changes, and shared constraints.

3. Publish-Subscribe

Agents publish events, and agents subscribed to the relevant events receive the messages.

Suitable for asynchronous decoupling and event-driven architectures.

4. Shared State

Multiple Agents exchange task information through a unified state store.

Suitable for systems that need to share task progress, results, and collaboration context.

5.2 Message Passing Architecture

flowchart TD
    A["Agent A"] --> B["Message Bus"]
    C["Agent B"] --> B
    D["Agent C"] --> B
    B --> E["Agent Router"]
    E --> F["Agent D"]
    E --> G["Agent E"]
    E --> H["Agent F"]
    F --> I["Shared State Store"]
    G --> I
    H --> I

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

5.3 Agent Message Structure

A production environment should not pass along just a plain piece of text; it should use structured messages.

For example:

{
  "message_id": "msg_001",
  "task_id": "task_001",
  "sender": "planner_agent",
  "receiver": "developer_agent",
  "message_type": "task_assignment",
  "correlation_id": "corr_001",
  "payload": {
    "task": "Implement the user query API",
    "requirements": [
      "Support lookup by user ID",
      "Handle the case where the user does not exist",
      "Return a unified JSON format"
    ]
  },
  "priority": "high",
  "created_at": "2026-11-20T10:00:00Z",
  "deadline": "2026-11-20T10:10:00Z"
}

Important fields:

Field Purpose
message_id Unique message identifier
task_id The task it belongs to
sender Message sender
receiver Message receiver
message_type Message type
correlation_id Links requests and responses
payload The actual message content
priority Message priority
created_at Creation time
deadline Task deadline

You can also add:

  • trace_id: cross-Agent link tracing.
  • schema_version: message structure version.
  • reply_to: the related message being replied to.
  • idempotency_key: idempotent processing identifier.
  • metadata: model, tool, and execution environment information.

5.4 Communication Protocols and Message Semantics

Multi-Agent communication needs to solve not only how messages are sent, but also what operation each message represents.

Common message types:

Type Meaning
task_assignment Assign a task
task_acceptance Accept a task
task_rejection Reject a task
task_progress Report progress
task_result Return execution result
clarification Request additional information
error Report an execution error
cancellation Request task cancellation
handoff Hand off control
approval_request Request approval

We also need to define message states:

  • Created.
  • Sent.
  • Received.
  • Acknowledged.
  • Processed.
  • Failed.
  • Expired.

A message being sent successfully does not mean the receiver has finished processing it.

Therefore, message delivery state and task execution state must be distinguished.


VI. Shared State and Memory Management in Multi-Agent Systems

Multiple Agents usually need to share part of their information, but that does not mean all Agents should access exactly the same context.

A reasonable design for state and memory is the key to avoiding information chaos and context contamination.

6.1 Shared State and Private State

A multi-agent system usually has two kinds of state at the same time.

Private State

Maintained independently by a single Agent.

For example:

  • The reasoning context of the current Agent.
  • The execution plan of the current Agent.
  • The temporary observations of the Agent.
  • The tool invocation state of the current Agent.

Shared State

Can be read or, subject to permissions, modified by multiple Agents.

For example:

  • The overall task objective.
  • The assignment of subtasks.
  • Common requirements and constraints.
  • Results of completed tasks.
  • The shared domain model.
  • Global execution progress.
Data Type Recommended Storage Access Scope
Agent private context Agent Context Single Agent
Current task state Task State Store Relevant Agents
Public execution results Shared State Authorized Agents
Historical experience Long-term Memory Retrieved on demand
Message records Message Store Communication system
Execution traces Trace Store Monitoring and auditing

6.2 Update Conflicts in Shared State

Suppose two Agents modify the order state at the same time:

  • Agent A marks the order as paid.
  • Agent B marks the order as cancelled.

Without concurrency control, state overwrites and business inconsistencies may occur.

Common solutions:

1. Single-writer principle

A shared state may only be written by a designated Agent or service.

2. Optimistic locking

Detect concurrent modifications through version numbers.

3. Transaction control

Place related updates in a transaction to guarantee atomicity.

4. Event sourcing

Store state-change events and reconstruct the current state from them.

5. State machine constraints

Allow only legal state transitions.

For example, order states:

stateDiagram-v2
    [*] --> Pending
    Pending --> Paid
    Pending --> Cancelled
    Paid --> Shipped
    Shipped --> Completed
    Paid --> Refunding
    Refunding --> Refunded
    Cancelled --> [*]
    Completed --> [*]
    Refunded --> [*]

This diagram shows the legal transitions between order states. For state updates involving funds and inventory, database transactions, idempotency keys, and business compensation mechanisms are also required.

6.3 Multi-Agent Memory

A multi-agent system can adopt a hierarchical memory structure:

Memory Layer Content Primary Use
Agent Short-term Memory Temporary context of the current Agent Single-Agent execution
Task Memory Shared information for the current task Multi-Agent collaboration
Episodic Memory Historical task execution experiences Reuse historical experience
Semantic Memory Stable knowledge and facts Professional knowledge retrieval
Procedural Memory Processes and execution experience Reuse task methods

Memory management needs to clarify:

  • Who can read.
  • Who can write.
  • Which information is allowed to be shared.
  • Whether the information has been verified.
  • The validity period of the information.
  • How conflicts are resolved.
  • How sensitive data is isolated.

In particular, avoid directly treating an Agent's unverified conclusion as a global fact and propagating it to other Agents.


7. Multi-Agent Collaboration Control and Task Handoff

Collaboration between Agents cannot rely solely on natural language dialogue; it also requires clear control ownership and task status.

7.1 Handoff: Task Handoff

Handoff means that one Agent hands over the current task or control to another Agent.

For example:

  • Planner hands the code implementation task to Developer.
  • Developer hands the code review task to Reviewer.
  • After finding issues, Reviewer hands the modification task back to Developer.

A complete Handoff should include:

  1. Current task objective.
  2. Completed work.
  3. Current execution status.
  4. Relevant context.
  5. Remaining tasks.
  6. Reason for handoff.
  7. Expected actions of the receiver.

Handoff process:

flowchart TD
    A["Agent A executes task"] --> B["Determine whether handoff is needed"]
    B --> C{"Is another Agent needed?"}
    C -->|"No"| D["Continue current task"]
    C -->|"Yes"| E["Build handoff context"]
    E --> F["Send Handoff message"]
    F --> G["Agent B receives task"]
    G --> H["Confirm task and context"]
    H --> I{"Accept task?"}
    I -->|"Yes"| J["Agent B starts execution"]
    I -->|"No"| K["Return rejection reason"]
    K --> L["Coordinator reassigns"]

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

7.2 Agent Collaboration State Machine

A task in a multi-agent system may go through multiple states.

State Meaning
CREATED Task created
ASSIGNED Agent assigned
ACCEPTED Agent accepted
RUNNING Executing
WAITING Waiting for dependencies or external events
REVIEWING Under review
COMPLETED Execution completed
FAILED Execution failed
CANCELLED Cancelled
EXPIRED Expired

Task status should be maintained centrally by the coordinator or task management service to prevent multiple Agents from arbitrarily modifying the lifecycle of the same task.

7.3 Timeouts, Cancellation, and Retry

In production environments, an Agent may experience:

  • Model call timeout.
  • Tool call failure.
  • Agent unresponsive.
  • Incorrect output format.
  • Execution time exceeding the deadline.
  • Task dependencies remaining incomplete for an extended period.

A unified execution control mechanism needs to be designed:

flowchart TD
    A["Task assignment"] --> B["Agent starts execution"]
    B --> C["Monitor execution status"]
    C --> D{"Completed on time?"}
    D -->|"Yes"| E["Receive task result"]
    D -->|"No"| F["Trigger timeout handling"]
    F --> G{"Retry allowed?"}
    G -->|"Yes"| H["Check idempotency and retry budget"]
    H --> I{"Execution allowed again?"}
    I -->|"Yes"| J["Re-execute or reassign"]
    I -->|"No"| K["Task failed"]
    G -->|"No"| K
    E --> L["Result validation"]
    J --> C

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

Pay special attention: a task timeout does not mean the original Agent has stopped executing.

If the task is directly assigned to another Agent, two Agents may execute the same task at the same time.

For operations with side effects, idempotency keys, execution leases, or resource locks must be used to prevent duplicate execution.


VIII. Multi-Agent Result Integration and Quality Control

After multiple Agents complete their subtasks separately, their results still need to be integrated into a consistent final output.

This step is often underestimated.

Different Agents may:

  • Use different data sources.
  • Reach contradictory conclusions.
  • Use different terminology and data formats.
  • Make different assumptions about the same issue.
  • Ignore constraints from other Agents.

Therefore, result integration cannot simply concatenate the outputs of multiple Agents.

8.1 Result Integration Mechanism

Typical process:

flowchart TD
    A["Collect results from each Agent"] --> B["Structured result parsing"]
    B --> C["Check task completeness"]
    C --> D["Check facts and evidence"]
    D --> E["Identify result conflicts"]
    E --> F{"Are there conflicts?"}
    F -->|"No"| G["Unify result format"]
    F -->|"Yes"| H["Conflict analysis and coordination"]
    H --> I["Additional verification or task reassignment"]
    I --> D
    G --> J["Final review by the Reviewer"]
    J --> K{"Acceptance passed?"}
    K -->|"Yes"| L["Generate final result"]
    K -->|"No"| M["Return for task correction"]

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

8.2 Handling Result Conflicts

When results from multiple Agents conflict, the following strategies can be used:

Strategy Principle Applicable Scenario
Evidence Based Decide based on evidence quality Research and fact verification
Rule Based Adjudicate according to predefined rules Clear business constraints
Expert Review Review by a specialized Agent Professional technical issues
Majority Voting Decide based on majority opinion Multiple independent judgments
Re-execution Re-execute for verification Results are in doubt
Human Review Final human adjudication High-risk decisions

Majority voting is not always reliable.

If multiple Agents use the same model, the same materials, and similar prompts, they may produce highly correlated errors.

Therefore, result integration should prioritize evidence, independence, and verifiability rather than simply counting the number of supporters.

8.3 Multi-Agent Quality Evaluation

The system can be evaluated from the following dimensions:

  • Subtask completion rate.
  • Task dependency fulfillment rate.
  • Result consistency.
  • Factual accuracy.
  • Evidence completeness.
  • Final task success rate.
  • Failure recovery capability.

For critical outputs, each Agent can be required to provide structured results:

{
  "agent_id": "research_agent_01",
  "task_id": "research_001",
  "status": "completed",
  "summary": "研究结论摘要",
  "findings": [
    {
      "claim": "技术方案支持水平扩展",
      "evidence": "官方技术文档中的相关说明",
      "confidence": 0.92
    }
  ],
  "limitations": [
    "缺少特定版本的性能测试数据"
  ],
  "recommended_next_steps": [
    "补充实际负载测试"
  ]
}

9. Engineering Implementation of Multi-Agent Systems

Below, we build a simplified Multi-Agent system in Python to understand the core logic of task assignment, Agent execution, and result aggregation.

9.1 Defining an Agent

from dataclasses import dataclass, field
from typing import Callable, Any


@dataclass
class Agent:
    name: str
    role: str
    handler: Callable[[dict], Any]

    def run(self, task: dict):
        return self.handler(task)

Each Agent contains:

  • name: Agent name.
  • role: Agent responsibility.
  • handler: Concrete execution logic.

9.2 Define Tasks

@dataclass
class Task:
    task_id: str
    description: str
    assigned_agent: str
    dependencies: list[str] = field(
        default_factory=list
    )
    status: str = "pending"
    result: Any = None

A task contains a unique identifier, task description, assignee, dependencies, execution status, and result.

9.3 Create Specialized Agents

def research_handler(task):
    return {
        "topic": task["description"],
        "result": "完成技术资料收集",
        "status": "success"
    }


def analysis_handler(task):
    return {
        "topic": task["description"],
        "result": "完成技术分析",
        "status": "success"
    }


def review_handler(task):
    return {
        "result": "审查通过",
        "status": "success"
    }


research_agent = Agent(
    name="research_agent",
    role="技术研究",
    handler=research_handler
)

analysis_agent = Agent(
    name="analysis_agent",
    role="技术分析",
    handler=analysis_handler
)

review_agent = Agent(
    name="review_agent",
    role="质量审查",
    handler=review_handler
)