Get a state value by key with optional type-safe property lookup. Returns a deep copy to prevent mutations.
The complete state interface type
The property key (inferred from argument)
Key to retrieve specific value
The value for the key, or undefined if key doesn't exist
Get a state value by key with optional type-safe property lookup. Returns a deep copy to prevent mutations.
Key to retrieve specific value
The value for the key, or undefined if key doesn't exist
Set a state value with optional type-safe property validation. Validates JSON serializability and stores a deep copy.
The complete state interface type
The property key (inferred from argument)
Set a state value with optional type-safe property validation. Validates JSON serializability and stores a deep copy.
The key to set
The value to store (must be JSON serializable)
Clear all state values.
Get all state keys.
Array of state keys
Agent state provides key-value storage outside conversation context. State is not passed to the model during inference but is accessible by tools (via ToolContext) and application logic.
All values are deep copied on get/set operations to prevent reference mutations. Values must be JSON serializable.
Example