intermediate45 minLesson 1 of 6

Multi-Agent Orchestration Patterns

Design and implement multi-agent workflows in OpenCode. Learn routing strategies, delegation patterns, and how to coordinate multiple agents for complex tasks.

Multi-Agent Orchestration Patterns

Why Multi-Agent?

Single agents work well for simple tasks, but complex projects benefit from specialized agents working together.

PatternUse CaseBenefit
RouterDirect tasks to specialistsBetter accuracy
PipelineSequential processingClear workflow
ParallelIndependent tasksFaster execution
HierarchicalComplex delegationScalability

Router Pattern

The router pattern directs tasks to the most appropriate agent based on content.

json
{ "agents": { "default": { "model": "gpt-4o", "description": "Routes tasks to specialists" }, "frontend": { "model": "gpt-4o", "description": "React, CSS, TypeScript, UI/UX" }, "backend": { "model": "claude-sonnet-4-20250514", "description": "APIs, databases, server logic" }, "devops": { "model": "gpt-4o", "description": "Docker, CI/CD, deployment, infrastructure" } }, "agentRouting": { "mode": "auto", "defaultAgent": "default", "rules": [ { "pattern": "react|css|component|ui|frontend", "agent": "frontend" }, { "pattern": "api|database|sql|endpoint|backend", "agent": "backend" }, { "pattern": "docker|deploy|ci/cd|pipeline|kubernetes", "agent": "devops" } ] } }

Pipeline Pattern

Chain agents for sequential processing:

100%

Implementation

json
{ "agents": { "requirements": { "model": "gpt-4o", "description": "Analyzes requirements and creates specifications" }, "design": { "model": "claude-sonnet-4-20250514", "description": "Creates technical design from specifications" }, "implement": { "model": "gpt-4o", "description": "Writes code based on design documents" }, "test": { "model": "gpt-4o-mini", "description": "Generates and runs tests" }, "review": { "model": "claude-sonnet-4-20250514", "description": "Reviews code quality and security" } } }

Parallel Pattern

Execute independent tasks simultaneously:

100%

When to Use Parallel

Task TypeParallel?Reason
Independent modulesNo dependencies
Cross-cutting concernsNeed coordination
Sequential logicOrder matters
Multiple test suitesIndependent execution

Hierarchical Pattern

Use subagents for complex delegation:

json
{ "agents": { "lead": { "model": "gpt-4o", "description": "Project lead that coordinates work", "subagents": { "frontend-lead": { "model": "gpt-4o", "description": "Manages frontend team" }, "backend-lead": { "model": "gpt-4o", "description": "Manages backend team" } } } } }

Agent Communication

Via Files

Agents can communicate through shared files:

python
# Agent 1 writes with open("tmp/design.json", "w") as f: json.dump(design_spec, f) # Agent 2 reads with open("tmp/design.json") as f: design_spec = json.load(f)

Via Context

The primary agent passes context to subagents:

> Have the backend agent implement the API, then have the test agent write tests for it

Best Practices

Agent Specialization

Agent TypeModelTemperatureUse Case
ArchitectClaude0.3Design decisions
CoderGPT-4o0.7Implementation
ReviewerClaude0.2Code review
TesterGPT-4o-mini0.5Test generation

Permission Isolation

json
{ "permissions": [ { "tool": "write", "allow": ["src/frontend/**"], "agent": "frontend" }, { "tool": "write", "allow": ["src/backend/**"], "agent": "backend" } ] }

Practice Questions

Practice Question

Which orchestration pattern is best for tasks that can run independently?

Practice Question

What field controls how OpenCode routes tasks to agents?

Practice Question

When should you use the pipeline pattern instead of parallel?

Practice Question

How do subagents communicate with their parent agent?

Practice Question

Which model temperature is best for code review tasks?


Success

Key Takeaways

  • Multi-agent workflows improve accuracy through specialization
  • The router pattern directs tasks to specialists based on content
  • Use pipeline for sequential dependencies, parallel for independent tasks
  • Hierarchical patterns with subagents enable complex delegation
  • Agent temperature should match the task: low for review, high for creativity
  • Permission isolation prevents agents from interfering with each other
  • Agents communicate through shared files and context, not external systems
Progress17%