Skip to main content
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.

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

Server Implementation

Agent

src/server.ts

Workflow

src/server.ts

How It Works

1

Submit task

The client calls agent.submitTask(taskName), which creates a new workflow and returns a WorkflowItem with the initial state.
2

Workflow runs

The workflow executes through multiple steps: validate, process, approval, finalize. Each step reports progress via reportProgress().
3

Progress updates

Progress updates trigger onWorkflowProgress(), which broadcasts to all connected clients in real-time.
4

Wait for approval

The workflow pauses at waitForApproval(). The UI shows approve/reject buttons.
5

User approves/rejects

The client calls agent.approve(workflowId) or agent.reject(workflowId). The workflow resumes or terminates.
6

Completion

When the workflow finishes, onWorkflowComplete() fires, broadcasting the final result.

Key Concepts

Multi-Workflow State

The agent maintains workflow state in SQLite via the cf_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:
The UI renders approve/reject buttons for each waiting workflow:

Running the Example

1

Install dependencies

2

Generate types

3

Start development server

4

Try it out

Open http://localhost:5173 and:
  1. Enter a task name and click “Start Task” (you can start multiple)
  2. Watch progress updates in real-time
  3. When a workflow reaches the approval step, approve or reject it
  4. See the workflow complete and show results
  5. Dismiss completed workflows or clear all completed at once

Workflow Lifecycle

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