pub struct TurnSummary {
pub thread_id: ThreadId,
pub turn: usize,
pub total_turns: u32,
pub turn_usage: TokenUsage,
pub total_usage: TokenUsage,
pub provenance: AuditProvenance,
pub response_id: Option<String>,
pub stop_reason: Option<StopReason>,
pub tool_call_count: usize,
pub duration_ms: u64,
pub tool_runtime: ToolRuntime,
pub strict_durability: bool,
}Expand description
Structured server-facing outcome metadata for a single turn.
Captures everything the server needs to durably persist about a
turn’s LLM-level provenance: thread/turn identity, provider and model
identifiers, response ID and stop reason from the turn-closing LLM
call, token usage, tool-call count, wall-clock duration, and the
TurnOptions the caller requested.
§Why this exists
The original TurnOutcome only exposed token counts and turn
numbers. Later server phases need:
- Provider / model — to correlate rows across provider rotations and to route audit streams by provider.
- Response ID — to join durable turn rows against the raw provider response stored externally (observability pipelines, replay, support escalations).
- Stop reason — to branch on
end_turnvstool_usevsrefusalwithout re-parsing message history. - Tool-call count — to bill tool execution and detect runaway turns without walking the tool registry.
- Duration — to feed SLO dashboards and auto-tune retry budgets.
- Tool runtime / strict durability flags — to record which execution profile was in effect, so later replay can reconstruct the same decisions.
§Serialization
TurnSummary is fully serializable. Servers are expected to persist
it alongside (or inside) their turn rows. Duration is exposed as
duration_ms (milliseconds) to avoid a serde dance around
std::time::Duration.
§Authoritative vs convenience
Fields in TurnSummary are authoritative for server execution:
they are produced by the same code path that writes the durable
event store and are guaranteed to be consistent with the events the
server observed on the wire. Convenience accessors on TurnOutcome
(e.g. the legacy input_tokens / output_tokens fields on Done)
are kept only so local callers do not have to break; new code should
read from summary instead.
Fields§
§thread_id: ThreadIdThread this turn belongs to.
Duplicated from the call site so the summary is self-describing when persisted alone (for durable audit rows).
turn: usizeTurn number that produced this outcome (1-indexed).
total_turns: u32Total number of turns executed in this run so far.
For mid-run outcomes like NeedsMoreTurns / PendingToolCalls
this equals turn. For terminal outcomes (Done, Refusal,
Cancelled) it reflects the final total.
turn_usage: TokenUsageToken usage for the LLM call(s) that produced this turn.
total_usage: TokenUsageCumulative token usage across every turn in this run so far.
provenance: AuditProvenanceProvider / model provenance captured from the turn-closing
LLM call — identical shape to AuditProvenance so durable
audit rows stay consistent with turn rows.
response_id: Option<String>Provider response ID from the turn-closing LLM call.
None when the provider did not return an ID or the turn
terminated before the LLM responded (e.g. cancelled before the
first call).
stop_reason: Option<StopReason>Stop reason reported by the turn-closing LLM call.
None when no response was produced for this turn (e.g. the
turn was cancelled before the LLM replied, or the turn was
resumed purely from external tool results without calling the
LLM again).
tool_call_count: usizeNumber of tool calls the LLM requested in this turn.
Zero for pure text turns.
duration_ms: u64Wall-clock duration of this turn, in milliseconds.
Measured from the start of run_turn to the moment the outcome
is returned. Clamped to u64::MAX on the unlikely overflow.
tool_runtime: ToolRuntimeThe ToolRuntime selected for this turn.
strict_durability: boolWhether strict durability was requested for this turn.
Implementations§
Source§impl TurnSummary
impl TurnSummary
Sourcepub fn new(
thread_id: ThreadId,
turn: usize,
provenance: AuditProvenance,
options: &TurnOptions,
) -> Self
pub fn new( thread_id: ThreadId, turn: usize, provenance: AuditProvenance, options: &TurnOptions, ) -> Self
Construct an empty summary for a thread / provider / model.
Used by the runtime as a starting point; it then updates specific fields as the turn progresses. Tests and downstream consumers should generally pattern-match on the outcome and read fields from the populated summary rather than construct one from scratch.
Trait Implementations§
Source§impl Clone for TurnSummary
impl Clone for TurnSummary
Source§fn clone(&self) -> TurnSummary
fn clone(&self) -> TurnSummary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TurnSummary
impl Debug for TurnSummary
Source§impl<'de> Deserialize<'de> for TurnSummary
impl<'de> Deserialize<'de> for TurnSummary
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TurnSummary
Source§impl PartialEq for TurnSummary
impl PartialEq for TurnSummary
Source§fn eq(&self, other: &TurnSummary) -> bool
fn eq(&self, other: &TurnSummary) -> bool
self and other values to be equal, and is used by ==.