Skip to main content

Module algorithm

Module algorithm 

Source
Expand description

Custom compaction algorithm interface (issue #4).

compact() no longer hard-codes one strategy: it dispatches through CompactAlgorithm, which composes the three classic decision points — when to trigger, where to cut, and how to summarize.

  • BuiltinCompactAlgorithm is the shipped default: the 80%-window trigger heuristic, the turn-boundary-safe keep_recent_tokens cut, and LLM summarization (with the overflow-budget retry loop).
  • Custom algorithms implement the same trait. The TS path is host-wired: the CLI (theway-daemon::ts_extensions) discovers kind = "compaction" extensions, adapts them to CompactAlgorithm, and injects the registry via AgentHarnessOptions.compact_algorithms — the core never loads extensions itself.

The trait methods carry defaults that delegate to the same free functions the builtin uses, so a custom algorithm that overrides only select_cut_point still gets the builtin trigger + summarizer for free.

Structs§

BuiltinCompactAlgorithm
The shipped default algorithm. All hooks are the trait defaults (builtin behavior).
CompactAlgorithmRegistry
Resolves CompactionSettings.algorithm names to implementations. Holds the custom algorithms (host-injected, e.g. TS extensions); the builtin is always available as fallback.
SummarizeRequest
Everything an algorithm needs to produce a summary of the folded prefix.
SummaryOutcome
Result of a summarize hook (summarize_prefix). usage is meaningful for LLM-backed algorithms; custom (e.g. TS) algorithms return Usage::default().

Traits§

CompactAlgorithm
Custom compaction algorithm — the extension point behind issue #4.