pub struct AgentState { /* private fields */ }Expand description
Shared state that persists across graph execution. All nodes can read and write to this state.
Implementations§
Source§impl AgentState
impl AgentState
Sourcepub fn with_limits(limits: StateLimits) -> Self
pub fn with_limits(limits: StateLimits) -> Self
Create a new empty state with explicit limits.
Sourcepub fn with_data_and_limits(
data: HashMap<String, Value>,
limits: StateLimits,
) -> Self
pub fn with_data_and_limits( data: HashMap<String, Value>, limits: StateLimits, ) -> Self
Create state with initial data and explicit limits.
Sourcepub async fn register_reducer(
&self,
key: impl Into<String>,
reducer: impl Reducer + 'static,
)
pub async fn register_reducer( &self, key: impl Into<String>, reducer: impl Reducer + 'static, )
Register a reducer for a specific state key.
When set() is called on this key and a value already exists,
the reducer is used to combine old and new values.
Sourcepub async fn get<T>(&self, key: &str) -> Result<T>where
T: DeserializeOwned,
pub async fn get<T>(&self, key: &str) -> Result<T>where
T: DeserializeOwned,
Get a value from state (type-safe)
Sourcepub async fn get_opt<T>(&self, key: &str) -> Result<Option<T>>where
T: DeserializeOwned,
pub async fn get_opt<T>(&self, key: &str) -> Result<Option<T>>where
T: DeserializeOwned,
Try to get a value (returns None if missing)
Sourcepub async fn set<T>(&self, key: &str, value: T) -> Result<()>where
T: Serialize,
pub async fn set<T>(&self, key: &str, value: T) -> Result<()>where
T: Serialize,
Set a value in state (type-safe). If a reducer is registered for this key and a value already exists, the reducer is used to combine old and new values.
Sourcepub async fn set_raw(&self, key: &str, value: Value) -> Result<()>
pub async fn set_raw(&self, key: &str, value: Value) -> Result<()>
Set a raw JSON value without applying reducers.
Sourcepub async fn apply_reducer(
&self,
key: &str,
current: &Value,
new: &Value,
) -> Result<Value>
pub async fn apply_reducer( &self, key: &str, current: &Value, new: &Value, ) -> Result<Value>
Apply a reducer to combine current and new values for a key. If no reducer is registered, returns the new value (last-write-wins).
Sourcepub async fn snapshot(&self) -> StateSnapshot
pub async fn snapshot(&self) -> StateSnapshot
Create a snapshot of current state
Sourcepub async fn save_to_history(&self)
pub async fn save_to_history(&self)
Save current state to history
Sourcepub async fn restore(&self, snapshot: &StateSnapshot)
pub async fn restore(&self, snapshot: &StateSnapshot)
Restore state from snapshot
Sourcepub async fn get_history(&self) -> Vec<StateSnapshot>
pub async fn get_history(&self) -> Vec<StateSnapshot>
Get state history
Sourcepub async fn transaction(&self) -> StateTransaction
pub async fn transaction(&self) -> StateTransaction
Begin a transaction. Captures a snapshot so changes can be rolled back.
Sourcepub async fn fork(&self) -> AgentState
pub async fn fork(&self) -> AgentState
Create an independent deep copy of this state for parallel branches. The forked state has its own data storage but shares the same reducers.
Trait Implementations§
Source§impl Clone for AgentState
impl Clone for AgentState
Source§fn clone(&self) -> AgentState
fn clone(&self) -> AgentState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more