StateSpec

Trait StateSpec 

Source
pub trait StateSpec:
    Sized
    + State
    + Clone
    + Send
    + 'static {
    type Action: Serialize + DeserializeOwned + Send + 'static;

    const SCOPE: StateScope = StateScope::Thread;

    // Required method
    fn reduce(&mut self, action: Self::Action);
}
Expand description

Extends State with a typed action and a pure reducer.

Implementors define what actions their state accepts and how the state transitions in response. The kernel applies actions via type-erased AnyStateAction without knowing the concrete types.

Scope (Run vs ToolCall) is determined at the call site — AnyStateAction::new() for run-scoped state, AnyStateAction::new_for_call() for tool-call-scoped state — rather than being encoded in the trait, keeping business semantics out of tirea-state.

§Usage

Typically generated by #[derive(State)] with #[tirea(action = "...")]:

#[derive(State, Clone, Serialize, Deserialize)]
#[tirea(path = "counters.main", action = "CounterAction")]
struct Counter { value: i64 }

impl Counter {
    fn reduce(&mut self, action: CounterAction) {
        match action {
            CounterAction::Increment(n) => self.value += n,
        }
    }
}

Provided Associated Constants§

Source

const SCOPE: StateScope = StateScope::Thread

Lifecycle scope of this state type.

Defaults to Thread (never automatically cleaned) for backward compatibility. Override via #[tirea(scope = "run")] or #[tirea(scope = "tool_call")] in the derive macro.

Required Associated Types§

Source

type Action: Serialize + DeserializeOwned + Send + 'static

The action type accepted by this state.

Required Methods§

Source

fn reduce(&mut self, action: Self::Action)

Pure reducer: apply an action to produce the next state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl StateSpec for RunLifecycleState

Source§

const SCOPE: StateScope = ::tirea_state::StateScope::Run

Source§

type Action = RunLifecycleAction

Source§

impl StateSpec for SuspendedCallState

Source§

const SCOPE: StateScope = ::tirea_state::StateScope::ToolCall

Source§

type Action = SuspendedCallAction

Source§

impl StateSpec for ToolCallState

Source§

const SCOPE: StateScope = ::tirea_state::StateScope::ToolCall

Source§

type Action = ToolCallStateAction