Skip to content

[feat] Add "subagent" AI task delegation #1293

Closed

Description

@monotykamary

I mean, they just came out with subagents, which sounds like a pretty good story progression given how terminal agents are becoming primitives to creating personal AI architectures.

Key Concepts

  • Subagents: Specialized, pre-configured AI "personalities" that opencode can invoke for domain-specific tasks (e.g., code review, testing, data analysis).
  • Context encapsulation: Each subagent handles its own conversation context, preventing cross-task pollution.
  • Configurable toolsets: Subagents may be restricted to a subset of tools, for task-appropriate behavior and security.
  • Explicit/automatic invocation: Users can invoke subagents via commands, or opencode can delegate based on task descriptions.

Example workflow

  • Interactive switch:
    /agents
  • Developer triggers:
    /agents run code-reviewer on latest PR
  • Opencode delegates the request to code-reviewer subagent, which loads its config, handles task, and returns results in a contextually isolated manner.

Proposed Implementation (MVP)

  • Subagent configs:
    Store subagent definitions as YAML/markdown files (project or user scope).
    Example format (adapted from Claude Code):

    ---
    name: code-reviewer
    description: Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code.
    tools: Read, Grep, Glob, Bash
    ---
    You are a senior code reviewer ensuring high standards of code quality and security.
    
    When invoked:
    1. Run git diff to see recent changes
    2. Focus on modified files
    3. Begin review immediately
    
    Review checklist:
    - Code is simple and readable
    - Functions and variables are well-named
    - No duplicated code
    - Proper error handling
    - No exposed secrets or API keys
    - Input validation implemented
    - Good test coverage
    - Performance considerations addressed
    
    Provide feedback organized by priority:
    - Critical issues (must fix)
    - Warnings (should fix)
    - Suggestions (consider improving)
    
    Include specific examples of how to fix issues.
  • Registry/loader:
    Subagent configs scanned at startup or on-demand.

  • Invocation:
    CLI (or API) support for explicit invocation. Auto-delegation for tasks matching a subagent's description (simple keyword matching for MVP).

  • Context isolation:
    Separate context store per subagent session.

  • Extensibility:
    Designed for future chaining (i.e., compose subagents for multi-step workflows).

Other Example:

---
name: debugger
description: Debugging specialist for errors, test failures, and unexpected behavior. Use proactively when encountering any issues.
tools: Read, Edit, Bash, Grep, Glob
---
You are an expert debugger specializing in root cause analysis.

When invoked:
1. Capture error message and stack trace
2. Identify reproduction steps
3. Isolate the failure location
4. Implement minimal fix
5. Verify solution works

Debugging process:
- Analyze error messages and logs
- Check recent code changes
- Form and test hypotheses
- Add strategic debug logging
- Inspect variable states

For each issue, provide:
- Root cause explanation
- Evidence supporting the diagnosis
- Specific code fix
- Testing approach
- Prevention recommendations

Focus on fixing the underlying issue, not just symptoms.

Benefits:

  • Keeps main workflows focused; specialized agents reduce clutter. Also a chance to let users prompt engineer for their specific use case or peculiar models.
  • Encourages best practices by delegating review/debug tasks to expert-coded prompts/tools.
  • Allows project-level or user-level customization and sharing.

Acceptance Criteria:

  • Can define and register at least one subagent per project/user.
  • Can explicitly invoke a subagent on a task, passing target payload.
  • Each subagent session maintains separate context/logging.
  • Supports restriction of tool access per subagent (basic allowlist).

Activity

  1. thdxr commented on Jul 25, 2025

    @thdxr
    Member

    done

  2. self-assigned this
    on Jul 25, 2025
  3. fahimanwer commented on Sep 8, 2025

    @fahimanwer

    Can we limit the tools subagent is allowed to use?

  4. rekram1-node commented on Sep 8, 2025

    @rekram1-node
    Contributor

    yes you can configure tools and permissions per subagent see docs

    https://opencode.ai/docs/agents/#json

  5. added a commit that references this issue on May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions