feat: compact history #922
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces automatic context compaction to the agent system, allowing conversations to be summarized and condensed when they exceed token limits. This helps keep the conversation within model context constraints and improves long-running interaction reliability. The changes add a new
Compactorutility, integrate it into the agent lifecycle, and update event handling to support compacted context summaries.Agent context compaction integration
Compactorinstance and token usage tracking (total_usage_tokens) to theAgentstruct, enabling monitoring and management of context length.run_auto_compactandget_compact_summarymethods inAgent, which trigger compaction, summarize conversation history via LLM, reset token counters, and emit a newContextCompactedevent.Agent::start), automatically summarizing when token thresholds are exceeded and the conversation continues.Compactorwith configuration based on model token limits during agent initialization.Compactor utility and summarization prompts
internal/compact/compact.mbtmodule, which provides theCompactorstruct, compaction threshold logic, and summarization prompt construction.internal/compact/prompts.mbtfor consistent LLM handoff and context continuity.Event handling and serialization
ContextCompacted(summary : String)variant to theEventDescenum, including serialization and deserialization support for compacted context summaries. [1] [2] [3]Testing
internal/compact/compact_test.mbt.