Purpose: How to correctly invoke subagents using the task tool
Priority: HIGH - Critical for agent delegation
Issue: Agents trying to invoke subagents with incorrect subagent_type format
Error:
Unknown agent type: ContextScout is not a valid agent type
Root Cause: The subagent_type parameter in the task tool must match the registered agent type in the OpenCode CLI, not the file path.
Based on the OpenCode CLI registration, use these exact strings for subagent_type:
Core Subagents:
"Task Manager" - Task breakdown and planning"Documentation" - Documentation generation"ContextScout" - Context file discoveryCode Subagents:
"Coder Agent" - Code implementation"TestEngineer" - Test authoring"Reviewer" - Code review"Build Agent" - Build validationSystem Builder Subagents:
"Domain Analyzer" - Domain analysis"Agent Generator" - Agent generation"Context Organizer" - Context organization"Workflow Designer" - Workflow design"Command Creator" - Command creationUtility Subagents:
"Image Specialist" - Image generation/editingtask(
subagent_type="Task Manager",
description="Break down feature into subtasks",
prompt="Detailed instructions..."
)
// ❌ Using file path
task(
subagent_type="TaskManager",
...
)
// ❌ Using kebab-case ID
task(
subagent_type="task-manager",
...
)
// ❌ Using registry path
task(
subagent_type=".opencode/agent/TaskManager.md",
...
)
# List all subagent names
cat registry.json | jq -r '.components.subagents[] | "\(.name)"'
Output:
Task Manager
Image Specialist
Reviewer
TestEngineer
Documentation Writer
Coder Agent
Build Agent
Domain Analyzer
Agent Generator
Context Organizer
Workflow Designer
Command Creator
ContextScout
# List available agents (if CLI supports it)
opencode list agents
Look at the name field in the subagent's frontmatter:
---
id: task-manager
name: Task Manager # ← Use this for subagent_type
type: subagent
---
task(
subagent_type="Task Manager",
description="Break down complex feature",
prompt="Break down the following feature into atomic subtasks:
Feature: {feature description}
Requirements:
- {requirement 1}
- {requirement 2}
Create subtask files in tasks/subtasks/{feature}/"
)
task(
subagent_type="Documentation",
description="Update documentation for feature",
prompt="Update documentation for {feature}:
What changed:
- {change 1}
- {change 2}
Files to update:
- {doc 1}
- {doc 2}"
)
task(
subagent_type="TestEngineer",
description="Write tests for feature",
prompt="Write comprehensive tests for {feature}:
Files to test:
- {file 1}
- {file 2}
Test coverage:
- Positive cases
- Negative cases
- Edge cases"
)
task(
subagent_type="Reviewer",
description="Review implementation",
prompt="Review the following implementation:
Files:
- {file 1}
- {file 2}
Focus areas:
- Security
- Performance
- Code quality"
)
task(
subagent_type="Coder Agent",
description="Implement subtask",
prompt="Implement the following subtask:
Subtask: {subtask description}
Files to create/modify:
- {file 1}
Requirements:
- {requirement 1}
- {requirement 2}"
)
Status: ⚠️ May not be registered in OpenCode CLI yet
The ContextScout subagent exists in the repository but may not be registered in the OpenCode CLI's available agent types.
Until ContextScout is properly registered, use direct file operations instead:
// ❌ This may fail
task(
subagent_type="ContextScout",
description="Find context files",
prompt="Search for context related to {topic}"
)
// ✅ Use direct operations instead
// 1. Use glob to find context files
glob(pattern="**/*.md", path=".opencode/context")
// 2. Use grep to search content
grep(pattern="registry", path=".opencode/context")
// 3. Read relevant files directly
read(filePath=".opencode/context/openagents-repo/core-concepts/registry.md")
ContextScoutFind incorrect invocations:
grep -r 'subagent_type="subagents/' .opencode/agent --include="*.md"
Replace with correct format:
# Example: Fix task-manager invocation
# Old: subagent_type="TaskManager"
# New: subagent_type="Task Manager"
Test the fix:
# Run agent with test prompt
# Verify subagent delegation works
// Pseudo-code for validation
available_types = [
"Task Manager",
"Documentation",
"TestEngineer",
"Reviewer",
"Coder Agent",
"Build Agent",
"Image Specialist",
"Domain Analyzer",
"Agent Generator",
"Context Organizer",
"Workflow Designer",
"Command Creator"
]
if subagent_type not in available_types:
error("Invalid subagent type: {subagent_type}")
✅ Use exact names - Match registry name field exactly
✅ Check registry first - Verify subagent exists before using
✅ Test invocations - Test delegation before committing
✅ Document dependencies - List required subagents in agent frontmatter
❌ Don't use paths - Never use file paths as subagent_type
❌ Don't use IDs - Don't use kebab-case IDs
❌ Don't assume - Always verify subagent is registered
Cause: Subagent type not registered in CLI or incorrect format
Solutions:
.opencode/agent/subagents/name fieldCause: Subagent file doesn't exist
Solutions:
./scripts/registry/validate-registry.shCause: Subagent invoked but doesn't execute
Solutions:
registry.json - Component catalog.opencode/agent/subagents/ - Subagent definitionsscripts/registry/validate-registry.shLast Updated: 2025-12-29
Version: 0.5.1