State Management
Voice agents need to remember things. User names, order IDs, preferences, and what was said earlier in the conversation. State management handles this memory.
Types of State
Session State (Instance Variables)
Store data on self to remember it across turns within a call.
Initial Variables
Access caller-provided data via self.initial_variables in __init__.
Initial variables are passed when making outbound calls or via the WebSocket connection.
Context History
The conversation context tracks all messages:
Extracting Information
Use tools to extract and store structured data:
Turn Counting
Track conversation progress:
Shared State Across Nodes
For multi-node graphs, use the session for shared state:
Persistent State
For data that survives across calls, use an external store:
State Validation
Validate collected data before proceeding:
Tips
Use instance variables for session state
The simplest and most reliable approach. Each session gets its own agent instance.
Access initial_variables in start()
Session context is available in the init_event. Store what you need as instance variables.
Validate before proceeding
Build tools that check required fields are present before taking action.

