Workflows
Build multi-step, durable pipelines with automatic retries and checkpointing, powered by Cloudflare Workflows.
workflow() API
TypeScript
1import { workflow, step } from 'honidev'
2
3function workflow(config: WorkflowConfig): Workflow
4function step(name: string, config: StepConfig): Step
StepConfig
| Field | Type | Default | Description |
|---|---|---|---|
retries | number | 3 | Number of retry attempts on failure |
timeout | string | '30s' | Max duration per attempt (e.g. '30s', '5m') |
backoff | 'linear' | 'exponential' | 'exponential' | Retry backoff strategy |
run | (input, ctx) => Promise<any> | - | Step execution handler |
Callbacks
| Callback | When | Arguments |
|---|---|---|
onComplete | All steps finish successfully | (results: StepResult[]) => void |
onError | A step exhausts all retries | (error: Error, stepName: string) => void |
Example: Research Pipeline
TypeScript
1import { workflow, step } from 'honidev'
2
3export const researchPipeline = workflow({
4 name: 'research',
5
6 steps: [
7 step('gather', {
8 timeout: '2m',
9 async run(input, ctx) {
10 // Fetch data from multiple sources
11 const sources = await fetchSources(input.topic)
12 return { sources }
13 }
14 }),
15
16 step('analyze', {
17 retries: 2,
18 async run(input, ctx) {
19 // Use LLM to analyze gathered data
20 const analysis = await ctx.llm('Analyze these sources...', input.sources)
21 return { analysis }
22 }
23 }),
24
25 step('summarize', {
26 async run(input, ctx) {
27 const summary = await ctx.llm('Summarize the analysis...', input.analysis)
28 return { summary }
29 }
30 })
31 ],
32
33 onComplete(results) {
34 console.log('Research complete!', results)
35 },
36
37 onError(error, stepName) {
38 console.error(`Step ${stepName} failed:`, error)
39 }
40})
wrangler.toml Binding
Workflows require a binding in your wrangler.toml:
TOML
1[[workflows]]
2name = "research"
3binding = "RESEARCH_WORKFLOW"
4class_name = "ResearchPipeline"