Cloudflare Workflows for Agents

VerifiedSafe

Pair an agent with a durable Cloudflare Workflow for long-running tasks with retries and recovery.

Sby Skills Guide Bot
DevelopmentIntermediate
8/1/2026
Claude CodeCursorCodex
#cloudflare-workers#durable-execution#agent-framework#workflow-orchestration#typescript

Recommended for

Automated summary

This skill scaffolds a durable Cloudflare Workflow in `agents/<route>/workflow.ts` paired with an ayjnt agent, with the binding, typed RPC stub and `withWorkflow` mixin emitted by the framework.

Strengths

  • Simple file convention (workflow.ts next to agent.ts): the framework discovers the workflow at scan time and emits the binding, with no magic binding strings.
  • The curried `withWorkflow<W>()(Base)` mixin keeps typing end to end: params are checked and `this.agent` stays typed.
  • No migrations required: state lives in the paired Agent's Durable Object, while the workflow is just an ephemeral execution container.
  • Covers both modes: `AgentWorkflow` for typed RPC back to the agent and `WorkflowEntrypoint` for fire-and-forget jobs.

Limitations

  • Tightly coupled to the ayjnt framework: detection is a source-level regex that requires `extends AgentWorkflow` / `extends WorkflowEntrypoint` and rejects aliased imports.
  • The skill only covers co-located workflows; the section on workflows living outside the agent folder is cut off.
  • Little guidance on error handling and retry strategy beyond `step.do` and `step.sleep`.
When to use it

Use it when an ayjnt agent needs a long-running, durable, resumable job such as order processing or backoff retries that survive worker restarts.

When not to use it

Avoid it if the project doesn't use the ayjnt framework, or if the work is short enough to stay inside the agent's request handler.

Security analysis

Safe
Quality score82/100

This is purely technical documentation describing TypeScript code patterns for pairing agents with Cloudflare Workflows. It contains no executable shell commands, no destructive operations, no network exfiltration, no base64 payloads, and no attempts to disable safety controls. No tools are declared or invoked—the skill only presents illustrative code snippets that a developer would hand-write. Risk of listing is negligible.

No concerns found

How this analysis is made

Examples

Add a durable order workflow
Add a workflow to my orders agent: mark the order as running, call the payment API, then sleep 5 seconds before sending the confirmation.
Survive restarts with retries
Make my agent's order processing durable so it retries with backoff and survives worker restarts.
Trigger a workflow from the agent
Extend AgentWorkflow in agents/orders/workflow.ts and wire it up so onRequest can trigger it with a typed this.workflow(params) call.

name: ayjnt-workflows description: Pair an agent with a durable Cloudflare Workflow. Use when the user asks to "add a workflow", "run a long-running job", "extend AgentWorkflow", "make order processing durable", "retry with backoff", or "survive worker restarts". Creates agents/<route>/workflow.ts next to agent.ts; the framework wires the workflow binding, the typed RPC stub, and the GeneratedEnv field. Uses the withWorkflow<typeof MyWorkflow>()(Agent) mixin so the agent gets a typed this.workflow(params) shortcut with no magic binding strings. NO migrations — workflows are ephemeral execution containers; state lives in the paired Agent's DO.

Pair an agent with a workflow

workflow.ts next to agent.ts is the entire convention. The default-exported class extends AgentWorkflow (typed RPC back to the agent) or WorkflowEntrypoint (fire-and-forget). The framework discovers it at scan time and emits the binding.

File shape

// agents/<route>/workflow.ts
import { AgentWorkflow } from "agents/workflows";
import type { AgentWorkflowEvent } from "agents/workflows";
import type { WorkflowStep } from "cloudflare:workers";
import type MyAgent from "./agent.ts";

type Params = { /* user-defined params */ };

export default class MyWorkflow extends AgentWorkflow<MyAgent, Params> {
  async run(
    event: Readonly<AgentWorkflowEvent<Params>>,
    step: WorkflowStep,
  ): Promise<unknown> {
    const params = event.payload;

    await step.do("step-one", async () => {
      // durable work
      await this.agent.markStatus(params.id, "running");
    });

    const result = await step.do("step-two", async () => {
      // each step.do persists its return value
      return { something: "useful" };
    });

    await step.sleep("wait-a-bit", "5 seconds");

    return result;
  }
}

Rules

  • Default-export the class. ayjnt scans agents/**/workflow.ts files and reads the default export.
  • extends AgentWorkflow for typed RPC back to the agent. extends WorkflowEntrypoint when the workflow doesn't talk to an agent. ayjnt detects either.
  • Generic params: AgentWorkflow<AgentType, Params> — first arg is the paired Agent class (gives you this.agent with typed RPC); second is the workflow's payload type.
  • No aliased imports for the base class. The detection is source-level regex on extends AgentWorkflow / extends WorkflowEntrypoint.

Triggering from the agent

Use the withWorkflow mixin so you don't have to type the binding name. The framework knows the pairing from the file layout and injects the binding onto the agent's prototype at build time:

