Get State
Retrieves the current state data from a session.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
Inputs
- Session ID - (string) Unique identifier for the conversation session.
Outputs
- State - (object) The current state data from the session, containing all key-value pairs stored in the session.
How It Works
The Get State node retrieves session state:
- Input Validation - Verifies that Session ID is provided
- Session Lookup - Retrieves the session from the session service
- State Extraction - Extracts the state object from the session
- Output - Returns the complete state as an object
Common Use Cases
- Reading Agent Data - Access data stored by agents during conversations
- Workflow Decisions - Use state values for conditional logic
- Data Extraction - Retrieve specific values from the conversation context
- Debugging - Inspect session state to troubleshoot issues
- State Transfer - Copy state between sessions or workflows
- Reporting - Extract conversation data for analytics or reporting
Error Handling
The node will return errors in the following cases:
- Missing required field - "Session ID is required"
- Session not found - "Session with ID
{{session_id}}not found" - Service unavailable - Cannot connect to the session service
- Permission errors - Insufficient permissions to access the session
Usage Notes
- Complete State - Returns the entire state object with all key-value pairs
- Read-Only Operation - This node does not modify the state; use Update State to change values
- State Structure - The state is a JavaScript object (dictionary/map) with string keys and any value types
- Empty State - If no state has been set, returns an empty object
{} - Nested Objects - State can contain nested objects and arrays
- Agent Updates - State includes all updates made by agents during the conversation
- Session Required - The session must exist; use Create Session or Load Session first
State Content
The state object may contain:
- Agent Results - Output keys set by LLM Agents via the Output Key input
- User Data - Information about the user or conversation context
- Workflow Variables - Data stored by Update State nodes
- Agent Context - Context information used by agents
- Custom Data - Any key-value pairs added during the workflow
Example Usage
Reading agent output:
- Session ID:
"session-123" - Expected State:
{
"analysis_result": "The data shows a positive trend",
"confidence_score": 0.85,
"user_name": "John Doe"
}
Conditional workflow:
- Use Get State to retrieve session state
- Check if a specific key exists (e.g.,
analysis_complete) - Branch workflow based on the state value
Data extraction:
- Use Get State to get the full state
- Extract specific fields using JavaScript or other processing nodes
- Pass extracted data to subsequent nodes
Accessing State Values
After retrieving the state, you can access individual values:
In JavaScript nodes:
const state = $msg.state;
const userName = state.user_name;
const analysisResult = state.analysis_result;
In Mustache templates:
Hello \{\{state.user_name\}\}!
Analysis: \{\{state.analysis_result\}\}
Best Practices
- Check Session Exists - Ensure the session exists before getting state
- Handle Empty State - Account for the possibility of an empty state object
- Use Specific Keys - Access specific keys rather than relying on the entire state structure
- Error Handling - Enable Continue On Error if the session might not exist
- State Validation - Verify that expected keys exist before using them
Integration with Other Nodes
With LLM Agent:
- LLM Agents automatically have access to session state
- Use Output Key on LLM Agent to write values to state
- Use Get State to read those values in other parts of the workflow
With Update State:
- Get State retrieves current values
- Update State modifies specific keys
- Get State again to verify changes
With Create/Load Session:
- Create Session can set initial state
- Load Session retrieves the session and state
- Get State provides the state for subsequent use