The src/agents/ directory implements a multi-agent orchestration system for OpenCode. It defines specialized AI agents with distinct roles, capabilities, and behaviors that collaborate under an orchestrator to optimize coding tasks across quality, speed, cost, and reliability dimensions.
Agent Definition Interface (defined in orchestrator.ts)
interface AgentDefinition {
name: string;
description?: string;
config: AgentConfig;
/** Priority-ordered model entries for runtime fallback resolution. */
_modelArray?: Array<{ id: string; variant?: string }>;
}
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: { ... } }configuredSkills parameterCustom Prompts
loadAgentPrompt(name) from config| Agent | Primary Focus | Tools | Constraints | Temperature |
|---|---|---|---|---|
| Explorer | Codebase navigation | grep, glob, ast_grep_search | Read-only, parallel | 0.1 |
| Librarian | External docs | context7, grep_app, websearch | Evidence-based, citations required | 0.1 |
| Oracle | Architecture guidance | Analysis tools, code review | Read-only, advisory | 0.1 |
| Designer | UI/UX implementation | Tailwind, CSS, animations | Visual excellence priority | 0.7 |
| Fixer | Implementation | Edit/write, lsp_diagnostics | No research/delegation, structured output | 0.2 |
createAgents(config?)
│
├─→ For each subagent:
│ ├─→ Get model (with fallback for fixer)
│ ├─→ Load custom prompts
│ ├─→ Call factory function
│ ├─→ Apply overrides (model, temperature, variant)
│ └─→ Apply default permissions (question: 'allow', skill permissions)
│
├─→ Create orchestrator:
│ ├─→ Get model (or leave unset for runtime resolution)
│ ├─→ 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)
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
├── index.test.ts # Unit tests for agent creation and configuration
├── orchestrator.ts # Orchestrator agent definition, delegation workflow, AgentDefinition interface
├── 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()