Skip to main content
Workflow session state enables sharing and updating state data across all components within a workflow: agents, teams, and custom functions. Session state data will be persisted if a database is available, and loaded from there in subsequent runs of the workflow. Workflows session state diagram

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 via run_context.session_state. Example: Shopping List Management
See the RunContext schema for more information.

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
See examples for more details. The run_context is also available as a parameter in the evaluator and selector functions of the Condition and Router steps:
See example of Session State in Condition Evaluator Function and Session State in Router Selector Function for more details.

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
Cross-Component Coordination
  • Agents, teams, and functions share the same state object
  • Enables sophisticated collaboration patterns
  • Maintains data consistency across workflow execution
Flexible Data Structure
  • 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.

Agent Examples

See how agents interact with shared session state

Team Examples

Learn how teams coordinate using shared state