[PR #4119] Add context control for subagents #10869

Closed
opened 2026-02-16 18:15:37 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: No


Summary

  • Add granular context control for subagents to optimize performance with small local models
  • Enable 90-99% token reduction and 5-10× faster inference for lightweight models

Implementation

This PR introduces native context filtering for subagents, allowing fine-grained control over what parent session context is passed to subagents.

Key Features

Context Modes:

  • none (default) - No parent context, maintains current behavior
  • summary - Compact session summary (~100-500 tokens)
  • filtered - Selective inclusion by message type and tool results
  • full - All context with configurable limits

Configuration:

context:
  mode: filtered
  maxTokens: 2000
  includeToolResults: ["read", "edit"]
  includeMessageTypes: ["user"]

Performance Impact

Before: 45,000 tokens → 8 seconds (llama3.2:1b)
After: 200 tokens → 1 second (99% reduction, 8× faster)

Changes

  • New files:

    • packages/opencode/src/session/context-filter.ts - Core filtering logic (246 lines)
    • packages/opencode/src/session/context-filter.test.ts - Comprehensive tests (237 lines)
    • .opencode/agent/ - Example agent configurations
  • Modified files:

    • packages/opencode/src/config/config.ts - Context filter schema
    • packages/opencode/src/agent/agent.ts - Agent context support
    • packages/opencode/src/tool/task.ts - Apply filtering before subagent invocation
    • AGENTS.md - Documentation

Backward Compatibility

  • Fully backward compatible
  • Default mode is none (current behavior)
  • Optional feature, no breaking changes
  • All existing tests passing

Testing

cd packages/opencode
bun test src/session/context-filter.test.ts

Test Results: 11 tests passing, 32 assertions

Addresses https://github.com/sst/opencode/issues/4096

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4119 **State:** closed **Merged:** No --- ## Summary - Add granular context control for subagents to optimize performance with small local models - Enable 90-99% token reduction and 5-10× faster inference for lightweight models ## Implementation This PR introduces native context filtering for subagents, allowing fine-grained control over what parent session context is passed to subagents. ### Key Features **Context Modes:** - `none` (default) - No parent context, maintains current behavior - `summary` - Compact session summary (~100-500 tokens) - `filtered` - Selective inclusion by message type and tool results - `full` - All context with configurable limits **Configuration:** ```yaml context: mode: filtered maxTokens: 2000 includeToolResults: ["read", "edit"] includeMessageTypes: ["user"] ``` ### Performance Impact **Before:** 45,000 tokens → 8 seconds (llama3.2:1b) **After:** 200 tokens → 1 second (99% reduction, 8× faster) ### Changes - **New files:** - `packages/opencode/src/session/context-filter.ts` - Core filtering logic (246 lines) - `packages/opencode/src/session/context-filter.test.ts` - Comprehensive tests (237 lines) - `.opencode/agent/` - Example agent configurations - **Modified files:** - `packages/opencode/src/config/config.ts` - Context filter schema - `packages/opencode/src/agent/agent.ts` - Agent context support - `packages/opencode/src/tool/task.ts` - Apply filtering before subagent invocation - `AGENTS.md` - Documentation ### Backward Compatibility - ✅ Fully backward compatible - ✅ Default mode is `none` (current behavior) - ✅ Optional feature, no breaking changes - ✅ All existing tests passing ## Testing ```bash cd packages/opencode bun test src/session/context-filter.test.ts ``` **Test Results:** ✅ 11 tests passing, 32 assertions Addresses https://github.com/sst/opencode/issues/4096
yindo added the pull-request label 2026-02-16 18:15:37 -05:00
yindo closed this issue 2026-02-16 18:15:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10869