Skip to content

Add keepLastWithSummary compaction strategy (#100) - #108

Merged
ananmouaz merged 1 commit into
mainfrom
feat/summary-compaction-100
Jul 1, 2026
Merged

ananmouaz merged 1 commit into
mainfrom
feat/summary-compaction-100

Conversation

@ananmouaz

Copy link
Copy Markdown
Owner

Closes #100.

What

A new context strategy, keepLastWithSummary({summary, count}), for UseChatController.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 synthetic system message — right after any real system messages — then windows the most recent count messages.

Why this shape (not an LLM baked in)

The trimHistory seam 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 via ChatStore), and returns it from summary(). This package supplies the compaction/windowing mechanism, giving durable cross-session memory without owning a memory service.

Details

  • Injects nothing when nothing was dropped or the summary is empty.
  • Skips leading orphaned tool results (like the existing strategies).
  • Never mutates the stored transcript — only what each request sends.

Verification

  • flutter test packages/flutter_ai_client — 45 pass, incl. 4 new keepLastWithSummary tests
  • flutter analyze clean · dart format clean repo-wide

Version

flutter_ai_client 0.2.4 (additive; no core constraint change)

🤖 Generated with Claude Code

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>
@ananmouaz
ananmouaz merged commit 5fb81c7 into main Jul 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Durable cross-session memory + controllable summarization/compaction

1 participant