[PR #7271] feat(agent): add subagents config for per-agent task tool filtering #12325

Open
opened 2026-02-16 18:17:14 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7271

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7271 **State:** open **Merged:** No --- ## 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: ```json { "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 ```bash cd packages/opencode && bun test test/tool/task-subagents.test.ts ``` All 9 tests pass.
yindo added the pull-request label 2026-02-16 18:17:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12325