Repository navigation
Add keepLastWithSummary compaction strategy (#100) - #108
Merged
Merged
Conversation
A context strategy that folds a caller-supplied rolling summary of older turns into each request (as a synthetic system message) instead of silently dropping them — compaction that preserves load-bearing context rather than causing 'context rot'. The app owns producing and persisting the summary (any model or heuristic, saved via ChatStore); this strategy injects it after real system messages and windows the recent messages, skipping orphaned leading tool results. No memory service is baked in, matching the roadmap's 'apps supply retrieval' stance. Pure, synchronous, composes with trimHistory. Closes #100 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #100.
What
A new context strategy,
keepLastWithSummary({summary, count}), forUseChatController.trimHistory. Instead of silently dropping older turns (the "context rot" the research flagged), it folds a caller-supplied rolling summary of the trimmed span into the request as a syntheticsystemmessage — right after any real system messages — then windows the most recentcountmessages.Why this shape (not an LLM baked in)
The
trimHistoryseam is synchronous and pure; real summarization is async. Per the roadmap ("let apps/MCP supply retrieval — do not build a memory service"), the app owns producing and persisting the summary (any model or heuristic, saved viaChatStore), and returns it fromsummary(). This package supplies the compaction/windowing mechanism, giving durable cross-session memory without owning a memory service.Details
toolresults (like the existing strategies).Verification
flutter test packages/flutter_ai_client— 45 pass, incl. 4 newkeepLastWithSummarytestsflutter analyzeclean ·dart formatclean repo-wideVersion
flutter_ai_client0.2.4 (additive; no core constraint change)🤖 Generated with Claude Code