Master-Slave Architecture in Multi-Agent Systems

In the past year, Multi-Agent systems have been gaining significant traction, with continuous funding and increasing popularity.

From AutoGPT to MetaGPT, from CrewAI to LangGraph, various multi-agent frameworks are emerging. The domestic phenomenon Manus, along with the recently open-sourced OpenManus by the MetaGPT team, are notable examples. OpenAI’s Swarm, Microsoft’s AutoGen, and Anthropic’s Claude Code show that every major company is exploring its own Multi-Agent solutions. The number of stars on related projects on GitHub often exceeds ten thousand, and community discussions are continuously rising.

This trend reveals an important shift in AI applications: moving from single model invocation to multi-agent collaboration. Just as software development has evolved from monolithic applications to microservices architecture, AI systems are also exploring how to collaborate through multiple specialized agents to accomplish more complex tasks.

When we closely observe the architectures of these Multi-Agent systems, we notice a pattern:

MetaGPT includes a product manager role responsible for coordinating other engineering roles; AutoGen supports a Manager-Worker model; Claude Code explicitly adopts a master loop engine with sub-task agents design. In OpenAI Swarm, we can also see the shadow of an Orchestrator Agent.

These systems all employ some form of a “master-slave” architecture—where one agent is responsible for global coordination, while other agents provide specialized support.

Why is this the case? Is it just a coincidence?

Today, we will discuss the master-slave architecture of Multi-Agent systems, starting from the underlying principles of large models.

1 Starting from the Principles of Large Models

1.1 The “Attention” Mechanism of Large Models

To understand why a master-slave architecture is necessary, we first need to grasp how large models “think”.

The core of large models is the Transformer architecture, and the essence of the Transformer is the attention mechanism. Simply put, when generating each token, the model “attends” to all relevant information in the input (within the context window) and then makes decisions based on this information.

Here is a key point:Every decision made by a large model is based on all the context it can “see”.

This is akin to solving a math problem. If the problem states, “Xiao Ming has 5 apples and gives 2 to Xiao Hong,” to answer “How many does Xiao Ming have left?” you must see both “5 apples” and “gave away 2”. If you only see part of the information, you cannot arrive at the correct answer.

Large models operate similarly. Their intelligence stems from a complete understanding of context (which also derives from knowledge learned during pre-training, pattern recognition, knowledge transfer, etc.). Once context is missing or contradictory, the quality of the model’s output can plummet.

1.2 Challenges of Collaboration Among Multiple Models

When multiple large models (agents) need to collaborate, how can we ensure they all have the necessary context?

Suppose we have three agents working in parallel on development and deployment tasks:

  • Agent A: responsible for front-end development
  • Agent B: responsible for back-end development
  • Agent C: responsible for deployment and operations

Ideally, they should function like an experienced full-stack engineer, always aware of the design decisions made in other areas. However, in reality, each agent is an independent instance of a large model, each maintaining its own context.

This creates the first problem: context fragmentation.

Agent A decides to use React, while Agent B opts for Python Flask, which is fine. But when Agent A later generates code assuming the back-end returns GraphQL, while Agent B actually provides a REST API, the final code will not work correctly.

Moreover, large models have a characteristic called “autoregressive generation”—each new output depends on all previous outputs. This means that once an agent makes an erroneous assumption, that error will be amplified in subsequent generations.

2 The Design Philosophy of Master-Slave Architecture

2.1 Why Master-Slave Architecture is Effective

The core idea of master-slave architecture is simple:one commander, multiple executors. One master agent controls the overall situation, while other slave agents provide specialized support in subfields.

This design directly addresses the issue of context fragmentation. The master agent always maintains a complete task context, knowing:

  • What the overall goal is
  • What decisions have already been made
  • How various parts cooperate
  • What the current priorities are

The slave agents act as the “external brain” of the master agent—when the master agent requires specialized knowledge, it will call upon the corresponding slave agent, but the final decision and execution are always carried out by the master agent.

In our specific implementation, each different slave agent has its own role and system prompt.

2.2 Practical Validation of Claude Code

The design of Claude Code embodies the master-slave concept. According to reverse engineering analysis on GitHub, its architecture includes:

nO Master Loop Engine (master agent) responsible for:

  • Maintaining complete code context
  • Coordinating all sub-tasks
  • Making final decisions
  • Generating actual code

