[FEATURE]: Agent-driven Selective Context Management via Block IDs #8794

Open
opened 2026-02-16 18:10:52 -05:00 by yindo · 1 comment
Owner

Originally created by @Hubedge on GitHub (Feb 7, 2026).

Originally assigned to: @thdxr on GitHub.

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

Describe the enhancement you want to request

Disclaimer

I am a user of Opencode and do not have a background in TypeScript or the project's internal codebase. I am proposing this as a functional enhancement rather than a technical implementation plan.

1. The Problem

Currently, Opencode manages long conversations using automatic cleanup (pruning and compaction). While this is helpful for staying within token limits, it is a "system-level" decision that doesn't always align with the actual progress of the task.

For example, the system might automatically delete an important piece of code I read earlier that the agent still needs, or it might keep thousands of tokens of useless error logs that have already been resolved, simply because they are "recent."

2. The Proposed Idea: Agent-driven Context Management

I suggest giving the AI agent the ability to actively manage its own memory using a block-based system:

  • Visible Block IDs: Every significant part of the conversation (a user message, a large tool output, a reasoning block) should be assigned a unique ID that the agent can see.
  • Agent Control: Allow the agent to issue commands to manage these blocks. For instance:
    • Discard: The agent can decide that a specific block (like a long, failed build log) is no longer useful and should be removed from its context.
    • Summarize: The agent can choose to replace a massive block of data with a short summary it generates itself.
    • Pin: The agent can mark a specific block as "critical" so that the automatic cleanup system never deletes it.

3. Integration with Session Reversion (Rollback)

Opencode already has a powerful "Revert" feature. It is critical that this new memory management system is integrated with it:

  • Consistent Rollback: If a user reverts the session to a previous message, any "Discard" or "Summarize" actions taken by the agent after that point should also be automatically undone.
  • Memory Sync: The agent's memory (the state of which blocks are hidden or summarized) must stay perfectly in sync with the conversation history. If we go back in time, the agent should "regain" the full context that was available at that moment.

4. Benefits

  • Smarter Context: The agent knows better than the system which information is truly "finished" and which is "ongoing."
  • Efficiency: By proactively cleaning up resolved issues, the agent can keep the conversation focused and high-quality for much longer.
  • Reliability: Ensuring that memory management respects rollbacks will prevent the agent from being "confused" by missing information that it previously discarded in a future that no longer exists.

Similar Issues

https://github.com/anomalyco/opencode/issues/7459
https://github.com/anomalyco/opencode/issues/9896
https://github.com/anomalyco/opencode/issues/8932

Originally created by @Hubedge on GitHub (Feb 7, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request **Describe the enhancement you want to request** ### **Disclaimer** I am a user of Opencode and do not have a background in TypeScript or the project's internal codebase. I am proposing this as a functional enhancement rather than a technical implementation plan. # **1. The Problem** Currently, Opencode manages long conversations using automatic cleanup (pruning and compaction). While this is helpful for staying within token limits, it is a "system-level" decision that doesn't always align with the actual progress of the task. For example, the system might automatically delete an important piece of code I read earlier that the agent still needs, or it might keep thousands of tokens of useless error logs that have already been resolved, simply because they are "recent." # **2. The Proposed Idea: Agent-driven Context Management** I suggest giving the AI agent the ability to **actively manage its own memory** using a block-based system: - **Visible Block IDs**: Every significant part of the conversation (a user message, a large tool output, a reasoning block) should be assigned a unique ID that the agent can see. - **Agent Control**: Allow the agent to issue commands to manage these blocks. For instance: - **Discard**: The agent can decide that a specific block (like a long, failed build log) is no longer useful and should be removed from its context. - **Summarize**: The agent can choose to replace a massive block of data with a short summary it generates itself. - **Pin**: The agent can mark a specific block as "critical" so that the automatic cleanup system never deletes it. # **3. Integration with Session Reversion (Rollback)** Opencode already has a powerful "Revert" feature. It is critical that this new memory management system is integrated with it: - **Consistent Rollback**: If a user reverts the session to a previous message, any "Discard" or "Summarize" actions taken by the agent *after* that point should also be automatically undone. - **Memory Sync**: The agent's memory (the state of which blocks are hidden or summarized) must stay perfectly in sync with the conversation history. If we go back in time, the agent should "regain" the full context that was available at that moment. # **4. Benefits** - **Smarter Context**: The agent knows better than the system which information is truly "finished" and which is "ongoing." - **Efficiency**: By proactively cleaning up resolved issues, the agent can keep the conversation focused and high-quality for much longer. - **Reliability**: Ensuring that memory management respects rollbacks will prevent the agent from being "confused" by missing information that it previously discarded in a future that no longer exists. # Similar Issues https://github.com/anomalyco/opencode/issues/7459 https://github.com/anomalyco/opencode/issues/9896 https://github.com/anomalyco/opencode/issues/8932
yindo added the discussion label 2026-02-16 18:10:52 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 7, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #7459: [FEATURE]: implement smart pruning - Proposes a smarter pruning mechanism that keeps important information instead of just removing the latest operations
  • #9896: [FEATURE]: "Compact above" - Partial Compaction - Suggests user-driven compaction of messages, allowing users to mark which parts of conversation should be compacted
  • #8932: [FEATURE]: Allow pinning important instructions/messages per session to keep them after compaction - Proposes pinning messages to preserve them after compaction

Your proposal for agent-driven context management with block IDs, discard, summarize, and pin operations builds upon these related feature requests. Feel free to ignore if your specific case requires additional functionality beyond these existing proposals.

@github-actions[bot] commented on GitHub (Feb 7, 2026): This issue might be a duplicate of existing issues. Please check: - #7459: [FEATURE]: implement smart pruning - Proposes a smarter pruning mechanism that keeps important information instead of just removing the latest operations - #9896: [FEATURE]: "Compact above" - Partial Compaction - Suggests user-driven compaction of messages, allowing users to mark which parts of conversation should be compacted - #8932: [FEATURE]: Allow pinning important instructions/messages per session to keep them after compaction - Proposes pinning messages to preserve them after compaction Your proposal for agent-driven context management with block IDs, discard, summarize, and pin operations builds upon these related feature requests. Feel free to ignore if your specific case requires additional functionality beyond these existing proposals.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8794