Skip to content

feat(compaction): opt-in LLM semantic compaction summarizer (M3.2c / §1)#22

Merged
wusijian007 merged 1 commit into
mainfrom
feat/m3.2c-llm-summarizer
Jun 17, 2026
Merged

feat(compaction): opt-in LLM semantic compaction summarizer (M3.2c / §1)#22
wusijian007 merged 1 commit into
mainfrom
feat/m3.2c-llm-summarizer

Conversation

@wusijian007

Copy link
Copy Markdown
Owner

Add the long-designed semantic-compaction seam. Where the default compactMessagesTiered shrinks stale messages in place (deterministic, pointer- izing the whales), the new compactMessagesWithSummary REPLACES the whole stale region with a single LLM-written recap — recovering the reasoning/prose that pointers cannot. Root task + recent window stay verbatim.

Boundary safety: the recent-window start snaps earlier past any leading tool_result so a kept tool_result never has its originating tool_use dropped (no orphaned pairing). When there is no accumulated stale history yet (e.g. one big recent tool_result), it returns untouched and leaves the pathological case to the reactive prompt_too_long net — semantic compaction condenses HISTORY, not the recent window.

Opt-in and non-breaking: the deterministic pointer path stays the default. The proactive-compaction block branches on QueryOptions.compactionSummarizer and marks the reset as proactive_compaction_semantic. It is one amortized cache reset like any compaction (invariant #1); non-determinism is gated behind a scripted fake in tests (invariant #2).

  • core: compactMessagesWithSummary + MessageSummarizer (context.ts), QueryOptions.compactionSummarizer, createModelCompactionSummarizer (model- backed summarizer kept in core next to the loop).
  • cli: myagent agent --semantic-compaction (builds the summarizer from the agent's own client), help/usage text.
  • eval: EvalTask.initialMessages + new semantic-compaction task (seeds a stale whale, asserts the summarizer seam fires + tokens drop); fingerprint updated to tasks=10 turns=21 in=14350 out=835.
  • tests: 3 unit (recap replacement, boundary snap, under-target no-op) + 1 loop integration (proactive path uses the injected summarizer).
  • docs: CLAUDE.md query-loop step 7 + roadmap M3.2c marked delivered.

214 tests pass (+4).

Add the long-designed semantic-compaction seam. Where the default
compactMessagesTiered shrinks stale messages in place (deterministic, pointer-
izing the whales), the new compactMessagesWithSummary REPLACES the whole stale
region with a single LLM-written recap — recovering the reasoning/prose that
pointers cannot. Root task + recent window stay verbatim.

Boundary safety: the recent-window start snaps earlier past any leading
tool_result so a kept tool_result never has its originating tool_use dropped
(no orphaned pairing). When there is no accumulated stale history yet (e.g. one
big recent tool_result), it returns untouched and leaves the pathological case
to the reactive prompt_too_long net — semantic compaction condenses HISTORY,
not the recent window.

Opt-in and non-breaking: the deterministic pointer path stays the default. The
proactive-compaction block branches on QueryOptions.compactionSummarizer and
marks the reset as proactive_compaction_semantic. It is one amortized cache
reset like any compaction (invariant #1); non-determinism is gated behind a
scripted fake in tests (invariant #2).

- core: compactMessagesWithSummary + MessageSummarizer (context.ts),
  QueryOptions.compactionSummarizer, createModelCompactionSummarizer (model-
  backed summarizer kept in core next to the loop).
- cli: myagent agent --semantic-compaction (builds the summarizer from the
  agent's own client), help/usage text.
- eval: EvalTask.initialMessages + new semantic-compaction task (seeds a stale
  whale, asserts the summarizer seam fires + tokens drop); fingerprint updated
  to tasks=10 turns=21 in=14350 out=835.
- tests: 3 unit (recap replacement, boundary snap, under-target no-op) + 1 loop
  integration (proactive path uses the injected summarizer).
- docs: CLAUDE.md query-loop step 7 + roadmap M3.2c marked delivered.

214 tests pass (+4).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wusijian007 wusijian007 merged commit 3307bc6 into main Jun 17, 2026
3 checks passed
@wusijian007 wusijian007 deleted the feat/m3.2c-llm-summarizer branch June 17, 2026 01:23
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.

1 participant