State
Leverage a Network’s State across Routers and Agents.
The State
class provides a way to manage state and history across a network of agents. It includes key-value storage and maintains a stack of all agent interactions.
The State
is accessible to all Agents, Tools and Routers as a state
or network.state
property.
Creating a State
Reading and Modifying State (state.kv
)
The State
class provides a key-value store accessible via the kv
property.
Learn more about the State use cases in the State concept guide.
Set a value in the key-value store.
Get a value from the key-value store.
Delete a key from the store.
Check if a key exists in the store.
Get all key-value pairs as a record.
State History
The State history is passed as a history
to the lifecycle hooks and via the network
argument to the Tools handlers to the Router function.
The State history can be retrieved - as a copy - using the state.results
property composed of InferenceResult
objects:
InferenceResult
The InferenceResult
class represents a single agent call as part of the network state. It stores all inputs and outputs for a call.
The agent responsible for this inference call.
The input passed into the agent’s run method.
The input instructions without additional history, including the system prompt, user input, and initial agent assistant message.
The history sent to the inference call, appended to the prompt to form a complete conversation log.
The parsed output from the inference call.
Output from any tools called by the agent.
The raw API response from the call in JSON format.
Message
Types
The state system uses several message types to represent different kinds of interactions: