OpenWriterControle/.opencode/context/openagents-repo/guides/subagent-invocation.md
Darren Hinde 456021fdab
refactor: Standardize agent naming to TestEngineer and fix permissions (#178)
* fix: migrate all agents to OpenCode v1.1.1+ permission (singular) key

Resolves #164

## Changes

### Agent Files (16 files)
- Migrated all agent frontmatter from deprecated `permissions:` (plural) to `permission:` (singular)
- Updated: core agents (OpenCoder, OpenAgent, RepoManager)
- Updated: code subagents (TestEngineer, CoderAgent, BuildAgent, CodeReviewer)
- Updated: core subagents (TaskManager, DocWriter, ExternalScout, ContextScout, ContextManager, Context Retriever)
- Updated: development subagents (DevOpsSpecialist, FrontendSpecialist)
- Updated: system-builder subagents (ContextOrganizer, WorkflowDesigner)

### Context Documentation (3 files)

#### Updated: agent-frontmatter.md
- Fixed field name from `permissions:` to `permission:`
- Updated all examples to use correct singular form
- Corrected "Wrong Field Names" section to show `permissions:` as deprecated
- Updated validation checklist and valid keys list

#### Updated: agent-metadata.md
- Added clarification that `permission` replaces deprecated `permissions`
- Added comprehensive migration guide with before/after examples
- Added validation steps for migration

#### New: permission-patterns.md
- Comprehensive 400+ line permission patterns reference
- Permission evaluation order (last-matching-wins)
- Complete table of valid permission keys
- Agent type patterns (read-only, write-enabled, orchestrators)
- Security patterns (sensitive files, dangerous commands)
- Task permission patterns
- Complete working examples for each agent type
- Validation checklist

## Verification

- ✅ 0 agents using deprecated `permissions:` (plural)
- ✅ 16 agents using correct `permission:` (singular)
- ✅ All permission patterns follow last-matching-wins order
- ✅ Security denials applied consistently
- ✅ Context documentation updated and accurate

## Migration Details

Based on official OpenCode documentation (https://opencode.ai/docs/agents/):
- OpenCode v1.1.1+ uses `permission:` (singular)
- Deprecated: `permissions:` (plural)
- Granular control with last-matching-wins evaluation
- Valid actions: "allow", "ask", "deny"

All agents now comply with OpenCode v1.1.1+ standards.

* fix: correct YAML errors and restore missing permissions in agent configs

- Fix repo-manager.md duplicate permission section
- Fix externalscout.md YAML indentation error
- Remove old tools: section from devops-specialist.md
- Restore context file permissions in context-manager.md
- Restore test command permissions in tester.md
- Clean up formatting in coder-agent.md

All 20 agent files now have valid YAML frontmatter with proper permission blocks.

* fix: standardize permission key across agent files

- Updated all instances of `permissions:` to `permission:` in agent frontmatter for consistency.
- Removed deprecated `write:` and `edit:` sections from externalscout.md.
- Adjusted related documentation to reflect the singular form of permission key.

These changes ensure compliance with OpenCode v1.1.1+ standards and improve YAML structure across the repository.

* feat: implement parallel execution workflow for TaskManager and CoderAgent

- Update OpenCoder Stage 5 to support parallel batch execution
- Add batch analysis, grouping, and simultaneous delegation patterns
- Update OpenAgent ExecuteParallel step with task-cli integration
- Update CoderAgent to self-update task status on completion
- Create new BatchExecutor subagent for parallel task management
- Add BatchExecutor to agent metadata with dependencies
- Enable 50-70% time savings for multi-component features

Closes parallel execution gap between TaskManager and CoderAgent

* refactor: clarify BatchExecutor usage logic and multiple executor patterns

- Add explicit decision logic for when to use BatchExecutor vs direct execution
- Document threshold: 1-4 tasks = direct, 5+ tasks = BatchExecutor
- Add advanced pattern section for multiple simultaneous BatchExecutors
- Clarify default behavior: one feature at a time, batches within feature parallel
- Update execution philosophy with BatchExecutor usage guidelines

* feat(plugins): add coder-verification plugin for agent validation

- Add coder-verification plugin with validation hooks
- Implements session validation and approval gate checking
- Provides delegation analysis and context compliance tracking
- Includes comprehensive implementation summary and README

* refactor: standardize agent naming to TestEngineer and fix permissions

BREAKING CHANGE: Renamed 'Tester' to 'TestEngineer' for consistency

Agent Naming Updates:
- Rename: tester.md → test-engineer.md
- Update registry.json path to point to test-engineer.md
- Update all references in subagent-invocation.md guide
- Update example comment in repo-manager.md

Permission Fixes:
- CoderAgent: Remove empty bash section, add TestEngineer task permission
- CodeReviewer: Remove redundant task deny-all rule

Why:
- Consistent naming across all agents (OpenCoder, TestEngineer, etc.)
- Cleaner permission patterns (remove redundant rules)
- Fixes subagent invocation with correct agent names

Files Changed:
- .opencode/agent/subagents/code/test-engineer.md (renamed from tester.md)
- .opencode/agent/subagents/code/coder-agent.md (permissions)
- .opencode/agent/subagents/code/reviewer.md (permissions)
- .opencode/agent/meta/repo-manager.md (example comment)
- .opencode/context/openagents-repo/guides/subagent-invocation.md (all refs)
- registry.json (path update)
2026-02-06 00:41:21 +00:00

7.5 KiB

Guide: Subagent Invocation

Purpose: How to correctly invoke subagents using the task tool
Priority: HIGH - Critical for agent delegation


The Problem

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.


Correct Subagent Invocation

Available Subagent Types

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 discovery

Code Subagents:

  • "Coder Agent" - Code implementation
  • "TestEngineer" - Test authoring
  • "Reviewer" - Code review
  • "Build Agent" - Build validation

System Builder Subagents:

  • "Domain Analyzer" - Domain analysis
  • "Agent Generator" - Agent generation
  • "Context Organizer" - Context organization
  • "Workflow Designer" - Workflow design
  • "Command Creator" - Command creation

Utility Subagents:

  • "Image Specialist" - Image generation/editing

Invocation Syntax

✅ Correct Format

task(
  subagent_type="Task Manager",
  description="Break down feature into subtasks",
  prompt="Detailed instructions..."
)

❌ Incorrect Formats

// ❌ 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",
  ...
)

How to Find the Correct Type

Method 1: Check Registry

# 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

Method 2: Check OpenCode CLI

# List available agents (if CLI supports it)
opencode list agents

Method 3: Check Agent Frontmatter

Look at the name field in the subagent's frontmatter:

---
id: task-manager
name: Task Manager  # ← Use this for subagent_type
type: subagent
---

Common Subagent Invocations

Task Manager

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}/"
)

