Repository navigation
[EPIC-W][LOU-W3.2] compaction.start/compaction.done stream events and createAgent({ compaction }) - #102
Merged
Conversation
… createAgent({ compaction })
The compaction hook now emits typed compaction.start / compaction.done
events into streamed runs (via a new optional GenerateHookContext.emit),
and createAgent() takes `compaction` (true or an options object, where
`summarizer` selects twoPhaseStrategy) and `hooks`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bY29ibQgv3MDdjAbUT4YR
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.
What
compaction.start(strategy,tokensBefore,contextWindow,thresholdTokens) andcompaction.done(strategy,tokensBefore,tokensAfter,prunedToolCallIds,summary?: boolean,error?: { message }), emitted intoagent.stream()/session.stream()/AgentExecutor.stream()inside the step, before the model call that triggered them. Every start has exactly one done;erroris set when the strategy fails and the hook falls back.GenerateHookContext.emit(event)(set only in streamed runs), backed by a newhookEventon the internalRunEventSink; sub-agent events are tagged withsubagent.createAgent({ compaction }):trueinstalls the prune hook with defaults; an object takesstrategy,thresholdPercent,contextWindow,protectedTokensandsummarizer('provider/model'orLLMProvider, which selectstwoPhaseStrategy).summarizertogether withstrategyis aConfigurationError.createAgent({ hooks })(was missing): anyAgentHook[], run in order before the compaction hook; also used when resuming after approval.Why
Finishes compaction parity (LOU-W2/W3): the hook existed but could only be observed through
onCompactionand could not be configured oncreateAgent(). Additive: event schema stays v1.Acceptance criteria
compaction.start/compaction.doneemitted whenever the hook compacts, includingcompaction.donewitherroron strategy failure/fallbackcreateAgent({ compaction?: boolean | {...} }), withsummarizerselectingtwoPhaseStrategycreateAgent({ hooks })addedmockModel: event order around the triggering model call,compaction: truecompacts a long transcript,summarizerprovider is used (instance and'provider/model'), failing strategy and failing summarizer, sub-agent tagging,hooksforwarding andctx.emitHow verified
npx tsc --noEmit: passnpm run lint: 0 errors (404 warnings; none in the touched files)npm run test:types: 27 passed, no type errorsnpx vitest run: all pass afternpm run buildexceptcloudflare.test.ts"wrangler devserves the worker" (needs the wrangler CLI/workerd, fails in isolation too, unrelated) andguardrails.test.tschild-kill timeout (flaky under load; passes in isolation, 23/23)npm run build && npm run build --workspace=packages/create-loushy-agent: passnpm run docs:verify-snippets -- --skip-build: all 116 snippets type-check; 6 also runnpm run docs:llms:check: passvitest run --coverage --config vitest.coverage.config.ts --exclude src/deploy/adapters/cloudflare.test.ts: 153 files, 2221 passed, 3 skipped;npm run fallow: exit 0, no dead code (one pre-existing duplicate block in AnthropicProvider/OpenAIProvider)🤖 Generated with Claude Code
https://claude.ai/code/session_016bY29ibQgv3MDdjAbUT4YR
Generated by Claude Code