Multi-Agent Patterns
Patterns for Multiple Agents
Section titled “Patterns for Multiple Agents”Nulang’s AI runtime provides three multi-agent patterns that compose agents into structured workflows. Each pattern addresses a different coordination need.
| Pattern | Use case |
|---|---|
| Pipeline | Sequential processing through stages |
| Debate | Pro/con argumentation with synthesis |
| Supervisor team | Hierarchical agent management with restart strategies |
Pipelines
Section titled “Pipelines”A pipeline chains agents through named stages. Each stage receives the previous stage’s output and processes it according to a template.
Building a pipeline
Section titled “Building a pipeline”agent Researcher = { model: "llama3.1", system_prompt: "You are a researcher. Provide factual information.", pricing: { input: 0.0, output: 0.0 }}
agent Writer = { model: "llama3.1", system_prompt: "You are a writer. Create engaging content.", pricing: { input: 0.0, output: 0.0 }}
fn main() { let researcher = spawn Researcher {} in let writer = spawn Writer {} in let pipeline = Pipeline.new() |> Pipeline.stage("research", researcher, "Research: {input}") |> Pipeline.stage("write", writer, "Write based on: {input}") in pipeline.run("CRDTs")}The {input} placeholder in each stage’s template is replaced with the previous stage’s output. pipeline.run("CRDTs") executes the stages in order and returns the final output.
Debates
Section titled “Debates”Debates coordinate multiple agents arguing different positions, with a moderator synthesizing the final answer.
Declaring a debate
Section titled “Declaring a debate”Define agents for each position plus a moderator:
agent ProAgent = { model: "llama3.1", system_prompt: "Argue in favor.", pricing: { input: 0.0, output: 0.0 }}
agent ConAgent = { model: "llama3.1", system_prompt: "Argue against.", pricing: { input: 0.0, output: 0.0 }}
agent Moderator = { model: "llama3.1", system_prompt: "Synthesize the arguments into a balanced conclusion.", pricing: { input: 0.0, output: 0.0 }}The debate runtime runs the pro and con agents in rounds, then feeds their arguments to the moderator for synthesis. Each agent maintains its own memory and position across rounds.
When to use debates
Section titled “When to use debates”Debates are effective for questions with genuine tradeoffs — architectural decisions, trade-off analysis, or any problem where considering opposing viewpoints improves the answer. For straightforward tasks, a single agent or a pipeline is simpler and cheaper.
Supervisor Teams
Section titled “Supervisor Teams”Supervisor teams apply OTP-style supervision to agents. If an agent fails (LLM timeout, rate limit, malformed response), the supervisor restarts it according to a strategy.
How supervisor teams work
Section titled “How supervisor teams work”The supervisor team runtime wraps agents in a supervision tree. Each agent is a supervised child. When an agent’s LLM call fails, the supervisor applies its restart strategy:
| Strategy | Behavior on failure |
|---|---|
| Restart the failed agent only | One-for-one |
| Restart all agents in the team | One-for-all |
This mirrors the actor supervision model — the same OTP primitives, applied to agents. The difference is that agent supervisors understand LLM-specific failure modes (rate limits, provider outages) and can apply backoff before restarting.
When to use supervisor teams
Section titled “When to use supervisor teams”Use supervisor teams when running long-lived agents that must survive transient failures — a persistent assistant, a monitoring agent, or any agent that should recover automatically without manual intervention.
Combining Patterns
Section titled “Combining Patterns”The three patterns compose. A common production setup:
- A supervisor team wraps a set of agents for fault tolerance.
- The supervised agents participate in a pipeline for sequential processing.
- A debate stage in the pipeline handles questions requiring multiple perspectives.
- Durable Workflows Overview — workflows orchestrate agents with checkpointed state
- Supervision Trees — the OTP supervision model that agent supervisors extend