Skip to main content

Module ctx_transcript_compact

Module ctx_transcript_compact 

Source
Expand description

ctx_transcript_compact business logic (#hermes-engine).

Deterministic, prompt-cache-friendly compaction of an OpenAI-format message array. Used by the Hermes context-engine plugin so the compaction lives in the daemon (Single Source of Truth) instead of being re-implemented per client (AGENTS.md #498).

Invariants (mirrored by the Python plugin’s compaction.py):

  • an assistant message with tool_calls is never separated from its following tool results (atomic blocks);
  • leading / inline system/developer messages are preserved verbatim;
  • output is a deterministic function of the input (no time/random).

Structs§

CompactResult
Outcome of a compaction pass.

Functions§

compact_messages
Compact a message array. fresh_tail_tokens and protect_min_messages bound the verbatim tail; the split always lands on an atomic-block boundary.
render_result
Build the JSON payload returned by the MCP tool: the compacted array plus deterministic stats. Separated so the registered wrapper stays thin.
serialize_transcript
Render messages to a plain-text transcript (bounded, deterministic) for durable offload into the session/knowledge store.