pub struct CompactedHistory { /* private fields */ }Expand description
Compacted view over a SessionGraph’s event log.
External operators implementing Compactor for a custom
strategy (LLM-summary compaction, importance-weighted retention,
…) construct the initial form via CompactedHistory::group
and return either the same value or one rebuilt with
CompactedHistory::from_turns after filtering. The
tool_call / tool_result pair invariant stays type-enforced:
the only path to a ToolPair is the internal grouping code,
so external impls can drop or pass through tool round-trips
but can’t synthesize unmatched ones.
Implementations§
Source§impl CompactedHistory
impl CompactedHistory
Sourcepub fn group(events: &[GraphEvent]) -> Result<Self>
pub fn group(events: &[GraphEvent]) -> Result<Self>
Group events into the type-enforced Turn shape and
return the un-trimmed compaction. The grouping rejects an
event log that violates the pair invariant before
compaction (e.g. ToolResult without a preceding
ToolCall); a well-formed SessionGraph never hits the
error path.
External Compactor impls call this to get the initial
grouped form, then choose which turns to retain.
Sourcepub const fn from_turns(turns: Vec<Turn>) -> Self
pub const fn from_turns(turns: Vec<Turn>) -> Self
Build a CompactedHistory from a pre-grouped Vec<Turn>.
External Compactor impls reach for this after filtering
or transforming the turns returned by
CompactedHistory::group. The pair invariant survives
the round-trip because the only path to a ToolPair is
still the internal grouping — operators pass them through
but can’t synthesize new ones.
Sourcepub fn to_messages(&self) -> Vec<Message>
pub fn to_messages(&self) -> Vec<Message>
Render as Vec<Message> suitable for ChatModel::complete.
Mirrors crate::SessionGraph::current_branch_messages but
over the compacted view: every assistant turn’s tool_use
blocks are followed by a synthetic Role::Tool message
per ToolPair, so the wire-side codec sees the matched
pairs the vendor expects.
Trait Implementations§
Source§impl Clone for CompactedHistory
impl Clone for CompactedHistory
Source§fn clone(&self) -> CompactedHistory
fn clone(&self) -> CompactedHistory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more