Skip to content

Conversation Memory & Compaction

In AGBoss, a conversation thread is a sequence of completed workflow executions (turns). Agents and model-backed routers see a bounded window of recent finished turns (uncompactedTurns) plus compacted summaries of older turns generated by a @Compaction component, keeping context windows bounded and predictable without losing long-range facts.

How turn windows (uncompactedTurns) and @Compaction strategies work

Section titled “How turn windows (uncompactedTurns) and @Compaction strategies work”

Only finished executions enter thread memory (each formatted as start <start-name>: <input JSON> and finish <finish-name>: <output JSON>; paused or failed executions and intermediate step outputs never pollute thread history).

In v2, compaction is declared as a dedicated @Compaction class with one of four strategies (CompactionStrategy.SummaryQueue, CompactionStrategy.SingleSummary, CompactionStrategy.Custom, or CompactionStrategy.None) and bound via compaction and uncompactedTurns on @Application, @Workflow, @Agent, or @Router (the most specific level wins). A compaction summarizes every turn older than the smallest uncompactedTurns among the agents and routers that share it, so no reader ever loses a turn:

Memory and @Compaction configuration options

Section titled “Memory and @Compaction configuration options”
Option Where Configured Purpose
uncompactedTurns @Application, @Workflow, @Agent, @Router Number of recent finished turns shown in full (0 or higher, or TurnLimit.ALL; default 5). Most specific level wins.
compaction @Application, @Workflow, @Agent, @Router @Compaction class governing how turns older than uncompactedTurns are summarized. Most specific level wins.
CompactionStrategy.SummaryQueue @Compaction({ strategy }) Writes a new self-contained summary every turnsBetweenCompactions turns and retains the latest summaryQueueLength summaries in FIFO order.
CompactionStrategy.SingleSummary @Compaction({ strategy }) Maintains a single rolling summary rewritten from the previous summary plus the newly aged-out turns every turnsBetweenCompactions turns.
CompactionStrategy.Custom @Compaction({ strategy }) Delegates summarization to compact(input: CompactionInput) on your CompactionHandler class with full DI (deps: [...]) and automatic PII masking/unmasking.
CompactionStrategy.None @Compaction({ strategy }) Disables summarization (model and turnsBetweenCompactions are omitted); readers see only the uncompactedTurns window.
summaryMaxTokens @Compaction Maximum tokens for each summary generation call (number or TokenLimit.MODEL_MAX). If a summary is truncated at the limit, AGBoss retries once asking for a shorter summary before throwing CompactionError.