Documentation

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}"
)

TestEngineer

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"
)

Reviewer

task(
  subagent_type="Reviewer",
  description="Review implementation",
  prompt="Review the following implementation:
          
          Files:
          - {file 1}
          - {file 2}
          
          Focus areas:
          - Security
          - Performance
          - Code quality"
)

Coder Agent

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}"
)

ContextScout Special Case

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.

Workaround

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")

Fixing Existing Agents

Agents That Need Fixing

  1. repo-manager.md - Uses ContextScout
  2. opencoder.md - Check if uses incorrect format

Fix Process

  1. Find incorrect invocations:

    grep -r 'subagent_type="subagents/' .opencode/agent --include="*.md"
    
  2. Replace with correct format:

    # Example: Fix task-manager invocation
    # Old: subagent_type="TaskManager"
    # New: subagent_type="Task Manager"
    
  3. Test the fix:

    # Run agent with test prompt
    # Verify subagent delegation works
    

Validation

Check Subagent Type Before Using

// 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}")

Best Practices

✅ 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


Troubleshooting

Error: "Unknown agent type"

Cause: Subagent type not registered in CLI or incorrect format

Solutions:

  1. Check registry for correct name
  2. Verify subagent exists in .opencode/agent/subagents/
  3. Use exact name from registry name field
  4. If subagent not registered, use direct operations instead

Error: "Subagent not found"

Cause: Subagent file doesn't exist

Solutions:

  1. Check file exists at expected path
  2. Verify registry entry is correct
  3. Run ./scripts/registry/validate-registry.sh

Delegation Fails Silently

Cause: Subagent invoked but doesn't execute

Solutions:

  1. Check subagent has required tools enabled
  2. Verify subagent permissions allow operation
  3. Check subagent prompt is clear and actionable

  • Registry: registry.json - Component catalog
  • Subagents: .opencode/agent/subagents/ - Subagent definitions
  • Validation: scripts/registry/validate-registry.sh

Last Updated: 2025-12-29
Version: 0.5.1