State
Shared memory, history, and key-value state for Agents and Networks.
State is shared memory, or context, that is be passed between different Agents in a Networks. State is used to store message history and any arbitrary data from Tools.
State is what enables agent workflows to execute in a loop and contextually make decisions. Agents continuously build upon and leverage this context to complete complex tasks.
AgentKit’s State stores data in two ways:
- History of messages - A list of prompts, responses, and tool calls.
- Key-value storage - Simple storage for sharing data between agent calls and tool calls.
Both history and key-value data are used automatically by the Network to store and provide context to the next Agent.
History
The history system maintains a chronological record of all Agent interactions in your Network.
Each interaction is stored as an InferenceResult
, which includes:
agent
: TheAgent
that created this result.input
: The original user input prompt passed to the Agent’srun()
method.prompt
: The complete initial set of messages (Message[]
) forming the initial call’s prompt.history
: The history of messages (Message[]
) also sent to the model’s inference call which is appended to theprompt
array.output
: The parsed results as list of messages (Message[]
). May be an empty array if the model returns only tool calls (see below).toolCalls
: The results of any Tools called by the Agent as an array ofToolResultMessage
objects.raw
: Raw API response
Key-value store
The key-value store can be used to store information between Agent calls. It’s API contains all the simple methods you might expect:
Common uses for the key-value store include:
- Storing intermediate results that other Agents might need within lifecycles
- Storing user preferences or context
- Passing data between Tools and Agents
The State
’s key-value store is only retained for a single Network
’s run.
This means that it is only short-term memory and is not persisted across
different Network run()
calls.
State, which is required by Networks, has many uses across various AgentKit components.
State in Tools
State can be leveraged in a Tool’s handler
method to get or set data. Here is an example of a Tool that uses kv
as a temporary store for files and their contents that are being written by the Agent.