adk_context_compaction (erlang_adk v0.7.0)

View Source

Bounded automatic context compaction with explicit checkpoints.

The module decides when compaction is needed, keeps recent context-selection units (including complete tool call/response exchanges), and executes the configured compactor in an owner-bound, heap-bounded process. Results and checkpoints are versioned JSON values suitable for persistence. This module does not persist anything itself.

Summary

Functions

Validate and compile immutable compaction configuration.

Evaluate triggers and, when selected, return a compacted history.

Types

policy/0

-type policy() :: map().

Functions

cancel_message(CancelRef)

-spec cancel_message(reference()) -> tuple().

capabilities()

-spec capabilities() -> map().

compile(Opts)

-spec compile(map()) -> {ok, policy()} | {error, term()}.

Validate and compile immutable compaction configuration.

At least one of token_threshold, event_threshold, or turn_interval must be enabled. A trigger is disabled with the atom disabled.

evaluate(Events, Stats, Policy)

-spec evaluate([adk_event:event() | map()], map(), policy()) ->
                  {ok, no_compaction, map()} | {ok, map()} | {error, term()}.

Evaluate triggers and, when selected, return a compacted history.

Stats accepts estimated_tokens (otherwise a deterministic byte estimate is used) and turns_since_compaction. Runtime accepts an absolute monotonic deadline_ms and a cancel_ref. Send the value returned by cancel_message/1 to the evaluating process to cancel explicit work.

version()

-spec version() -> pos_integer().