I2A Sub-task Agents (slave agents) responsible for:

  • Answering specific questions
  • Providing expert advice
  • Exploring possible solutions

Claude Code deliberately avoids parallel modifications by sub-agents. When multiple directions need to be explored, the master agent will consult different sub-agents in a limited scope, ensuring that each decision is based on the latest complete context.

This design may seem “inefficient,” but it actually avoids a lot of errors and rework, resulting in higher overall efficiency.

2.3 Biological Inspiration

Moreover, the master-slave architecture has many examples in the biological world.

The human brain is a typical example. The prefrontal cortex acts as the “master agent,” responsible for high-level decision-making and planning. Various specialized brain areas (visual cortex, auditory cortex, motor cortex, etc.) function like “slave agents,” processing specific types of information.

All sensory inputs ultimately converge in the prefrontal cortex, which integrates the information and makes decisions. Even reflex actions are later “known” by the brain, which may adjust subsequent behavior.

This centralized architecture has been validated through billions of years of evolution.

3 Technical Implementation of Master-Slave Architecture

3.1 Context Management

To implement a master-slave architecture, the core aspect is context management. The master agent needs to:

1. Maintain a complete yet concise context

Not all information is equally important. The master agent needs to intelligently compress and summarize historical information. Claude Code employs a strategy:

When token usage reaches a threshold of 92%, a compression mechanism is triggered. Key decisions are retained, while intermediate exploration processes from slave agents are compressed or discarded. This maintains decision coherence while avoiding context explosion.

2. Build structured decision records

Do not simply concatenate all dialogue history. It is necessary to record in a structured manner:

  • Task goals and constraints
  • Key decisions made
  • Dependencies between decisions
  • Queue of unresolved issues

3. Dynamically adjust the context window

Adjust the amount of context passed to slave agents dynamically based on task complexity and current phase. The initial exploration phase can be more open, while the later execution phase requires more precision.

3.2 Design Principles for Agents

Agents should not be overly intelligent; rather, they should be focused and controllable:

1. Clear boundaries of capability

Each slave agent should have a clearly defined scope of capabilities. For example:

  • Code Review Agent: only responsible for identifying potential issues
  • Refactoring Agent: only responsible for improving code structure
  • Testing Agent: only responsible for generating test cases

2. Standardized input and output

The interfaces of slave agents should be standardized so that the master agent can call them in a uniform manner. The output format should also be standardized for easy parsing and integration by the master agent.

3. Stateless design

Slave agents should ideally be stateless, with each call being independent. This avoids the complexity of state management and facilitates parallelization (when tasks are indeed independent).

3.3 Key Points of Coordination Mechanism

The coordination ability of the master agent determines the performance of the entire system:

1. Task decomposition strategy

Not all tasks need to be decomposed. The master agent needs to learn to judge:

  • Simple tasks should be handled directly
  • Complex tasks should be decomposed while maintaining context
  • Exploratory tasks can be parallelized, but results need to be integrated serially

2. Conflict detection and resolution

Even under a master-slave architecture, suggestions from slave agents may contradict each other. The master agent needs to:

  • Detect potential conflicts
  • Evaluate the pros and cons of different solutions
  • Make final decisions and maintain consistency

3. Graceful degradation

When a slave agent fails or is unavailable, the master agent should be able to:

  • Attempt to obtain help from other slave agents
  • Degrade to handle it independently
  • Adjust task strategies

4 Advantages and Limitations of Master-Slave Architecture

4.1 Core Advantages of Master-Slave Architecture

1. Guarantee of global consistencyThe master agent, as the sole decision-making center, naturally ensures the consistency of architectural decisions. This is not just about the choice of technology stack (e.g., uniformly using REST or GraphQL), but more importantly, details such as interface agreements, error handling strategies, and naming conventions can all remain consistent. This consistency is immensely valuable in complex projects.

2. Clear decision-making chainEach decision has a clear source and basis. You can trace how each architectural decision was made and why a particular solution was chosen in the dialogue history of the master agent. This traceability is very valuable for debugging issues or explaining system design to others.

3. Elegant error handlingThe master agent understands the global state, so when a sub-task fails, it can accurately assess the impact range and formulate recovery strategies. For example, if there is an error in database design, the master agent knows which API designs need to be adjusted accordingly. In decentralized systems, tracking and fixing such cascading impacts can be very challenging.

