pub struct Turn {
pub id: TurnId,
pub input: TurnInput,
pub metrics: TurnMetrics,
pub cancel_token: CancellationToken,
}Expand description
Complete state of a single agent turn from input through metrics capture.
Created at the start of process_user_message, populated through the turn lifecycle,
and consumed at the end for metrics emission and trace completion.
Ownership: Turn is stack-owned — created in begin_turn, passed through sub-methods
by &mut Turn, and consumed in end_turn. It is never stored on the Agent struct.
Phase 1 scope: carries id, input, metrics, and cancel_token only.
Fields§
§id: TurnIdMonotonically increasing identifier for this turn within the conversation.
input: TurnInputResolved user input for this turn.
metrics: TurnMetricsPer-turn metrics accumulated during the turn lifecycle.
cancel_token: CancellationTokenPer-turn cancellation token. Cancelled when the user aborts the turn or the agent shuts
down. Created fresh in Turn::new so each turn has an independent token.
Implementations§
Source§impl Turn
impl Turn
Sourcepub fn new(id: TurnId, input: TurnInput) -> Self
pub fn new(id: TurnId, input: TurnInput) -> Self
Create a new turn with the given ID and input.
A fresh CancellationToken is created for each turn so that cancelling one turn
does not affect subsequent turns.
§Examples
let input = TurnInput::new("hello".to_owned(), vec![]);
let turn = Turn::new(TurnId(0), input);
assert_eq!(turn.id, TurnId(0));Sourcepub fn metrics_snapshot(&self) -> &TurnMetrics
pub fn metrics_snapshot(&self) -> &TurnMetrics
Return an immutable reference to the turn metrics.
Sourcepub fn metrics_mut(&mut self) -> &mut TurnMetrics
pub fn metrics_mut(&mut self) -> &mut TurnMetrics
Return a mutable reference to the turn metrics.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request