Skip to content

[EPIC-W][LOU-W3.2] compaction.start/compaction.done stream events and createAgent({ compaction }) - #102

Merged
LinuxDevil merged 2 commits into
mainfrom
lou-w3-2-compaction-events-option
Oct 1, 2026
Merged

LinuxDevil merged 2 commits into
mainfrom
lou-w3-2-compaction-events-option

Conversation

@LinuxDevil

Copy link
Copy Markdown
Owner

What

  • Two new typed stream events, compaction.start (strategy, tokensBefore, contextWindow, thresholdTokens) and compaction.done (strategy, tokensBefore, tokensAfter, prunedToolCallIds, summary?: boolean, error?: { message }), emitted into agent.stream() / session.stream() / AgentExecutor.stream() inside the step, before the model call that triggered them. Every start has exactly one done; error is set when the strategy fails and the hook falls back.
  • Minimal emit plumbing: optional GenerateHookContext.emit(event) (set only in streamed runs), backed by a new hookEvent on the internal RunEventSink; sub-agent events are tagged with subagent.
  • createAgent({ compaction }): true installs the prune hook with defaults; an object takes strategy, thresholdPercent, contextWindow, protectedTokens and summarizer ('provider/model' or LLMProvider, which selects twoPhaseStrategy). summarizer together with strategy is a ConfigurationError.
  • createAgent({ hooks }) (was missing): any AgentHook[], 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 onCompaction and could not be configured on createAgent(). Additive: event schema stays v1.

Acceptance criteria

  • compaction.start / compaction.done emitted whenever the hook compacts, including compaction.done with error on strategy failure/fallback
  • createAgent({ compaction?: boolean | {...} }), with summarizer selecting twoPhaseStrategy
  • createAgent({ hooks }) added
  • Tests with mockModel: event order around the triggering model call, compaction: true compacts a long transcript, summarizer provider is used (instance and 'provider/model'), failing strategy and failing summarizer, sub-agent tagging, hooks forwarding and ctx.emit
  • Docs: docs/compaction.md, docs/streaming.md, docs/configuration.md (+ api-overview note); llms-full.txt regenerated; CHANGELOG (Added)

How verified

  • npx tsc --noEmit: pass
  • npm run lint: 0 errors (404 warnings; none in the touched files)
  • npm run test:types: 27 passed, no type errors
  • npx vitest run: all pass after npm run build except cloudflare.test.ts "wrangler dev serves the worker" (needs the wrangler CLI/workerd, fails in isolation too, unrelated) and guardrails.test.ts child-kill timeout (flaky under load; passes in isolation, 23/23)
  • npm run build && npm run build --workspace=packages/create-loushy-agent: pass
  • npm run docs:verify-snippets -- --skip-build: all 116 snippets type-check; 6 also run
  • npm run docs:llms:check: pass
  • vitest 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

claude added 2 commits October 1, 2026 16:18
… 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
@LinuxDevil
LinuxDevil merged commit 9aefce6 into main Oct 1, 2026
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.

2 participants