Skip to content
The AI Agent Factory

34.2 Choosing the right mechanism

Approved by
Panaversity ·
9 min read

In everyday life. You do not hire a removal company to carry a chair to the next room. You do not carry a piano downstairs by yourself either. The size and risk of the job decide the tool.

What you will learn. Six ways to run a piece of work on the open stack, how to choose the lightest one that is safe, and how each foundation hands work to a process.

Why it matters. A Workflow for every small job adds cost, code and places to fail. No Workflow for a big job loses work. The choice is a design decision you should be able to explain.

Six mechanisms, lightest first

MechanismUse it forExample in the AP worker
Direct tool callA short action with an immediate resultLook up an invoice
Pi Durable taskRecoverable work inside the current conversation: a tool call Pi saves as a step, as in Chapter 33Post one approved invoice
Lifecycle jobA timer or deferred job for one conversation, run by Lifecycle, which owns the object's alarm (34.3)"Remind me on Friday if Ana has not answered"
FiberRecoverable application work tied to one object, from Cloudflare's Agents SDKNot used in this part; test it yourself before you rely on it
QueueTaking in events fast, and handling them in the backgroundInvoices arriving from the accounting system
WorkflowA process with several steps, long waits, its own retries, or a life beyond the conversationMonth-end reconciliation

Start at the top of the table and move down only when the job needs it.

When a Workflow is worth it

Use a Workflow when one or more of these is true:

  • The job must have its own life, start to end, separate from the conversation.
  • It has several business steps, and each can fail and be retried on its own.
  • Different steps need different retry rules: retry a slow API five times, but never retry a payment without checking first.
  • It may wait a long time: days for a reviewer, a week for a supplier.
  • It must finish even if nobody talks to the worker again.
  • People need to see its progress and know when it is done.

About 30 seconds is a useful rough guide. A job that usually finishes in a few seconds probably belongs in a tool. A job that takes minutes or hours probably does not. It is a guide, not a rule: a ten-second job that must outlive the conversation still needs a Workflow.

A person's approval alone is not a reason. Since Pi 1.6, a tool can wait days for a person without keeping the object awake. Whether the approval belongs in a Workflow depends on what is being approved, as 34.6 explains.

What a Workflow costs

Little. The paper prices the medium worker at about 2,400 Workflow steps a month, which is about $0.02 a month on Cloudflare's paid plan prices. On the free plan you pay nothing while you learn. The cost of a Workflow is not money. It is the code you write and keep for the handoff, which the next pages cover.

How each foundation hands work to a process

Checked on 29 November 2026.

Claude Managed Agents. A session can start an outside process through a tool, and wait for its result. The process itself lives outside Anthropic, on whatever runs your business processes. Chapter 23 showed schedules and web events with Claude Managed Agents. The handoff problem in 34.5 is the same there: the tool must start the process once, with a stable ID.

OpenAI Agents SDK. The SDK runs the agent loop. For a durable process it hands off to a workflow engine. Some durable workflow engines offer integrations with the Agents SDK; check which languages and versions they support before you choose one. As Chapter 32 showed, the SDK itself saves state only at a pause.

The open stack. Cloudflare Workflows. A Workflow is a class with a run method. Each step.do is saved when it finishes and retried on its own if it fails. step.sleep and step.waitForEvent wait without running. Workflow state is kept for a limited time after it ends: 3 days on the free plan, and 7 days by default on the paid plan, up to 30. So the lasting record of each run goes in your own Postgres table.

Claude Managed AgentsOpenAI Agents SDKOpen stack
Where the process runsOutside Anthropic, your choiceA workflow engine you addCloudflare Workflows
Who writes the handoffYouYouYou
Can the agent and the process share one store?NoDepends on your engineNot in one transaction

The last row is why 34.5 exists. On every foundation, the agent's state and the process's state live in different places, and no transaction covers both.

The invariant. Use the lightest mechanism that is safe. A Workflow earns its place when the job has steps, waits or a life of its own.

Check yourself. The worker must email a supplier a copy of a rejected invoice. It takes one call and two seconds. Workflow or not? (Not. It is a single short action. Make it a Pi Durable task with a saved idempotency key, so the email is not sent twice after a crash.)

Owner
Panaversity