Skip to main content

RunState

Struct RunState 

Source
pub struct RunState {
    pub total_actions: usize,
    pub turn_actions: usize,
    pub run_has_actions: bool,
    pub run_actions: Vec<String>,
    pub reasoning_only_strikes: usize,
    pub empty_response_strikes: usize,
    pub nudge_count: usize,
    pub thinking_disabled_for_rest_of_run: bool,
    pub original_thinking_enabled: bool,
    pub truncation_strikes: usize,
    pub awaiting_human: bool,
}
Expand description

Run-level state tracking for the react loop.

Manages counters and flags that track the current run’s progress. Most fields are reset at the start of each run (when a new user message arrives); total_actions and original_thinking_enabled are session-lifetime and survive run boundaries.

§Backward compatibility

Before this struct existed, nudge_count and turn_tool_calls were flat fields on AgentSession (and the session total lived in a top-level total_tool_calls). The RawAgentSession deserialization shim migrates them automatically; the field aliases below keep pre-T7 run_state wire keys readable.

Fields§

§total_actions: usize

Session-lifetime count of actions executed (across all runs). Not reset by reset_for_new_run — a session that already acted stays “not first turn” across run boundaries. Used by ToolEnforcementMiddleware for “first_turn_only” enforcement.

§turn_actions: usize

Number of actions already executed in the current turn. Reset to 0 at the start of each turn (when a new user message arrives). Used by TurnToolLimitMiddleware to enforce per-turn action limits.

§run_has_actions: bool

Whether any actions ran in the current run. Reset to false at the start of each run. Used by the completion judge to determine if actions were used before a text-only response.

§run_actions: Vec<String>

The tools this run has called, in order, by name. The completion judge is handed the response and nothing else, so without this it cannot tell “the agent did the work and is reporting” from “the agent said a few words and stopped” — both look like a short text-only turn. Names only: no arguments, so nothing sensitive rides along. Reset by reset_for_new_run.

§reasoning_only_strikes: usize

Number of consecutive LLM turns that produced only reasoning_content (no text, no tool call). Reset to 0 when a normal response or tool call is produced. Used by the react loop to fail instead of looping forever on a reasoning-model runaway.

§empty_response_strikes: usize

Number of consecutive LLM turns that produced a completely empty response (no text, no reasoning, no tool call). Reset to 0 when a normal response or tool call is produced. Used by the react loop to retry a bounded number of times, then fail instead of looping forever.

§nudge_count: usize

Number of tool-enforcement nudges issued in the current turn. Reset to 0 at the start of each turn (when a new user message arrives). Used by ToolEnforcementMiddleware to cap nudge attempts per turn.

§thinking_disabled_for_rest_of_run: bool

Thinking is disabled for the rest of the current run. Set to true when reasoning_only_strikes reaches the maximum (3). Reset to false at the start of each new run (when a new user message arrives). This allows the model to continue without thinking after too many reasoning-only responses.

§original_thinking_enabled: bool

Original thinking configuration (for restoration)

Records whether thinking was originally enabled when the session started. Used to restore thinking to its original state after DisableThinking → RestoreThinking cycle.

§truncation_strikes: usize

Number of consecutive LLM turns where the truncation guard fired (all tool_calls had invalid/truncated arguments). Reset to 0 when at least one valid tool call executes successfully. Used to break the re-issue death spiral: after N consecutive truncations, stop retrying and fail with an actionable message.

§awaiting_human: bool

The latest tool batch parked on a human step (a design-canvas screen awaiting a pick) and no tool ran after it. Overwritten per batch by handle_tool_calls. When true at the end of a run, the run is waiting for the user — the guard must complete instead of nudging “continue working” over their pending answer.

Implementations§

Source§

impl RunState

Source

pub fn reset_for_new_run(&mut self)

Reset all run-level state for a new run (when a new user message arrives). Session-lifetime state (total_actions, original_thinking_enabled) is not reset.

Source

pub fn record_actions(&mut self, n: usize, names: &[String])

Record executed actions (branch 3: actions ran). Counts them against both the turn and the session total (D5: one counting entry point, unit = actions) and resets reasoning_only_strikes, empty_response_strikes, and truncation_strikes.

Source

pub fn record_reasoning_only(&mut self) -> usize

Record reasoning-only response (branch 1). Resets empty_response_strikes. Returns the new strike count. If strikes reach 3, disables thinking for the rest of the run (the caller owns the observability for that flip — types stay I/O-free).

Source

pub fn record_empty_response(&mut self) -> usize

Record empty response (branch 2). Resets reasoning_only_strikes. Returns the new strike count.

Source

pub fn record_truncation(&mut self) -> usize

Record a truncation guard firing (all tool_calls had invalid arguments). Returns the new strike count. Caller should check against threshold.

Trait Implementations§

Source§

impl Clone for RunState

Source§

fn clone(&self) -> RunState

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 RunState

Source§

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

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

impl Default for RunState

Source§

fn default() -> RunState

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RunState

Source§

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

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

impl Serialize for RunState

Source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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: Sized + 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: Sized + 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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