Skip to main content

Crate clark_agent_compaction

Crate clark_agent_compaction 

Source
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§

CharHeuristic
Fast four-characters-per-token heuristic.
CompactedTranscript
Final model-visible compaction output.
CompactionConfig
Configuration for compaction planning.
CompactionPlan
Deterministic data needed to install a model-produced summary.
CompactionRequest
Prompt to send to the caller’s summarization model.
EpisodicCompactionConfig
Default policy for long-lived, append-only conversation histories.
EpisodicCompactionPressure
Storage-neutral observations for one append-only conversation episode.
PlainToolCall
Tool-call rendering helper for PlainMessage.
PreparedCompaction
Caller-owned model request and deterministic replacement plan.

Enums§

EpisodicCompactionTrigger
Durable reason an episodic boundary was written.
PlainMessage
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§

TokenEstimator
Approximate token estimator used by compaction budgets.
TranscriptMessage
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.