Multi-Agent Systems in Practice
Not every scenario needs multiple Agents. Multi-Agent is worth it when the work needs different expertise, parallel independent subtasks, or multi-party verification.
When Multi-Agent Is Needed
Single Agent handles:
- task boundaries clear
- needs centralized decision
- tool call chain not long
Consider Multi-Agent:
- task needs different expertise
- needs parallel processing of independent subtasks
- decisions need multi-party verification
- system scale needs responsibility separationCommon Architectures
Supervisor + Workers
Supervisor Agent
├── Worker Agent A (handles domain)
├── Worker Agent B (handles another domain)
└── Worker Agent C (handles third domain)// Supervisor handles task decomposition and synthesis
interface Worker {
execute(subtask: Subtask): Promise<SubtaskResult>;
}
class Supervisor {
async handle(task: Task): Promise<FinalResult> {
const subtasks = await this.decompose(task);
const results: SubtaskResult[] = [];
for (const subtask of subtasks) {
const worker = this.selectWorker(subtask);
results.push(await worker.execute(subtask));
}
return this.synthesize(results);
}
}Good for: tasks decomposable, subtasks relatively independent.
Sequential Pipeline
Agent A → Agent B → Agent C → Agent D// Sequential pipeline: each stage consumes the previous stage's output
const pipeline: Array<[string, StageAgent]> = [
["research", new ResearchAgent()],
["analyze", new AnalyzeAgent()],
["write", new WriteAgent()],
["review", new ReviewAgent()],
];
async function runPipeline(initialInput: string): Promise<string> {
let output = initialInput;
for (const [, agent] of pipeline) {
output = await agent.process(output);
if (agent.needsRetry(output)) {
output = await agent.retry(output);
}
}
return output;
}Good for: ordered steps, each with clear input/output.
Parallel + Merge
→ Agent A (parallel)
Task → → Agent B (parallel) → Merge Agent → Result
→ Agent C (parallel)// Parallel multi-perspective execution followed by synthesis
async function parallelAnalyze(task: Task): Promise<Report> {
const agents = [new ResearchAgent(), new AnalyzeAgent(), new CritiqueAgent()];
const results = await Promise.all(agents.map((agent) => agent.process(task)));
return mergeAgent.synthesize(results);
}Good for: multi-perspective analysis, synthesizing different viewpoints.
Communication Protocols
Multi-Agent needs communication. Two approaches:
Shared Message Queue
// Decoupled communication via a shared async queue
class QueueAgent {
constructor(
private readonly name: string,
private readonly inbox: AsyncQueue<AgentMessage>,
private readonly outbox: AsyncQueue<AgentMessage>,
) {}
async run(signal: AbortSignal): Promise<void> {
while (!signal.aborted) {
const msg = await this.inbox.dequeue(signal);
const result = await this.process(msg);
await this.outbox.enqueue({
from: this.name,
to: "merge",
content: result,
});
}
}
}Explicit Message Passing
// Explicit point-to-point messaging
class DirectAgent {
async sendTo(target: string, content: unknown): Promise<void> {
await this.messenger.send({
to: target,
content,
metadata: { priority: "normal" },
});
}
receive(): Promise<AgentMessage> {
return this.messenger.receive(this.id);
}
}Pitfalls Encountered
Information Loss Between Agents
// Prevent information loss with a strongly typed handoff contract
interface ResearchOutput {
findings: string[];
sources: string[];
confidence: number;
rawData: Record<string, unknown>;
}Circular Dependencies
Agent A → Agent B → Agent C
↑ ↓
└─────────────────────┘
# Agent C depends on A
# Agent A also indirectly depends on C// Prevent circular dependencies with a DAG and explicit arbitration
class Orchestrator {
resolveConflict(a: AgentResult, b: AgentResult): AgentResult {
return a.confidence >= b.confidence ? a : b;
}
}Debugging Difficulty
// Improve debuggability with structured per-agent logs and replayable queues
class TracedAgent {
async process(msg: AgentMessage): Promise<AgentResult> {
logger.info({ agent: this.name, event: "received", msgId: msg.id });
const result = await this.processImpl(msg);
logger.info({ agent: this.name, event: "completed", msgId: msg.id, status: result.status });
return result;
}
}Framework Selection
| Framework | Use Case | Characteristics |
|---|---|---|
| LangGraph | complex flow orchestration | strong state management |
| AutoGen | multi-Agent dialogue | rich collaboration modes |
| CrewAI | clear role separation | easy to start |
| Custom | highly customized | flexible but high effort |
Conclusion
Multi-Agent’s value: let specialists do specialized work.
Multiple Agents each have strengths, and combined they handle more complex tasks than a single Agent. Still, Multi-Agent adds communication, debugging, and consistency overhead (for the single-agent vs multi-agent trade-off, see AI Agent Architecture Patterns). Start with a single Agent and split only when context or specialization boundaries genuinely demand it.