@tanstack/ai-compaction#
0.3.1#
Patch Changes#
- Updated dependencies [
824ee98]:- @tanstack/ai@0.71.0
0.3.0#
Minor Changes#
#1728
3292bad- Prepare a compaction summary in the background withwithCompaction({ background: { atTokens } }).- When the count at a model call is over
atTokensand not overmaxTokens, the strategy runs on a copy of the messages. The model call does not wait for it. - The result waits in the metadata store (namespace
@tanstack/ai-compaction:background), or in memory without one. It applies at the first model call of the next run: as atanstack.compactionrecord on a durable host, or as the checkpoint. - A model call over
maxTokenswhile the summary runs waits for it and applies it. It compacts inline only when the list is still overmaxTokens. - A result whose kept message is gone, because a newer compaction cut further, is dropped.
compaction:endedandonCompactreport it withstale: true. A failed summary is reported witherrorand applies nothing. CompactionReasonhas a new value,'background'. Setup throws whenatTokensis not belowmaxTokens.
- When the count at a model call is over
#1728
3292bad- Count with real usage, compact on demand, and keep compaction in a session log.countTokens: 'usage'counts with the usage the provider reported for the last call, plus an estimate of the newer messages.- When a model call fails with
CONTEXT_OVERFLOW_CODE,withCompactioncompacts and calls the model again in the same run, once per model call. compactNext(threadId)compacts at the next model call.auto: falseturns off compaction atmaxTokensand keepscompactNext, the overflow retry, and the overflow check.durable: truewrites atanstack.compactionrecord throughLogRecordsCapabilitywhen the host provides it. Fold the record into the messages withprojectCompaction.- With
countTokens: 'usage'anddurable: true, a run checks once more after its last model call. When the usage passedmaxTokensorcontextWindow, compaction runs right away.contextWindowalso counts withauto: false. compaction:endedandonCompactreportreason, the summaryusage, and anerror.continueOnErrorsends the full messages when the strategy fails.summarizeOldest({ cut: 'turn' })gives the start of a cut turn its own summary.conversationSummarizerwrites a structured summary, updates the older summary, and takes adetailshook. The summary message is now wrapped in an<untrusted-conversation-summary>tag, so a later compaction can find and update it.
Patch Changes#
#1787
ee374b4- A failed nativecompactis not saved as the checkpoint or the durable compaction record. The next process callscompactagain. A compact result keeps image files, documents, and audio, and sends those parts back on the next request.Updated dependencies [
1d0f8f1,1d0f8f1,5f95dbd,3170517,3292bad,3170517,4298480,f68da51,30fa651,1d0f8f1,3170517,3170517]:- @tanstack/ai@0.70.0
0.2.0#
Minor Changes#
#1729
51f72fb- A text adapter can now have an optionalcompact(options)method. It sends the history to the provider's own compaction endpoint, and resolves to the history for the next calls. The options areTextCompactOptions:messages,model,signal,wrapFetch, andsystemPrompts.The OpenAI Responses adapters implement
compactwithPOST /responses/compact. The request sends the system prompts asinstructions. It sends no tools, because the endpoint does not take them. The encryptedcompactionitem goes back to the same model as it is on later requests. A compact result with no compaction item throws.withCompactionhas a newnativeoption. Pass the adapter of thechat()call. When the adapter hascompact, it runs in place ofstrategy. Whencompactfails,strategyruns, andonCompactandcompaction:endedget the failure inerror. After a 404, 405, or 501, that adapter and model use the strategy for the rest of the process. After any other failure, the next compaction triescompactagain. Without the option, nothing changes.
Patch Changes#
- Updated dependencies [
1bfcee3,412b0fe,a0150c2,b881627,fac0555,6774e80,5bd27f2,c20f7b0,cef1911,51f72fb,6f1e559,cef1911,7532b2b,1bfcee3,78edeb2,44e3a0a,7532b2b,7a5c0d6,b881627]:- @tanstack/ai@0.69.0
0.1.17#
Patch Changes#
0.1.16#
Patch Changes#
0.1.15#
Patch Changes#
#1671
2ee30cf-summarizeOldestnow fails the compaction when the summarizer returns an empty or whitespace-only summary. Before, it replaced the old messages with an empty summary and saved that result in the checkpoint, so the history was lost. Now the strategy throws an error, the history stays, and no checkpoint is written.Updated dependencies [
baafb17]:- @tanstack/ai@0.66.1
0.1.14#
Patch Changes#
0.1.13#
Patch Changes#
- Updated dependencies [
7b6b1a9,592c72c,592c72c,592c72c,592c72c,82291b2,ff3a66e,560c76f,4b9dcb4,30254ad,40fdd22]:- @tanstack/ai@0.65.0
0.1.12#
Patch Changes#
0.1.11#
Patch Changes#
- Updated dependencies [
37b2826,8e8ee26,c5c1996,3e30cde,0eb8f0b,f44b6b2,d632d41]:- @tanstack/ai@0.63.0
0.1.10#
Patch Changes#
- Updated dependencies [
a450d00,c54e20c,a56192e,740ae66,5099a32,820429f,0abae97,8c68c2d]:- @tanstack/ai@0.62.0
0.1.9#
Patch Changes#
0.1.8#
Patch Changes#
- Updated dependencies [
ef0a00f]:- @tanstack/ai@0.60.0
0.1.7#
Patch Changes#
0.1.6#
Patch Changes#
- Updated dependencies [
796f2b5]:- @tanstack/ai@0.58.0
0.1.5#
Patch Changes#
0.1.4#
Patch Changes#
0.1.3#
Patch Changes#
0.1.2#
Patch Changes#
0.1.1#
Patch Changes#
- Updated dependencies [
21775ee]:- @tanstack/ai@0.53.0
0.1.0#
Minor Changes#
#1235
e04ff6a- Add@tanstack/ai-compaction— context-window compaction as achat()middleware.withCompaction({ maxTokens, strategy })runs a pluggableCompactionStrategybefore each model call, so compaction is incremental and rolling. Three strategies ship built in:evictOldest(drop old messages, the default),summarizeOldest(replace them with an LLM summary), andclearToolResults(stub old tool output, keep the messages). Combine them withcomposeStrategies, which escalates through strategies until the transcript is back under budget. Strategies preserve tool-call/result pairing and never touch the system prompt.#1235
e04ff6a- Show compaction in TanStack AI DevTools.withCompactioninjectscompaction:started,compaction:state, andcompaction:endedCUSTOM stream events. State includes before/after counts, the token budget, and dropped vs sent message previews. The chat client re-emits the same three events. The AI panel has a Compaction tab and started/state/ended steps on the iteration.#1235
e04ff6a- Keep canonical chat history separate from compacted provider context. Reuse validated compaction checkpoints through an optional persistence metadata store.
Patch Changes#
- #1235
e04ff6a- Addctx.emitCustomEventon chat middleware context. The engine yieldsCUSTOMchunks while hooks such asonConfigare still running, so a long middleware step can send progress before it finishes. Compaction uses this to emitcompaction:startedbefore the strategy returns. - Updated dependencies [
49fc54c,e04ff6a,e04ff6a]:- @tanstack/ai@0.52.0