Skip to main content

Turn

Struct Turn 

Source
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 (between TurnStart and the assistant response).
  • output_message — the assistant’s streamed response (from TurnEnd.message).
  • tool_results — tool result messages executed this turn (from TurnEnd.tool_results). Empty when no tool calls were made (StopReason::Stop).

Fields§

§turn_id: TurnId

Identifies this turn: loop_id + turn_index.

§triggered_by: TurnTrigger

What caused this turn to begin.

§usage: Usage

Per-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: AgentMessage

The 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

Source

pub fn index(&self) -> u32

The zero-based turn index within its loop.

Source

pub fn duration(&self) -> Duration

Duration of this turn.

Source

pub fn has_tool_calls(&self) -> bool

Whether this turn included tool calls.

Source

pub fn all_messages(&self) -> Vec<&AgentMessage>

All messages in this turn in chronological order: input_messages, then output_message, then tool_results.

Trait Implementations§

Source§

impl Clone for Turn

Source§

fn clone(&self) -> Turn

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 Turn

Source§

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

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

impl<'de> Deserialize<'de> for Turn

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Turn

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Turn

§

impl RefUnwindSafe for Turn

§

impl Send for Turn

§

impl Sync for Turn

§

impl Unpin for Turn

§

impl UnsafeUnpin for Turn

§

impl UnwindSafe for Turn

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,