Overview
AgentWorkflow extends Cloudflare’s WorkflowEntrypoint to provide seamless access to the Agent that started the workflow, enabling bidirectional communication and typed RPC.
Type Parameters
Agent
default:"Agent"
The Agent class type (for typed RPC access)
unknown
default:"unknown"
User-defined params passed to the workflow
DefaultProgress
default:"DefaultProgress"
Type for progress reporting
Cloudflare.Env
default:"Cloudflare.Env"
Environment type
Properties
agent
DurableObjectStub<AgentType>
required
The Agent stub for RPC calls. Provides typed access to the Agent’s methods.
workflowId
string
required
Workflow instance ID (from Cloudflare Workflows)
workflowName
string
required
Workflow binding name (from environment)
Lifecycle
run()
AgentWorkflowEvent<Params>
required
Workflow event with user-defined params
AgentWorkflowStep
required
Durable step object with Agent communication methods
Promise<unknown> - Workflow result
AgentWorkflowStep
Thestep parameter is a standard WorkflowStep extended with Agent communication methods:
step.reportComplete()
Report successful completion to the Agent.T
Result data to send
Promise<void>
step.reportError()
Report an error to the Agent.Error | string
required
Error to report
Promise<void>
Errors are automatically reported if a workflow throws without explicitly calling
reportError().step.sendEvent()
Send a custom event to the Agent.T
required
Event data to send
Promise<void>
step.updateAgentState()
Replace the Agent’s entire state.unknown
required
New state
Promise<void>
step.mergeAgentState()
Merge partial state into the Agent’s state.Record<string, unknown>
required
Partial state to merge
Promise<void>
step.resetAgentState()
Reset the Agent’s state to initialState.Promise<void>
Protected Methods
reportProgress()
Report typed progress to the Agent.ProgressType
required
Typed progress data
broadcastToClients()
Broadcast a message to all connected WebSocket clients via the Agent.unknown
required
Message to broadcast (will be JSON-stringified)
waitForApproval()
Wait for approval from the Agent.AgentWorkflowStep
required
Step object
WaitForApprovalOptions
Promise<T> - Approval metadata
Throws: WorkflowRejectedError if rejected
Running Workflows from Agents
runWorkflow()
Start a workflow from an Agent.approveWorkflow()
Approve a waiting workflow.rejectWorkflow()
Reject a waiting workflow.Agent Callbacks
onWorkflowProgress()
Called when a workflow reports progress.onWorkflowComplete()
Called when a workflow completes successfully.onWorkflowError()
Called when a workflow errors.Full Example
Related
- Agent Class - Agent workflow methods
- Cloudflare Workflows - Workflows documentation