opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(agent): add subagents config for per-agent task tool filtering

Open marcusquinn opened this issue 1 week ago • 4 comments

Summary

Adds a new subagents configuration option that allows primary agents to specify which subagents appear in their Task tool description. This reduces token overhead when many subagents are configured but only a subset is relevant to a particular agent.

Closes #7269

Problem

The Task tool description includes all configured subagents, adding ~6-10k tokens to the system prompt regardless of whether the agent will use them. With 150+ subagents, this significantly impacts:

  • Token costs (especially with reasoning models)
  • Effective context window for actual work

Solution

Add a subagents field to agent config that filters which subagents appear in the Task tool description:

{
  "agent": {
    "build": {
      "subagents": ["explore", "general", "code-*"]
    }
  }
}
  • Supports glob patterns (e.g., code-*, *-reviewer)
  • If not set, all subagents are available (backward compatible)
  • Works alongside existing permission.task (which controls runtime access)

Changes

  • packages/opencode/src/config/config.ts - Add subagents field to Agent schema
  • packages/opencode/src/agent/agent.ts - Add subagents to Agent.Info and state
  • packages/opencode/src/tool/task.ts - Filter agents based on caller's subagents config
  • packages/opencode/test/tool/task-subagents.test.ts - Tests for filtering logic
  • packages/web/src/content/docs/agents.mdx - Documentation

Testing

cd packages/opencode && bun test test/tool/task-subagents.test.ts

All 9 tests pass.

marcusquinn avatar Jan 08 '26 01:01 marcusquinn