The src/agents/ directory defines and configures the multi-agent orchestration system for OpenCode. It creates specialized AI agents with distinct roles, capabilities, and behaviors that work together under an orchestrator to optimize coding tasks for quality, speed, cost, and reliability.
Agent Definition Interface
interface AgentDefinition {
name: string;
description?: string;
config: AgentConfig;
}
All agents follow a consistent factory pattern:
createXAgent(model, customPrompt?, customAppendPrompt?) → AgentDefinitionPrimary Agent
Subagents (5 specialized agents)
Override Application
../config/DEFAULT_MODELSPermission System
question: 'allow' by defaultgetSkillPermissionsForAgent(){ question, skill: { ... } }Custom Prompts
loadAgentPrompt(name) from config| Agent | Primary Focus | Tools | Constraints | Temperature |
|---|---|---|---|---|
| Explorer | Codebase search | grep, glob, ast_grep_search | Read-only, parallel | 0.1 |
| Librarian | External docs | context7, grep_app, websearch | Evidence-based | 0.1 |
| Oracle | Architecture | Analysis tools | Read-only, advisory | 0.1 |
| Designer | UI/UX | Tailwind, CSS | Visual excellence | 0.7 |
| Fixer | Implementation | Edit/write tools | No research/delegation | 0.2 |
createAgents(config?)
│
├─→ For each subagent:
│ ├─→ Get model (with fallback for fixer)
│ ├─→ Load custom prompts
│ ├─→ Call factory function
│ ├─→ Apply overrides (model, temperature)
│ └─→ Apply default permissions
│
├─→ Create orchestrator:
│ ├─→ Get model
│ ├─→ Load custom prompts
│ ├─→ Call factory function
│ ├─→ Apply overrides
│ └─→ Apply default permissions
│
└─→ Return [orchestrator, ...subagents]
getAgentConfigs(config?)
│
├─→ createAgents(config)
│
├─→ For each agent:
│ ├─→ Extract config
│ ├─→ Add description
│ ├─→ Add MCP list via getAgentMcpList()
│ ├─→ Set mode:
│ │ ├─→ 'primary' for orchestrator
│ │ └─→ 'subagent' for others
│ └─→ Map to Record<string, SDKAgentConfig>
│
└─→ Return config object
User Request
│
↓
Understand (parse requirements)
│
↓
Path Analysis (quality, speed, cost, reliability)
│
↓
Delegation Check
│
├─→ Need to discover unknowns? → @explorer
├─→ Complex/evolving APIs? → @librarian
├─→ High-stakes decisions? → @oracle
├─→ User-facing polish? → @designer
├─→ Clear spec, parallel tasks? → @fixer
└─→ Simple/quick? → Do yourself
│
↓
Parallelize (if applicable)
│
├─→ Multiple @explorer searches?
├─→ @explorer + @librarian research?
└─→ Multiple @fixer instances?
│
↓
Execute & Integrate
│
↓
Verify (lsp_diagnostics, tests)
Research → Implementation Chain
Orchestrator
↓ delegates to
Explorer (find files) + Librarian (get docs)
↓ provide context to
Fixer (implement changes)
Advisory Pattern
Orchestrator
↓ delegates to
Oracle (architecture decision)
↓ provides guidance to
Orchestrator (implements or delegates to Fixer)
Design Pattern
Orchestrator
↓ delegates to
Designer (UI/UX implementation)
↓ (Designer may use Fixer for parallel tasks)
External Dependencies
@opencode-ai/sdk - Core agent configuration types (AgentConfig)@modelcontextprotocol/sdk - MCP protocol (via config)Internal Dependencies
../config - Agent overrides, default models, MCP lists, custom prompts../cli/skills - Skill permission system (getSkillPermissionsForAgent)Direct Consumers
src/index.ts - Main plugin entry point exports getAgentConfigs()src/cli/index.ts - CLI entry point uses agent configurationsIndirect Consumers
getAgentConfigs()Agent Override Config
interface AgentOverrideConfig {
model?: string;
temperature?: number;
skills?: string[];
}
Plugin Config
interface PluginConfig {
agents?: {
[agentName: string]: AgentOverrideConfig;
};
// ... other config
}
Each agent gets skill-specific permissions:
../cli/skillsskill key in permissions objectAgents are configured with specific MCP tool lists:
getAgentMcpList(agentName, config) returns tool listquestion: 'allow' for smooth UXsrc/agents/
├── index.ts # Main entry point, agent factory registry, config application
├── orchestrator.ts # Orchestrator agent definition and delegation workflow
├── explorer.ts # Codebase navigation specialist
├── librarian.ts # Documentation and library research specialist
├── oracle.ts # Strategic technical advisor
├── fixer.ts # Fast implementation specialist
└── designer.ts # UI/UX design specialist
Adding New Agents
src/agents/newagent.ts with createNewAgent() factorySUBAGENT_FACTORIES in index.tsSUBAGENT_NAMES in ../config../config/DEFAULT_MODELS../config/agent-mcps../cli/skillsCustomizing Existing Agents
loadAgentPrompt()