Demonstrates the workflow integration features of Cloudflare Agents - multiple concurrent workflows, real-time progress updates, human-in-the-loop approval gates, and paginated workflow management.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/agents/llms.txt
Use this file to discover all available pages before exploring further.
What it demonstrates
- Multiple concurrent workflows - Start and track many tasks simultaneously
- Real-time progress updates via WebSocket
- Human-in-the-loop approval gate per workflow
- Paginated workflow list with status tracking via
getWorkflows() - Per-workflow approve/reject controls in the UI
- Workflow lifecycle callbacks - progress, completion, error handling
Features
| Feature | API Used |
|---|---|
| Start workflow | agent.runWorkflow() |
| Query workflows | agent.getWorkflows() |
| Typed progress | workflow.reportProgress({ step, status, percent, message }) |
| Wait for approval | workflow.waitForApproval(step, options) |
| Approve workflow | agent.approveWorkflow(id, data) |
| Reject workflow | agent.rejectWorkflow(id, data) |
| State sync | workflow.mergeAgentState(partial) |
| Progress callbacks | agent.onWorkflowProgress() |
| Completion callbacks | agent.onWorkflowComplete() |
Server Implementation
Agent
src/server.ts
Workflow
src/server.ts
How It Works
Submit task
The client calls
agent.submitTask(taskName), which creates a new workflow and returns a WorkflowItem with the initial state.Workflow runs
The workflow executes through multiple steps: validate, process, approval, finalize. Each step reports progress via
reportProgress().Progress updates
Progress updates trigger
onWorkflowProgress(), which broadcasts to all connected clients in real-time.User approves/rejects
The client calls
agent.approve(workflowId) or agent.reject(workflowId). The workflow resumes or terminates.Key Concepts
Multi-Workflow State
The agent maintains workflow state in SQLite via thecf_agents_workflows tracking table:
Tracking Table Integration
getWorkflows()retrieves tracked workflows with pagination (default limit 50)- Callbacks (
onWorkflowProgress,onWorkflowComplete,onWorkflowError) update both the tracking table and broadcast to clients - Metadata (like
taskName) is persisted for display after page refresh
Per-Workflow Approval
Each workflow independently waits for approval:Running the Example
Try it out
Open http://localhost:5173 and:
- Enter a task name and click “Start Task” (you can start multiple)
- Watch progress updates in real-time
- When a workflow reaches the approval step, approve or reject it
- See the workflow complete and show results
- Dismiss completed workflows or clear all completed at once
Workflow Lifecycle
Related Examples
AI Chat
AI chat with tool approval (similar pattern)
Email Agent
Process emails with state management
GitHub Webhook
Handle webhooks with event storage
Workflows Guide
In-depth guide to workflow patterns