Skip to main content

Transcript

Struct Transcript 

Source
pub struct Transcript { /* private fields */ }
Expand description

Running conversation history for one agent-loop run.

Why: Centralises message accumulation so the loop body stays focused on control flow rather than ChatMessage plumbing, and (#2070) centralises the compaction state machine so the loop only has to call maybe_compact at its turn boundary. What: A thin wrapper over Vec<TranscriptEntry> with append helpers, a raw-history accessor, a compacted model-facing view, and an assistant-text accessor. compaction_triggered records whether ANY compaction has happened yet in this run — once true, to_messages starts appending the last-user-message replay (§5.4 item 3) on every subsequent call, re-anchoring the model on every following turn, not just the turn compaction fired on. Test: transcript::tests::*.

Implementations§

Source§

impl Transcript

Source

pub fn seed(system: &str, task: &str) -> Self

Seed a transcript with a system prompt and the user task.

Why: Every run starts from exactly these two turns; bundling the seed in a constructor prevents the loop from forgetting either. What: Pushes a system message then a user message, both starting uncompacted. maybe_compact (#2070) never marks system or user role entries — see its docs — so these two seed turns are preserved forever regardless of how long the run continues. Test: transcript::tests::seed_has_two_messages.

Source

pub fn push_assistant(&mut self, text: Option<String>, tool_calls: &[ToolCall])

Append the assistant turn from a model response.

Why: The model’s turn (text and any tool calls) must be added to history before the tool results, so the next request reflects the real ordering the API expects. What: Reconstructs a ChatMessage with role = "assistant", carrying the optional text content and the emitted tool calls; records the text (if any) for the final answer. Test: transcript::tests::push_assistant_records_text.

Source

pub fn push_tool_result( &mut self, tool_call_id: &str, name: &str, content: &str, )

Append a tool role result message answering a specific tool call.

Why: The API requires each tool call to be answered by a tool message referencing its tool_call_id, or the next assistant turn errors. (#2070) A use_skill result is the loaded body of a skill the model deliberately chose to invoke — §5.4 item 5 requires it survive compaction forever, the same guarantee system/user turns get. What: Pushes a ChatMessage::tool_result with the call id, function name, and textual result — as a permanently pinned entry when name == USE_SKILL_TOOL_NAME, otherwise as an ordinary compaction- eligible entry. Test: transcript::tests::push_tool_result_sets_call_id, transcript::tests::maybe_compact_never_compacts_pinned_skill_output, transcript::tests::maybe_compact_still_compacts_non_skill_tool_results.

Source

pub fn messages(&self) -> Vec<ChatMessage>

Return the complete, uncompacted raw message history.

Why: (#2070) Non-destructive compaction is only meaningful if the full history stays retrievable for audit even after to_messages starts collapsing older turns; this is that escape hatch. What: Clones every entry’s original ChatMessage, in order, regardless of its compacted flag. Test: transcript::tests::messages_reflects_appends, transcript::tests::compacted_entries_remain_in_raw_history.

Source

pub fn to_messages(&self) -> Vec<ChatMessage>

Render the model-facing view: compacted spans collapsed to a summary, plus a replayed last user message once compaction has occurred.

Why: This is what ChatRequest.messages actually sends — it must shrink once compaction fires (the whole point of §5.4) while staying a valid, coherently-ordered conversation. What: Walks entries in order; a run of one-or-more contiguous compacted entries is replaced by ONE synthetic system-role message (super::compaction::summarize_span’s one-line text) in its place; uncompacted entries pass through unchanged. After the walk, if compaction_triggered is true (i.e. compaction has fired at least once in this transcript’s life), the LAST user-role entry’s message is cloned and appended again at the very end — §5.4 item 3’s “re-anchor the model” replay. A transcript with no user entry (never happens via seed, but guarded rather than assumed) simply skips the replay. Test: transcript::tests::to_messages_collapses_compacted_span, transcript::tests::to_messages_replays_last_user_message_after_compaction, transcript::tests::to_messages_is_passthrough_before_compaction.

Source

pub fn maybe_compact(&mut self, cfg: &CompactionConfig) -> bool

Apply the compaction policy: mark eligible older entries compacted.

Why: (#2070) This is the turn-boundary hook the agent loop calls — gated by the caller on HarnessMode::DailyDriver (Parity must never compact, per §5.9’s D2 reconciliation) — so growth is bounded without the loop body needing to know compaction’s internals. What: No-ops (returns false) unless the CURRENT model-facing view (to_messages(), not the ever-growing raw history — raw size would re-trigger every turn even after compaction shrank what’s actually sent) exceeds cfg.token_threshold. Otherwise, marks every entry before the trailing cfg.keep_last_messages (the active work zone, §5.4 item 4) as compacted = true, EXCEPT entries already compacted (a one-way transform), pinned entries (§5.4 item 5’s skill-output half — see push_tool_result), and system/user role entries (§5.4 item 5’s “preserve… user requests forever” half). Sets compaction_triggered and returns true only if at least one entry was newly marked (an already-fully-compacted or entirely-preserved prefix is a no-op, not a spurious trigger). Test: transcript::tests::maybe_compact_marks_middle_span_only, transcript::tests::maybe_compact_is_noop_below_threshold, transcript::tests::maybe_compact_never_touches_system_or_user, transcript::tests::maybe_compact_never_compacts_pinned_skill_output, transcript::tests::maybe_compact_still_compacts_non_skill_tool_results.

Source

pub fn compacted_count(&self) -> usize

Number of entries currently marked compacted.

Why: Test/observability accessor proving compaction happened without exposing the private TranscriptEntry type. What: Counts entries with compacted == true. Test: transcript::tests::maybe_compact_marks_middle_span_only.

Source

pub fn assistant_text(&self) -> String

Join all recorded assistant text turns into the final answer string.

Why: The AgentOutput.content should be the model’s prose across the run, not the raw JSON transcript; joining the text turns yields that. What: Joins the recorded non-empty assistant texts with blank lines. Test: transcript::tests::assistant_text_joins_turns.

Source

pub fn push_response(&mut self, resp: &ChatResponse)

Convenience accessor: push the assistant turn straight from a response.

Why: Callers usually have a ChatResponse in hand; this saves them destructuring first_text/first_tool_calls at the call site. What: Extracts the first choice’s text and tool calls and delegates to push_assistant. Test: transcript::tests::push_response_appends_assistant.

Trait Implementations§

Source§

impl Clone for Transcript

Source§

fn clone(&self) -> Transcript

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transcript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Transcript

Source§

fn default() -> Transcript

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more