Expand description
Provider-agnostic context compaction primitives for agent transcripts.
The crate owns the deterministic parts of compaction: checkpoint threshold checks, transcript rendering budgets, recent user-message retention, summary handoff finalization, and policy for append-only episodic histories. Callers own provider I/O, persistence, cancellation, telemetry, and conversion back into their typed message model.
Structs§
- Char
Heuristic - Fast four-characters-per-token heuristic.
- Compacted
Transcript - Final model-visible compaction output.
- Compaction
Config - Configuration for compaction planning.
- Compaction
Plan - Deterministic data needed to install a model-produced summary.
- Compaction
Request - Prompt to send to the caller’s summarization model.
- Episodic
Compaction Config - Default policy for long-lived, append-only conversation histories.
- Episodic
Compaction Pressure - Storage-neutral observations for one append-only conversation episode.
- Plain
Tool Call - Tool-call rendering helper for
PlainMessage. - Prepared
Compaction - Caller-owned model request and deterministic replacement plan.
Enums§
- Episodic
Compaction Trigger - Durable reason an episodic boundary was written.
- Plain
Message - Simple test/example transcript shape.
Constants§
- DEFAULT_
AUTO_ COMPACT_ TOKEN_ LIMIT - Default estimated-token threshold for automatic compaction.
- DEFAULT_
COMPACTION_ PROMPT - Default prompt for the caller-owned summarization model request.
- DEFAULT_
COMPACT_ REQUEST_ TOKEN_ LIMIT - Default source budget for the compaction request itself.
- DEFAULT_
PRIVATE_ REASONING_ EXCERPT_ CHARS - Default character cap for one private-reasoning excerpt.
- DEFAULT_
PRIVATE_ REASONING_ SUMMARY_ GUIDANCE - The behavior the default prompt requires for private reasoning excerpts. Exported so callers with a custom prompt can preserve the same contract.
- DEFAULT_
RECENT_ USER_ TOKEN_ BUDGET - Default budget for recent real user messages retained after compaction.
- DEFAULT_
SUMMARY_ PREFIX - Default runtime-context marker for model-visible compaction handoffs.
Traits§
- Token
Estimator - Approximate token estimator used by compaction budgets.
- Transcript
Message - Runtime-owned transcript adapter.
Functions§
- append_
private_ reasoning_ for_ compaction - Append one bounded private-reasoning excerpt to a compaction transcript.
- episodic_
compaction_ trigger - Select the highest-priority automatic episodic-compaction trigger.
- estimate_
transcript_ tokens - Estimate the rendered transcript token count.
- finalize_
compaction - Combine a model-produced summary with a previously prepared plan.
- prepare_
compaction - Build a compaction prompt plus deterministic finalization plan.
- should_
compact - Return true when compaction should run for this transcript.
- truncate_
to_ token_ budget - Truncate text by the default character heuristic while preserving the tail.
- truncate_
to_ token_ budget_ with_ estimator - Truncate text according to
estimator.max_chars_for_tokens, preserving the tail. - with_
private_ reasoning_ summary_ guidance - Add the private-reasoning handoff contract to a caller-supplied prompt.