Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d806255
Add Cloudflare Workflows integration to Agents
threepointone Jan 26, 2026
ba65fab
Add TestWorkflowAgent and workflow integration tests
threepointone Jan 26, 2026
505a853
Refactor workflow tracking to use metadata and improve callbacks
threepointone Jan 26, 2026
826de08
Add typed progress, approval, and state sync to workflows
threepointone Jan 26, 2026
347f9e1
Add workflow approval demo example
threepointone Jan 27, 2026
8d920f5
Remove PR reviewer notes and unused Env interface
threepointone Jan 27, 2026
ed64efa
Update brave-workflows-dance.md
threepointone Jan 27, 2026
4e7fb86
Fix metadata query to prevent SQL injection and add tests
threepointone Jan 27, 2026
ad034c3
Add workflow deletion methods and tests
threepointone Jan 27, 2026
85d2c49
Refactor workflow-agent communication to use internal RPC
threepointone Jan 27, 2026
e1056ba
Clarify return value in deleteWorkflows JSDoc
threepointone Jan 27, 2026
d5cb476
Handle duplicate workflow tracking with clear error
threepointone Jan 27, 2026
df7b3e5
Document workflow deletion methods in changeset
threepointone Jan 27, 2026
c3e423a
Introduce AgentWorkflowEvent type for cleaner workflow APIs
threepointone Jan 27, 2026
04f7b49
Rename 'olderThan' to 'createdBefore' in workflow deletion
threepointone Jan 27, 2026
7dae8c3
Refactor Agent workflow API to use workflow names
threepointone Jan 27, 2026
b5673f6
Add workflow binding migration and orphan detection
threepointone Jan 28, 2026
c63c5ae
Refactor approval progress reporting in workflows
threepointone Jan 28, 2026
c66826d
Add agentBinding option for explicit agent namespace binding
threepointone Jan 28, 2026
10d9201
Update workflow documentation for type imports and method name
threepointone Jan 28, 2026
7ab68ec
Refactor workflow status and timeout types
threepointone Jan 28, 2026
44845dd
Improve orphaned workflow warning with status breakdown
threepointone Jan 28, 2026
5c2e742
Update docs/workflows.md
threepointone Jan 28, 2026
dd144b9
Update docs/workflows.md
threepointone Jan 28, 2026
b4242ed
Update docs/workflows.md
threepointone Jan 28, 2026
07a8bde
Refactor AgentWorkflow to use durable step methods
threepointone Jan 28, 2026
5cab8f3
Merge branch 'workflows' of https://github.com/cloudflare/agents into…
threepointone Jan 28, 2026
12eeeab
Remove fetchAgent method from AgentWorkflow
threepointone Jan 28, 2026
a099119
Add resetAgentState to AgentWorkflowStep API
threepointone Jan 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .changeset/brave-workflows-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
"agents": patch
---

feat: Add Cloudflare Workflows integration for Agents

Adds seamless integration between Cloudflare Agents and Cloudflare Workflows for durable, multi-step background processing.

### Why use Workflows with Agents?

Agents excel at real-time communication and state management, while Workflows excel at durable execution. Together:

- Agents handle WebSocket connections and quick operations
- Workflows handle long-running tasks, retries, and human-in-the-loop flows

### AgentWorkflow Base Class

Extend `AgentWorkflow` instead of `WorkflowEntrypoint` to get typed access to the originating Agent:

```typescript
export class ProcessingWorkflow extends AgentWorkflow<MyAgent, TaskParams> {
async run(event: AgentWorkflowEvent<TaskParams>, step: AgentWorkflowStep) {
const params = event.payload;

// Call Agent methods via RPC
await this.agent.updateStatus(params.taskId, "processing");

// Non-durable: progress reporting (lightweight, for frequent updates)
await this.reportProgress({
step: "process",
percent: 0.5,
message: "Halfway done"
});
this.broadcastToClients({ type: "update", taskId: params.taskId });

// Durable via step: idempotent, won't repeat on retry
await step.mergeAgentState({ taskProgress: 0.5 });
await step.reportComplete(result);

return result;
}
}
```

### Agent Methods

- `runWorkflow(workflowName, params, options?)` - Start workflow with optional metadata for querying
- `sendWorkflowEvent(workflowName, workflowId, event)` - Send events to waiting workflows
- `getWorkflow(workflowId)` - Get tracked workflow by ID
- `getWorkflows(criteria?)` - Query by status, workflowName, or metadata
- `deleteWorkflow(workflowId)` - Delete a workflow tracking record
- `deleteWorkflows(criteria?)` - Delete workflows by criteria (status, workflowName, metadata, createdBefore)
- `approveWorkflow(workflowId, data?)` - Approve a waiting workflow
- `rejectWorkflow(workflowId, data?)` - Reject a waiting workflow

### AgentWorkflow Methods

**On `this` (non-durable, lightweight):**

- `reportProgress(progress)` - Report typed progress object to Agent
- `broadcastToClients(message)` - Broadcast to WebSocket clients
- `waitForApproval(step, opts?)` - Wait for approval (throws on rejection)

**On `step` (durable, idempotent):**

- `step.reportComplete(result?)` - Report successful completion
- `step.reportError(error)` - Report an error
- `step.sendEvent(event)` - Send custom event to Agent
- `step.updateAgentState(state)` - Replace Agent state (broadcasts to clients)
- `step.mergeAgentState(partial)` - Merge into Agent state (broadcasts to clients)
- `step.resetAgentState()` - Reset Agent state to initialState (broadcasts to clients)

### Lifecycle Callbacks

Override these methods to handle workflow events (workflowName is first for easy differentiation):

```typescript
async onWorkflowProgress(workflowName, workflowId, progress) {} // progress is typed object
async onWorkflowComplete(workflowName, workflowId, result?) {}
async onWorkflowError(workflowName, workflowId, error) {}
async onWorkflowEvent(workflowName, workflowId, event) {}
```

### Workflow Tracking

Workflows are automatically tracked in `cf_agents_workflows` SQLite table:

- Status, timestamps, errors
- Optional `metadata` field for queryable key-value data
- Params/output NOT stored by default (could be large)

See `docs/workflows.md` for full documentation.
Loading
Loading