What is FlowState?
FlowState is the central state object that flows through the entire execution lifecycle of an agent. It contains all the information about the current execution: conversation history, tool calls, configuration, storage access, and more. FlowState is available in tool handlers and hooks, providing a complete view of the execution context and utilities to modify it.FlowState Interface
Accessing FlowState
FlowState is passed as the first argument to tool handlers and hooks:- In Tools
- In Hooks
Key Properties
Identity
| Property | Type | Description |
|---|---|---|
threadId | string | Unique identifier for the conversation thread |
flowId | string | Unique identifier for this specific execution flow |
Configuration
| Property | Type | Description |
|---|---|---|
agentConfig | Agent | Complete agent configuration object |
currentSide | "a" | "b" | Which side is currently executing |
Execution State
| Property | Type | Description |
|---|---|---|
turnCount | number | Current turn number |
stopped | boolean | Whether execution has been stopped |
stoppedBy | "a" | "b" | undefined | Which side triggered the stop |
messageHistory | Message[] | Full conversation history |
Tool Queue
| Property | Type | Description |
|---|---|---|
sequence.queue | ToolCall[] | Pending tool calls to execute |
sequence.isHandling | boolean | Whether currently processing the queue |
Environment
| Property | Type | Description |
|---|---|---|
storage | DurableObjectStorage | Access to DurableObject SQLite storage |
env | ThreadEnv | Cloudflare environment bindings |
context | Record<string, unknown> | Arbitrary runtime state data |
Sub-Prompt Tracking
| Property | Type | Description |
|---|---|---|
rootState | FlowState | undefined | Reference to root FlowState (in sub-prompts) |
isChildPrompt | boolean | undefined | Whether this is a sub-prompt execution |