// agents/<route>/agent.ts
import { Agent } from "agents";
import { withWorkflow } from "ayjnt/workflow";
import type { GeneratedEnv } from "@ayjnt/env";
import type MyWorkflow from "./workflow.ts";

export default class MyAgent
  extends withWorkflow<typeof MyWorkflow>()(Agent)<GeneratedEnv, State>
{
  override async onRequest(req: Request): Promise<Response> {
    const params = await req.json();

    // No magic binding string — params type-checked against
    // MyWorkflow's Params generic. IntelliSense knows the shape.
    const workflowId = await this.workflow(params);

    return Response.json({ workflowId });
  }

  // The workflow calls this back via this.agent.markStatus(...)
  async markStatus(id: string, status: string): Promise<void> {
    this.setState({ /* … */ });
  }
}

Why curried

withWorkflow<W>()(Base) curries: the outer call binds the workflow type, the inner takes the base class. TypeScript can't partially infer one generic from a type arg and another from a value arg in a single call, so currying is the cleanest way to keep the syntax ergonomic while preserving Agent's <Env, State> parameterization downstream.

For non-co-located workflows

If a workflow lives outside the agent's folder (e.g. a fire-and-forget batch under a separate workflows/ tree), don't use the mixin. Call the SDK's runWorkflow directly with the binding name:

const workflowId = await this.runWorkflow("CLEANUP_JOB", params);

this.runWorkflow(binding, params) is provided by the SDK's Agent base class. The binding is type-checked against bindings ayjnt generated.

Name derivation

Class name drives everything:

  • OrdersProcessing → binding ORDERS_PROCESSING
  • OrdersProcessing → workflow name orders-processing (kebab)
  • OrdersProcessing → class_name: "OrdersProcessing"

Bindings must be unique across agents and workflows; the scanner errors at build time if two classes would collide.

What gets generated

// .ayjnt/dist/wrangler.jsonc
"workflows": [
  {
    "name": "orders-processing",
    "binding": "ORDERS_PROCESSING",
    "class_name": "OrdersProcessing"
  }
]
// .ayjnt/env.d.ts
export type GeneratedEnv = {
  ORDERS_AGENT: DurableObjectNamespace<OrdersAgent>;
  ORDERS_PROCESSING: Workflow;  // ← workflow binding, typed
};
// .ayjnt/dist/entry.ts
import OrdersProcessing from "../../agents/orders/workflow.ts";
export { OrdersProcessing };  // Cloudflare runtime registers the class

Workflows ≠ Durable Objects

  • No entries in migrations[]. Workflows are ephemeral execution containers. The framework will refuse to add a workflow class to the SQLite migrations.
  • State lives in the paired Agent's DO. Workflows don't have this.state. If you need state, RPC back into the agent and have it call setState.

step.do contract

Each step.do("name", fn) block is:

  • Idempotent across retries — if fn throws, the framework retries with exponential backoff. If the worker restarts, execution resumes from the last successful step using the persisted return value.
  • Keyed by name. Renaming a step in a deployed workflow makes the runtime think it's a new step and re-execute it. Treat step names like database column names — stable across deploys.

step.sleep("name", duration) also survives restarts.

Pair with a UI

The agent ⇄ workflow loop is naturally visible — each step.do flips the order's status, which broadcasts over WebSocket. Drop an app.tsx next to the agent and use the generated useAgent hook:

// agents/<route>/app.tsx
import { useAgent } from "@ayjnt/orders";

export default function OrdersUI() {
  const agent = useAgent();
  const orders = (agent.state as { orders?: Order[] })?.orders ?? [];
  // call agent.call("placeOrder", [{ sku, qty, customerId }]) on submit
  // render orders with their live status
}

Make the agent's trigger method @callable({ description: "..." }) so the UI can drive it via agent.call(method, args) without going through fetch.

Looking up a running workflow

// Inside the agent
const instance = await this.env.MY_WORKFLOW.get(workflowId);
const status = await instance.status();
// → { status: "running" | "complete" | "errored" | ..., output?: ... }

When NOT to use a workflow

  • The task is a single fetch + return → just do it in the agent.
  • The task is a stateless background side-effect → use{" "} this.ctx.waitUntil(fetch(...)).
  • The task needs millisecond-precision orchestration → workflows have per-step overhead; use the agent's scheduler instead.

Reach for workflows when you want durable, multi-step, retry-aware execution.

Reference

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/cloudflare-workflows-for-agents-ms9wny4n/download' --output '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md.part' && mv '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md.part' '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md' && test -s '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/ayjnt-workflows' && cp -R '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n' '.claude/skills/ayjnt-workflows'

Cursor
test -f '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md' && test -s '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/ayjnt-workflows' && cp -R '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n' '.cursor/skills/ayjnt-workflows'

Codex
test -f '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md' && test -s '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/ayjnt-workflows' && cp -R '.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n' '.agents/skills/ayjnt-workflows'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/cloudflare-workflows-for-agents-ms9wny4n'

openskills read 'cloudflare-workflows-for-agents-ms9wny4n'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/cloudflare-workflows-for-agents-ms9wny4n/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills