-
Notifications
You must be signed in to change notification settings - Fork 6k
feat(agent): add subagents config for per-agent task tool filtering #7271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat(agent): add subagents config for per-agent task tool filtering #7271
Conversation
Add 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. - Add 'subagents' field to Agent config schema (supports glob patterns) - Filter task tool description based on caller's subagents list - Add tests for the new filtering behavior - Update documentation with usage examples Closes anomalyco#7269
|
The following comment was made by an LLM, it may be inaccurate: Summary: One potentially related PR found:
This addresses similar concerns around managing which subagents are included in context. Review it to ensure there's no duplicate effort or conflicting approaches. |
|
Thanks for flagging #4119! After reviewing, these PRs address different problems:
#4119 optimizes the context sent to subagents when they're invoked. They're complementary - both reduce token usage but at different points:
With 150 subagents, the task tool description alone adds ~6-10k tokens to every conversation's system prompt. This PR allows agents to specify which subagents they need, reducing that overhead. |
|
To let you know any subagent that you list as denied in the task tool using the new permission system is already hidden from the task tool. The functionality that you are proposing already exists, just use the new permission system |
|
Thanks @malhashemi! I tested the However, I'd like to make the case that the allowlist approach is significantly more ergonomic for real-world usage at scale. Real-World NumbersOur setup (aidevops):
Config ComparisonDeny-list (current) - Accounts agent needing only "permission": {
"external_directory": "allow",
"task": {
"*": "deny",
"quickfile": "allow"
}
}Allowlist (proposed): "subagents": ["quickfile"]For Build+ needing ~20 subagents, the deny-list becomes: "task": {
"*": "deny",
"code-standards": "allow",
"code-simplifier": "allow",
"best-practices": "allow",
"git-workflow": "allow",
"branch": "allow",
"preflight": "allow",
"postflight": "allow",
"release": "allow",
"version-bump": "allow",
"conversation-starter": "allow",
"osgrep": "allow",
"augment-context-engine": "allow",
"context-builder": "allow",
"context7": "allow",
"toon": "allow",
"playwright": "allow",
"stagehand": "allow",
"github-cli": "allow",
"coolify": "allow"
}vs: "subagents": ["code-standards", "code-simplifier", "best-practices", "git-workflow", "branch", "preflight", "postflight", "release", "version-bump", "conversation-starter", "osgrep", "augment-context-engine", "context-builder", "context7", "toon", "playwright", "stagehand", "github-cli", "coolify"]Why Allowlist is Better
ProposalThe
Happy to revise the implementation if there's interest from maintainers. @rekram1-node @thdxr thoughts? |
Add 'subagents:' frontmatter to primary agents that specifies which subagents should appear in the Task tool description. This reduces token overhead by filtering 220 subagents down to 3-30 per agent. Changes: - Add parse_frontmatter() to generate-opencode-agents.sh - Generate permission.task deny-list rules from subagents list - Add subagents frontmatter to all 13 primary agents Token savings: ~6-10k tokens per conversation by hiding irrelevant subagents from the Task tool description. Related: anomalyco/opencode#7271
* feat(agents): add subagent filtering via frontmatter Add 'subagents:' frontmatter to primary agents that specifies which subagents should appear in the Task tool description. This reduces token overhead by filtering 220 subagents down to 3-30 per agent. Changes: - Add parse_frontmatter() to generate-opencode-agents.sh - Generate permission.task deny-list rules from subagents list - Add subagents frontmatter to all 13 primary agents Token savings: ~6-10k tokens per conversation by hiding irrelevant subagents from the Task tool description. Related: anomalyco/opencode#7271 * fix(parser): improve frontmatter parser robustness Address Gemini Code Assist review feedback: - Add encoding='utf-8' to file open - Skip comments and empty lines in YAML parsing - Use specific exception types instead of bare except - Add warning message for parse failures Co-authored-by: gemini-code-assist[bot] <176abortedflight+gemini-code-assist[bot]@users.noreply.github.com> * fix(health): remove context7 subagent context7 provides library/framework docs, not health information. crawl4ai is sufficient for health research workflows. Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176abortedflight+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary
Adds a new
subagentsconfiguration 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:
Solution
Add a
subagentsfield to agent config that filters which subagents appear in the Task tool description:{ "agent": { "build": { "subagents": ["explore", "general", "code-*"] } } }code-*,*-reviewer)permission.task(which controls runtime access)Changes
packages/opencode/src/config/config.ts- Addsubagentsfield to Agent schemapackages/opencode/src/agent/agent.ts- Addsubagentsto Agent.Info and statepackages/opencode/src/tool/task.ts- Filter agents based on caller's subagents configpackages/opencode/test/tool/task-subagents.test.ts- Tests for filtering logicpackages/web/src/content/docs/agents.mdx- DocumentationTesting
All 9 tests pass.