Use this file to discover all available pages before exploring further.
The Runflow Context is a global singleton that manages execution information and user identification. It allows you to identify once and all agents/workflows automatically use this context.
When you call identify(), you’re telling Runflow who is interacting with your agent. This single call connects three critical systems:
Memory — conversation history is stored and retrieved by this identifier. Same identifier = same conversation history.
Traces — all execution traces are linked to this user, so you can search and filter by user in the dashboard.
Metrics — business events emitted with track() are associated with this user.
Without identify(), your agent still works, but memory won’t persist correctly between sessions and your dashboard data won’t be linked to specific users.
import { identify } from '@runflow-ai/sdk/observability';// Always call identify BEFORE agent.process()identify(userPhone);const result = await agent.process({ message, sessionId });
import { Agent, openai } from '@runflow-ai/sdk';import { identify } from '@runflow-ai/sdk/observability';// Identify user by phone (WhatsApp)identify('+5511999999999');// Agent automatically uses the contextconst agent = new Agent({ name: 'WhatsApp Bot', instructions: 'You are a helpful assistant.', model: openai('gpt-4o'), memory: { maxTurns: 10, },});// Memory is automatically bound to the phone numberawait agent.process({ message: 'Hello!',});
import { Runflow } from '@runflow-ai/sdk/core';// Get complete stateconst state = Runflow.getState();// Get specific valueconst threadId = Runflow.get('threadId');const entityType = Runflow.get('entityType');// Set custom state (advanced)Runflow.setState({ entityType: 'custom', entityValue: 'xyz', threadId: 'my_custom_thread_123', userId: 'user_123', metadata: { custom: 'data' },});// Clear state (useful for testing)Runflow.clearState();