Skip to content

Reduce token overhead: Task tool injects all subagent descriptions into system prompt #7269

@marcusquinn

Description

@marcusquinn

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

The task tool definition includes the full list of all configured subagents with their descriptions, injected into every conversation's system prompt. With many subagents configured, this adds significant token overhead before the user even sends their first message.

Example: With 150 subagents configured in ~/.config/opencode/agent/, the task tool description alone adds ~6,000-10,000 tokens to every conversation, regardless of whether the agent will actually use subagents.

Current Behavior

The task tool description contains entries like:

Available agent types and the tools they have access to:
- general: General-purpose agent...
- explore: Fast agent specialized for exploring codebases...
- dev-browser: Read ~/.aidevops/agents/tools/browser/dev-browser.md
- authentication: Read ~/.aidevops/agents/tools/git/authentication.md
... (150+ entries)

This is injected for every agent that has task: true in their tools config.

Impact

Measured Example

Comparing two agents with identical instructions but different tool access:

Agent Task Tool First Message Tokens
Plan+ Disabled ~X tokens
Build+ Enabled ~X + 11,000 tokens

The ~11k difference is primarily the task tool's subagent list.

Proposed Solutions

Option A: Per-agent subagent filtering (preferred)

Allow primary agents to specify which subagents they can spawn:

{
  "agent": {
    "Build+": {
      "tools": {
        "task": ["explore", "dev-browser", "code-review"]
      }
    }
  }
}

Only listed subagents would appear in that agent's task tool definition. This also improves focus - the LLM only sees relevant options.

Option B: Lazy loading / on-demand lookup

Instead of injecting all descriptions upfront, provide a minimal task tool that can look up subagent details on demand:

task tool: "Launch subagents. Use `task list` to see available agents, or `task run <name> <prompt>` to launch."

The LLM would call task list only when it needs to spawn a subagent, paying the token cost only when needed.

Option C: Compact mode flag

Add a config option to use minimal descriptions:

{
  "task_tool_mode": "compact"
}

Compact mode would list only agent names without descriptions, or use a much shorter format.

Option D: Hierarchical/categorized listing

Group subagents by category with collapsed descriptions:

Available agent categories: browser (5), git (4), code-review (6), seo (7)...
Use task(category="browser") to see browser agents, or task(agent="explore") directly.

Related Issues

Environment

  • OpenCode version: 1.x
  • Subagents configured: 150+
  • Framework: aidevops (generates many specialized subagents)

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions