pub struct TurnStateMachine { /* private fields */ }Expand description
State machine for turn orchestration.
This is the core abstraction that unifies turn logic between in-memory and durable execution. It tracks the current phase, determines the next action, and handles state transitions.
§Thread Safety
The state machine is not thread-safe. For durable execution, each task execution creates its own state machine from serialized state.
Implementations§
Source§impl TurnStateMachine
impl TurnStateMachine
Sourcepub fn new(context: TurnContext, max_iterations: usize) -> Self
pub fn new(context: TurnContext, max_iterations: usize) -> Self
Create a new state machine for a turn.
§Arguments
context- Turn context with session, turn, and agent IDsmax_iterations- Maximum Reason → Act cycles before stopping
Sourcepub fn context(&self) -> &TurnContext
pub fn context(&self) -> &TurnContext
Get the turn context.
Sourcepub fn current_iteration(&self) -> usize
pub fn current_iteration(&self) -> usize
Get the current iteration count.
Sourcepub fn total_tool_calls(&self) -> usize
pub fn total_tool_calls(&self) -> usize
Get the total tool calls made so far.
Sourcepub fn next_action(&self) -> TurnAction
pub fn next_action(&self) -> TurnAction
Determine the next action to take.
This is the core dispatch method. Call this in a loop and execute
the returned action until TurnAction::Complete is returned.
Sourcepub fn on_input_completed(&mut self)
pub fn on_input_completed(&mut self)
Record that input processing completed.
Call this after successfully executing the input atom.
Sourcepub fn on_reason_completed(
&mut self,
response: String,
has_tool_calls: bool,
tool_call_count: usize,
success: bool,
error: Option<String>,
has_pending_user_messages: bool,
)
pub fn on_reason_completed( &mut self, response: String, has_tool_calls: bool, tool_call_count: usize, success: bool, error: Option<String>, has_pending_user_messages: bool, )
Record that reasoning completed.
§Arguments
response- The text response from the LLM (may be empty)has_tool_calls- Whether the LLM requested tool callstool_call_count- Number of tool calls (0 if none)success- Whether the LLM call succeedederror- Error message if success is falsehas_pending_user_messages- Whether new user messages arrived during this turn (steering signals). When true and reason would otherwise complete (no tool calls, success), the turn stays in PendingReason so the next iteration picks up the new messages from the conversation history. This is “in-turn steering” — matching Claude Code behavior.
Sourcepub fn on_act_completed(&mut self)
pub fn on_act_completed(&mut self)
Record that action (tool execution) completed.
Call this after successfully executing the act atom. The turn then loops back to Reason for another iteration.
Sourcepub fn seal(&mut self, reason: SealReason)
pub fn seal(&mut self, reason: SealReason)
Deliberately seal the turn, stopping further scheduling (EVE-534).
Call this between atoms when the engine decides to stop a turn to prevent
waste — e.g. the work budget is exhausted (SealReason::Budget). The
turn transitions to Completed and next_action resolves to
TurnOutcome::Sealed. Sealing is idempotent and the first reason wins.
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Check if the turn has completed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TurnStateMachine
impl RefUnwindSafe for TurnStateMachine
impl Send for TurnStateMachine
impl Sync for TurnStateMachine
impl Unpin for TurnStateMachine
impl UnsafeUnpin for TurnStateMachine
impl UnwindSafe for TurnStateMachine
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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