pub struct Turn {
pub turn_id: TurnId,
pub triggered_by: TurnTrigger,
pub usage: Usage,
pub input_messages: Vec<AgentMessage>,
pub output_message: AgentMessage,
pub tool_results: Vec<AgentMessage>,
pub started_at: DateTime<Utc>,
pub ended_at: DateTime<Utc>,
pub request_payload: Option<AnnotatedRequestPayload>,
}Expand description
A materialized record of one LLM turn within a loop.
Each turn represents one LLM call-response cycle plus any tool executions
that followed. Built by [SessionRecorder] from TurnStart/TurnEnd
event pairs.
§Message partitioning
input_messages— user prompts, steering messages, and follow-ups injected at the start of this turn (betweenTurnStartand the assistant response).output_message— the assistant’s streamed response (fromTurnEnd.message).tool_results— tool result messages executed this turn (fromTurnEnd.tool_results). Empty when no tool calls were made (StopReason::Stop).
Fields§
§turn_id: TurnIdIdentifies this turn: loop_id + turn_index.
triggered_by: TurnTriggerWhat caused this turn to begin.
usage: UsagePer-turn token usage (from TurnEnd.usage).
input_messages: Vec<AgentMessage>Messages injected at the start of this turn (user prompts, steering messages, follow-ups). Empty for continuation turns that only have tool results from the prior turn feeding back in.
output_message: AgentMessageThe assistant message produced by the LLM this turn.
tool_results: Vec<AgentMessage>Tool result messages from this turn. Empty when no tool calls were made.
started_at: DateTime<Utc>Wall-clock time when this turn began (from TurnStart.timestamp).
ended_at: DateTime<Utc>Wall-clock time when this turn completed (from TurnEnd.timestamp).
request_payload: Option<AnnotatedRequestPayload>Fully-assembled LLM request payload captured from
crate::AgentEvent::TurnRequest when
crate::session::SessionRecorderConfig::capture_turn_requests is
enabled. None when capture is off (default) or for sessions persisted
before phi-core 0.9.0.
Added in phi-core 0.9.0. Serialization is skipped when None for
back-compat (existing session JSON loads cleanly into 0.9.0 readers).
Implementations§
Source§impl Turn
impl Turn
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Whether this turn included tool calls.
Sourcepub fn all_messages(&self) -> Vec<&AgentMessage>
pub fn all_messages(&self) -> Vec<&AgentMessage>
All messages in this turn in chronological order: input_messages, then output_message, then tool_results.