Guild agents often need to pause execution — waiting for a tool to complete, a user to respond, or an external service to return data. State management determines how your agent’s in-progress work is preserved and restored across these pauses.Documentation Index
Fetch the complete documentation index at: https://docs.guild.ai/llms.txt
Use this file to discover all available pages before exploring further.
Two approaches
Guild offers two state management models:Auto-managed
The runtime handles state automatically. Write a normal
async function with the "use agent" directive — the Babel compiler transforms it into a resumable state machine.Self-managed
You handle state explicitly using
task.save() and task.restore(). More control, but more boilerplate.Auto-managed state
With the"use agent" directive, the Babel compiler transforms your async run function into a state machine that can be paused at any await expression, serialized, and resumed later.
- No
Promise.all,Promise.any, orPromise.raceacrossawaitpoints - Dynamic function references may not survive serialization
- Only code in the agent file is compiled (imports are not traversed)
Self-managed state
WithSelfManagedStateAgent, you define a stateSchema and use task.save() / task.restore() to explicitly persist and retrieve state between tool calls.
- Parallel tool calls via
callTools([...]) - Full control over what gets persisted
- No compiler limitations
Choosing a model
| Consideration | Auto-managed | Self-managed |
|---|---|---|
| Boilerplate | Minimal | More |
| Parallel tool calls | No | Yes |
| Serialization constraints | Yes | None |
| State visibility | Implicit | Explicit |
| Recommended for | Most agents | Complex workflows |