feat: session compaction#21
Merged
Merged
Conversation
Adds a heuristic token estimator (byte-length / 4) used by session compaction to detect when token usage approaches the context window limit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…action Add session compaction support: Compact() replaces old messages with a summary while keeping the most recent N messages. History() now prepends the active summary message when present, and Clear() resets all compaction state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add compact record type to the JSONL format so that compaction summary and version survive across Save/Load cycles. On rewrite, a "compact" record is emitted between the metadata line and the kept messages. On Load, encountering a compact record resets the message accumulator and restores summaryMsg/compactVersion on the session. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ContextBudget and ReserveTokens fields to SessionConfig for controlling the token-based compaction threshold. Add compaction prompt constants (preFlushPrompt, summaryPrompt, flushSkipSentinel) that will be used by the agent compaction orchestrator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…anagement Wire contextBudget/reserveTokens config into Agent struct, create the compaction pipeline (pre-flush, summarize, compact), and hook it into runLoop before appending the user message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
End-to-end tests covering the full session lifecycle: create, populate, compact, save, load, verify, append, save again, and verify persistence of summary and message counts across reloads. Also tests token estimation threshold detection for compaction triggering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.