
How Workflow Session State Works
1. State Initialization
Initialize session state when creating a workflow. The session state can start empty or with predefined data that all workflow components can access and modify.2. Access and Modify State Data
All workflow components - agents, teams, and functions - can read from and write to the shared session state. This enables persistent data flow and coordination across the entire workflow execution. From tools, you can access the session state viarun_context.session_state.
Example: Shopping List Management
3. run_context as a parameter for custom python functions step in workflow
You can add the run_context parameter to the Python functions you use as custom steps.
The run_context object will be automatically injected when running the function.
You can use it to read and modify the session state, via run_context.session_state.
On the function of the custom python function step for a workflow
run_context is also available as a parameter in the evaluator and selector functions of the Condition and Router steps:
Key Benefits
Persistent State Management- Data persists across all workflow steps and components
- Enables complex, stateful workflows with memory
- Supports deterministic execution with consistent state
- Agents, teams, and functions share the same state object
- Enables sophisticated collaboration patterns
- Maintains data consistency across workflow execution
- Use any Python data structure (dictionaries, lists, objects)
- Structure data to match your workflow requirements
- Access and modify state through standard Python operations
The
run_context object, containing the session state, is automatically passed to all agents and teams within a
workflow, enabling seamless collaboration and data sharing between different
components without manual state management.Useful Links
Agent Examples
See how agents interact with shared session state
Team Examples
Learn how teams coordinate using shared state
