Skip to main content

switchyard_libsy/core/
state.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Built-in state shared by processors and classifiers across a session.
5
6use std::collections::HashMap;
7
8use crate::algorithms::util::tool_signals::ToolSignals;
9
10/// A value in a session's [`State`].
11#[derive(Debug, Clone)]
12pub enum StateValue {
13    /// Text value.
14    String(String),
15    /// Nonnegative counter.
16    Count(u32),
17    /// Signed integer value.
18    Int(i32),
19    /// Floating-point value.
20    Scalar(f32),
21}
22
23/// Routing facts accumulated across one session's algorithm runs.
24#[derive(Debug, Clone, Default)]
25pub struct State {
26    /// Number of turns processed for this session.
27    pub turn_count: u32,
28    /// Tool-result signals for the current request, set by the tool-signal
29    /// processor. `None` until it runs or when the request has no tool activity,
30    /// so routers must treat absence as "no signal yet".
31    pub tool_signals: Option<ToolSignals>,
32    /// Algorithm-specific state keyed by stable internal names.
33    pub extra: HashMap<String, StateValue>,
34}