Multi-Agent Workflows: Orchestrating AI Teams
A single LLM call can answer a question. But real-world tasks — research reports, content pipelines, code reviews — require multiple specialized agents working together. This guide shows you how to build multi-agent systems with ElsiumAI: from simple sequential chains to complex supervised teams with parallel execution and approval gates.
When to Use Multi-Agent Systems
You should reach for multi-agent architectures when:
- Tasks have distinct phases — research, writing, and review are fundamentally different skills
- You need specialization — a coding agent with different system prompts and tools than a writing agent
- Quality requires checks — a reviewer agent that validates the output of other agents
- Throughput matters — agents working in parallel on independent subtasks
If a single agent with tools can solve your problem, use that. Multi-agent adds coordination overhead — only use it when the task genuinely benefits from specialization.
Three Orchestration Patterns
ElsiumAI supports three patterns for multi-agent coordination:
| Pattern | When to Use | API |
|---|---|---|
| Sequential | Each step depends on the previous output | defineWorkflow |
| Parallel | Independent tasks that can run concurrently | defineParallelWorkflow |
| Supervisor | A coordinator delegates to agents dynamically | runSupervisor |
Step 1: Define Your Agents
Start by creating specialized agents. Each agent has its own system prompt, tools, and personality. Think of them as team members with distinct roles.
import { defineAgent, createMemory } from '@elsium-ai/agents'
import { defineTool, httpFetchTool } from '@elsium-ai/tools'
const researcher = defineAgent({
name: 'researcher',
system: 'Research topics thoroughly. Cite all sources. Be factual and comprehensive.',
memory: createMemory(),
tools: [httpFetchTool(), defineTool('search', { execute: webSearch })],
})
const writer = defineAgent({
name: 'writer',
system: 'Write clear, engaging content. Use the research provided as your source material.',
})
const coder = defineAgent({
name: 'coder',
system: 'Write clean, well-documented TypeScript code. Include error handling.',
})
const reviewer = defineAgent({
name: 'reviewer',
system: 'Review deliverables for quality, accuracy, and completeness. Be constructive but thorough.',
})
Step 2: Sequential Workflows
The simplest multi-agent pattern. Each step receives the output of the previous step. Use this when tasks form a natural pipeline.
import { defineWorkflow } from '@elsium-ai/workflows'
const contentPipeline = defineWorkflow('content-pipeline', [
step('research', async (topic) => researcher.run(topic)),
step('write', async (research) => writer.run(research)),
step('review', async (draft) => reviewer.run(draft)),
])
const result = await contentPipeline.run('The state of TypeScript AI frameworks')
// result contains the reviewed final draft
The data flows linearly: topic → research → draft → reviewed draft. Each agent only sees the output of the previous step.
Step 3: Parallel Workflows
When you need the same content transformed into multiple formats simultaneously, use parallel workflows. All branches run concurrently.
import { defineParallelWorkflow } from '@elsium-ai/workflows'
const multiFormat = defineParallelWorkflow('multi-format', {
blog: (content) => writer.run(`Write a blog post: ${content}`),
tweet: (content) => writer.run(`Write a tweet thread: ${content}`),
email: (content) => writer.run(`Write a newsletter: ${content}`),
})
const outputs = await multiFormat.run(researchReport)
// outputs.blog, outputs.tweet, outputs.email — all generated in parallel
This is significantly faster than running three sequential calls. If each generation takes 5 seconds, sequential takes 15 seconds while parallel takes ~5 seconds.
Step 4: Supervisor Pattern
The most powerful pattern. A supervisor agent receives the task, decides which agents to delegate to, reviews their work, and may request revisions. The supervisor acts as a project manager.
import { runSupervisor, runParallel } from '@elsium-ai/agents'
import { createApprovalGate } from '@elsium-ai/agents'
const result = await runSupervisor({
agents: [writer, coder, reviewer],
task: 'Build a landing page with compelling copy and working code',
approvalGate: createApprovalGate({ threshold: 'final-review' }),
})
The supervisor will:
- Analyze the task and create a plan
- Delegate the copy to the writer and the code to the coder (potentially in parallel)
- Send both outputs to the reviewer
- If the reviewer requests changes, loop back to the relevant agent
- Return the final approved result
Step 5: Conditional Branching
Some workflows need branching logic — different paths based on the input or intermediate results.
import { defineBranchWorkflow } from '@elsium-ai/workflows'
const ticketRouter = defineBranchWorkflow('ticket-router', {
condition: async (ticket) => {
const classification = await classifier.run(ticket)
return classification.category
},
branches: {
'technical': (ticket) => techAgent.run(ticket),
'billing': (ticket) => billingAgent.run(ticket),
'general': (ticket) => supportAgent.run(ticket),
},
})
Step 6: State Machines for Complex Flows
For workflows with loops, retries, and multiple decision points, use state machines. They give you explicit control over every transition.
import { executeStateMachine } from '@elsium-ai/workflows'
const result = await executeStateMachine({
initial: 'research',
states: {
research: {
execute: (ctx) => researcher.run(ctx.topic),
transitions: { done: 'write' },
},
write: {
execute: (ctx) => writer.run(ctx.research),
transitions: { done: 'review' },
},
review: {
execute: async (ctx) => {
const review = await reviewer.run(ctx.draft)
return { ...ctx, review, approved: review.approved }
},
transitions: {
approved: 'done',
revision: 'write', // Loop back for another draft
},
decide: (ctx) => ctx.approved ? 'approved' : 'revision',
},
done: { terminal: true },
},
})
State machines shine when you need retry loops, branching decisions, or explicit control over the workflow lifecycle.
Step 7: Observe Everything
Multi-agent systems are hard to debug without observability. Use @elsium-ai/observe to trace every agent call, measure latency, and track costs across the entire workflow.
import { createSpan, createMetrics } from '@elsium-ai/observe'
const span = createSpan('content-pipeline', { workflow: 'multi-agent' })
// Each agent call is automatically traced as a child span
const result = await span.trace(async () => {
return contentPipeline.run('TypeScript AI frameworks')
})
// span.duration, span.children, span.cost — all available
Step 8: Test Multi-Agent Systems
import { createTestAgent, mockProvider } from '@elsium-ai/testing'
const mockWriter = createTestAgent({
agent: writer,
provider: mockProvider('anthropic', {
responses: [{ content: 'Mock blog post about AI frameworks.' }],
}),
})
const mockReviewer = createTestAgent({
agent: reviewer,
provider: mockProvider('anthropic', {
responses: [{ content: 'Approved. Well-written and accurate.' }],
}),
})
// Test the full pipeline with mocked agents
const result = await contentPipeline.run('Test topic', {
overrides: { writer: mockWriter, reviewer: mockReviewer },
})
assert(result.content.includes('Approved'))
Choosing the Right Pattern
| Scenario | Pattern | Why |
|---|---|---|
| Content pipeline (research → write → review) | Sequential | Each step depends on the previous |
| Generate blog + tweet + email from one brief | Parallel | Independent outputs, faster execution |
| Complex project with delegation and revisions | Supervisor | Dynamic coordination and quality loops |
| Ticket routing to specialized agents | Branch | Different paths based on input |
| Workflow with retry loops and decision points | State Machine | Explicit control over transitions |
What’s Next
- Add MCP servers — give agents access to external tools via the Model Context Protocol
- Governance layer — enforce policies on what agents can do with
@elsium-ai/coregovernance rules - Human-in-the-loop — add approval gates at critical workflow steps
- Persistent workflows — store workflow state so long-running tasks survive restarts
Check out the @elsium-ai/agents docs and @elsium-ai/workflows docs for the full API reference, or explore 30 more products you can build with ElsiumAI.
Eric Utrera
Creator of ElsiumAI. Building production AI infrastructure.