Feature: Subagents should support auto compaction #2088

Open
opened 2026-02-16 17:34:06 -05:00 by yindo · 4 comments
Owner

Originally created by @ghost on GitHub (Oct 13, 2025).

Originally assigned to: @thdxr on GitHub.

Currently, if a subagent goes on a long task and goes over the models context limit, the whole subagent fails.

I think a good solution for this might be auto compaction for sub-agents. If a subagent goes over its context it should reject/remove items that are too big (the last tool/mcp call that sent it over context rejected?) and then auto compact in a way that allows it to continue. This makes subagents resilient and recoverable, because when they go on long tasks and fail it can cost a lot of tokens.

Appreciate all the hard work, opencode is great.

Originally created by @ghost on GitHub (Oct 13, 2025). Originally assigned to: @thdxr on GitHub. Currently, if a subagent goes on a long task and goes over the models context limit, the whole subagent fails. I think a good solution for this might be auto compaction for sub-agents. If a subagent goes over its context it should reject/remove items that are too big (the last tool/mcp call that sent it over context rejected?) and then auto compact in a way that allows it to continue. This makes subagents resilient and recoverable, because when they go on long tasks and fail it can cost a lot of tokens. Appreciate all the hard work, opencode is great.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 13, 2025):

This issue might be a duplicate or closely related to existing issues. Please check:

  • #2906: Limit Subagent Tree Depth - discusses limiting subagent depth due to context management issues
  • #3032: Soft compaction / AI global workspace metabolism - proposes soft compaction to preserve context while managing tool calls
  • #2588: Feature request: let subagents inherit context - discusses context management for subagents
  • #3031: Model in BUILD mode does not have enough context to continue after compaction - addresses insufficient context after compaction

While your specific request for auto compaction in subagents is unique, these existing issues address related problems with subagent context management and compaction strategies. You might find useful insights or discussions there.

Feel free to ignore if none of these address your specific case of automatic compaction for subagents hitting context limits.

@github-actions[bot] commented on GitHub (Oct 13, 2025): This issue might be a duplicate or closely related to existing issues. Please check: - #2906: Limit Subagent Tree Depth - discusses limiting subagent depth due to context management issues - #3032: Soft compaction / AI global workspace metabolism - proposes soft compaction to preserve context while managing tool calls - #2588: Feature request: let subagents inherit context - discusses context management for subagents - #3031: Model in BUILD mode does not have enough context to continue after compaction - addresses insufficient context after compaction While your specific request for auto compaction in subagents is unique, these existing issues address related problems with subagent context management and compaction strategies. You might find useful insights or discussions there. Feel free to ignore if none of these address your specific case of automatic compaction for subagents hitting context limits.
Author
Owner

@rekram1-node commented on GitHub (Oct 13, 2025):

hmm I thought it would auto compact already will need to check

The auto compact logic isn't fool proof though

@rekram1-node commented on GitHub (Oct 13, 2025): hmm I thought it would auto compact already will need to check The auto compact logic isn't fool proof though
Author
Owner

@ghost commented on GitHub (Oct 13, 2025):

good test is use say a sequential thinking, and a web search & retrieval mcp, and give it a really hard problem (essentially a deep research subagent)

it's a crapshoot, but sometimes it will pull in something too big for the context window, the subagent will go red in the ui, and i get a token error in the top right corner if i'm actively viewing that subagent in the ui.

i guess it can't auto compact because the last thing it pulled in has taken it over the context limit for the model anyway, so it can't submit that for compaction, but that's a guess, just trying to give a reproduction route

ty for getting back to me

@ghost commented on GitHub (Oct 13, 2025): good test is use say a sequential thinking, and a web search & retrieval mcp, and give it a really hard problem (essentially a deep research subagent) it's a crapshoot, but sometimes it will pull in something too big for the context window, the subagent will go red in the ui, and i get a token error in the top right corner if i'm actively viewing that subagent in the ui. i guess it can't auto compact because the last thing it pulled in has taken it over the context limit for the model anyway, so it can't submit that for compaction, but that's a guess, just trying to give a reproduction route ty for getting back to me
Author
Owner

@rekram1-node commented on GitHub (Oct 13, 2025):

ofc and if you ever catch me not replying just @ me haha

yeah that very well could be it, tool overloads context and it cant recover ftom it

@rekram1-node commented on GitHub (Oct 13, 2025): ofc and if you ever catch me not replying just @ me haha yeah that very well could be it, tool overloads context and it cant recover ftom it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2088