# Multi-Agent System

> The Multi-Agent System is an architecture where several AI agents with different roles work together on a task.

## What is a multi-agent system in AI?

The architecture where several agents with different roles work on one task. Usually an orchestrator agent splits the task, assigns parts to worker agents, checks their results and combines them. Helps with large tasks but increases cost and makes debugging harder.

- Topic: AI Agents
- Type: architecture

## Example

Wrong:

```js
const results = await Promise.all(workers.map((w) => w.run(task)));
return combine(results);
```

Right:

```js
const withTimeout = (p) => Promise.race([p, timeout(60_000)]);
const settled = await Promise.allSettled(workers.map((w) => withTimeout(w.run(task))));
const valid = settled
  .filter((r) => r.status === 'fulfilled' && isValidResult(r.value))
  .map((r) => r.value);
return combine(valid);
```

Timeouts and validation keep one slow or broken worker from blocking or poisoning the combined result.

## Common mistakes

- Agents pass errors to each other and amplify them.
- The orchestrator trusts worker results without checking them.

## Key points

- Each agent has a clear role, its own tools and a defined output format.
- There is a limit on how many agents run and how many rounds they take.
- Worker results are validated before the orchestrator combines them.
- Failed or slow workers have a timeout and a retry or fallback.

## Interview questions

### Is a multi-agent system better than a single agent?

Not by default. It helps with parallel, separable tasks but uses more tokens and adds coordination failures. Start with one agent.

### What is the orchestrator-worker pattern?

One orchestrator agent splits the task, sends parts to worker agents, then checks and combines their results.

### How do agents in a multi-agent system communicate?

Usually through the orchestrator, by passing messages or structured results, or through shared files or state.

## Related cards

- [Sub-Agent](https://wonderium.dev/ai/sub-agent.md)
- [Parallel Agents](https://wonderium.dev/ai/parallel-agents.md)
- [Agentic Workflow](https://wonderium.dev/ai/agentic-workflow.md)
- [A2A](https://wonderium.dev/ai/a2a.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/multi-agent-system
- Last updated: 2026-11-25
