-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Feature Request: Context Control for Subagents
Problem
Subagents currently receive full repository context even for focused tasks, which:
- Increases token usage for small models (e.g., llama3.2:1b)
- Degrades performance for specialised, narrow-scope tasks
- Makes it difficult to optimise local models for specific use cases
- Wastes resources when only a minimal prompt is needed
Use Case
When using lightweight local models (1B-7B parameters) as subagents for focused tasks like:
- doc-reader: Extract key points from a single documentation file
- codegen: Generate a small code snippet
- log-analyser: Analyse a specific log file
- editor: Refine a single paragraph
These tasks require only the prompt and perhaps a single file reference, yet the subagent receives the entire repository context including:
- Full project structure
- Git history
- All configuration files
- Build scripts
- Documentation files
This is particularly problematic for resource-constrained local models where context window size directly impacts inference speed and quality.
Proposed Solution
Add a context configuration option in agent definitions to control what contextual information is passed to subagents:
{
"agent": {
"doc-reader": {
"mode": "subagent",
"model": "ollama/llama3.2:1b",
"context": {
"repo": false, // Disable full repository context
"files": "prompt-only", // Only include files mentioned in the prompt
"maxTokens": 2000, // Maximum context tokens to pass
"git": false, // Exclude git history
"config": false // Exclude configuration files
}
}
}
}Configuration Options
repo(boolean, default:true): Include full repository structurefiles(string, default:"all"): Control which files to include"all": All repository files"prompt-only": Only files explicitly mentioned in the prompt"none": No file context
maxTokens(number, optional): Hard limit on context tokensgit(boolean, default:true): Include git history and metadataconfig(boolean, default:true): Include configuration files
Alternative: Markdown Configuration
---
description: Reads documentation and summarises key insights
mode: subagent
model: ollama/llama3.2:1b
temperature: 0.1
context:
repo: false
files: prompt-only
maxTokens: 2000
---
Extract key points, APIs, and caveats from documentation.
Provide a short summary and a Q&A with likely follow-ups.Benefits
- Performance: Faster inference for small local models
- Cost: Reduced token usage for API-based models
- Quality: Less noise, more focused responses
- Flexibility: Different subagents can have different context requirements
- Resource optimisation: Better support for constrained environments
Real-World Example
Current configuration (16 subagents using llama3.2:1b):
{
"doc-reader": {
"mode": "subagent",
"model": "ollama/llama3.2:1b",
"prompt": "Extract key points, APIs, and caveats from documentation.\nProvide a short summary and a Q&A with likely follow-ups.",
"tools": {
"write": false,
"edit": false,
"bash": false
}
}
}When invoked with:
@doc-reader summarise the authentication section in README.md
Current behaviour: Receives entire repository context (potentially 50,000+ tokens)
Desired behaviour: Receives only the prompt + README.md content (~2,000 tokens)
This would make local small models significantly more practical for production use.
Compatibility
This would be a backwards-compatible addition:
- Default behaviour remains unchanged (full context)
- Existing agents continue to work without modification
- New
contextoption is entirely optional
Related Work
Similar context control exists in other AI systems:
- LangChain's
context_windowparameter - LlamaIndex's
chunk_sizeconfiguration - Anthropic's explicit context management in Claude
Would this feature align with OpenCode's roadmap? Happy to provide additional details or contribute to implementation if helpful.