> Documentation index for m4trix: https://m4trix.dev/llms.txt. Every page is available as Markdown by appending `.md` to its URL.

# Multi-Agent Workflow

Source: https://m4trix.dev/docs/examples/multi-agent-workflow

Chain multiple agents so events flow through a pipeline: request → planner → executor → client.

## Pattern

```ts
const main = mainChannel;
const processing = createChannel('processing');
const client = createChannel('client').proxy(proxy.sse());

registerAgent(plannerAgent).subscribe(main).publishTo(processing);
registerAgent(executorAgent).subscribe(processing).publishTo(client);
```

## Example Structure

Create two (or more) agents with compatible events:

1. **Planner** — Listens to `request`, emits `plan-ready` with a plan payload
2. **Executor** — Listens to `plan-ready`, emits `agent-response` with the result

Each agent is built with `AgentFactory` and registered with `subscribe`/`publishTo` to form the chain.

## Location

The [core-example](https://m4trix.dev/docs/examples/minimal-starter.md) can be extended to add a second agent. See [Patterns: Agent Chain](https://m4trix.dev/docs/guides/patterns.md) for the full pattern.

## Next

- [Patterns](https://m4trix.dev/docs/guides/patterns.md)
- [Networks](https://m4trix.dev/docs/concepts/networks.md)