4. Maximization of context utilizationWhat appears to be a serial decision-making process actually optimizes overall efficiency:

  • Avoids redundant work (multiple agents will not each generate similar code)
  • Reduces coordination overhead (no need for extensive communication between agents)
  • Maximizes context reuse (the decision history of the master agent can be directly passed to slave agents)

In the practice of Claude Code, this design allows the system to complete quite complex programming tasks within a limited token budget.

4.2 Limitations of Master-Slave Architecture

1. Master Agent becomes a performance bottleneckAll decisions must go through the master agent, which can limit overall efficiency when multiple complex sub-tasks need to be processed in parallel. This is akin to a project manager trying to manage too many teams at once, where coordination costs can skyrocket.

2. High dependency on the capabilities of the master agentThe intelligence ceiling of the system depends on the capabilities of the master agent. If the master agent does not have a deep understanding of a certain domain, even with specialized slave agents, the overall performance will be limited. This is similar to a manager who lacks technical knowledge, making it difficult to fully leverage the potential of the technical team.

3. Lack of true collaborative intelligenceThe master-slave architecture is essentially a “decompose-execute-combine” model, lacking equal negotiation and creative interaction between agents. In tasks that require brainstorming or multi-perspective exploration, this hierarchical structure may limit the diversity of solutions.

4. Difficulty in determining the granularity of task decompositionThe master agent needs to accurately judge the granularity of task decomposition. If it is too fine, coordination costs will be high; if too coarse, slave agents may not be able to handle it. Moreover, as task complexity increases, finding the right decomposition method becomes increasingly difficult.

4.3 Analysis of Applicable Scenarios

The master-slave architecture is particularly suitable for:

1. Engineering tasks

  • Code generation
  • System design
  • Documentation writing

These tasks require high consistency and structure.

2. Tasks with clear objectives

  • Problem diagnosis
  • Data analysis
  • Process automation

When objectives are clear, centralized coordination is more efficient.

3. Scenarios requiring controllability

  • Financial transactions
  • Medical diagnosis
  • Legal consultation

These fields cannot tolerate unpredictable behavior.

Not well-suited for:

1. Creative generation

  • Brainstorming
  • Artistic creation
  • Exploratory research

2. Large-scale parallel processing

  • Log analysis
  • Image batch processing
  • Distributed crawling

3. Peer collaboration

  • Multiplayer game AI
  • Group simulation
  • Decentralized systems

5 Conclusion

With the enhancement of large model capabilities, the master-slave architecture is also evolving:

  • Longer context windows: GPT-4 now supports a context of 128K, and Claude 3 even reaches 200K. This means the master agent can maintain a more complete history, reducing information loss.
  • Better instruction following: The new generation of models has shown significant improvements in instruction following, allowing slave agents to understand and execute the master agent’s instructions more accurately.
  • Native tool invocation: Models are beginning to natively support function calls, making the interfaces between master and slave agents more standardized and reliable.

If you are looking to implement a master-slave architecture for a Multi-Agent system, here are some suggestions:

1. Design clear agent roles: Do not let the responsibilities of slave agents be too broad. Each slave agent should function like a Unix tool—doing one thing and doing it well.

2. Implement robust error handling

Failures of slave agents are the norm, not the exception. The master agent needs to:

  • Implement timeout mechanisms
  • Establish retry strategies
  • Develop fallback plans
  • Ensure error isolation

3. Optimize context transfer: Control the boundaries of context; not all context needs to be passed to agents. Carefully design the content and format of context based on task types.

4. Monitoring and observability: Record all decision points and agent interactions for future debugging and optimization.

The master-slave architecture of Multi-Agent systems fundamentally addresses an age-old question:How to efficiently organize multiple agents to complete complex tasks.

From biological evolution to human society, from computer architecture to distributed systems, we repeatedly discover that in scenarios requiring consistency and controllability, some form of centralized coordination is necessary.

The emergence of large models has not changed this rule. On the contrary, due to the strong dependence of large models on context, the master-slave architecture has become even more important.

As the capabilities of large models improve and agent technologies mature, we will see more innovative architectures emerge. However, regardless of how they evolve, those fundamental principles—context consistency, decision controllability, and error recoverability—are considerations we must carefully address in practice.

That’s all.

Leave a Comment