Skip to content
The AI Agent Factory

Chapter 34. Workers Delegate, Workflows Execute

Approved by
Panaversity ·
11 min read

The point

A worker should not do everything inside a conversation. In Chapter 33 you built an AP worker that handles one invoice in one conversation. It survives a crash and waits days for a person. That is the right shape for a question, a decision or a single payment.

Month-end reconciliation is a different kind of job. It has ten steps, takes hours, waits days for a review and must finish even if nobody is talking to the worker. It has a beginning and an end, and the finance team wants to see where it is. That is a business process, and it should run as one: with its own ID, its own record, its own retries and its own approvals.

So the rule of this chapter is short. The worker decides. A process carries out the work. The worker understands what was asked, checks that it may do it, and starts the right process. The process runs. When it ends, the worker explains the result.

Most work does not start with a person. Invoices arrive from the accounting system as web events. Reconciliation starts on the first of the month. This chapter also shows how that work arrives safely, and what happens when one worker has twenty conversations open at once.

A map of the Part IV platform in four rows, foundation at the bottom, then work, platform and learning, with economics as a column on the right. Highlighted as this chapter, Chapter 34: Workflows (month-end reconciliation); Events, schedules (per-worker coordinator). Already built in earlier chapters: The AP worker (one object per conversation); Waits, approvals (asleep, not paying); Harness (Pi Durable); Runtime (Durable Objects); Process engine (Cloudflare Workflows); Model access (any model, AI Gateway). Dashed, later in this part: Memory (facts, source, expiry); Dreaming (proposes candidates); Evaluation (held-out cases, new judge); Releases (approve, canary, roll back); Control plane (workers, versions, tenants); Model router (filter, then rank); Role contracts (one authorize check); Tenant walls (and proven deletion); economics (Chapter 37). A note at the foot says approved knowledge, case files and the governed door are stand-ins here, and Part VI replaces them with the systems of record.

Where this chapter sits in Part IV. The same map opens every chapter, with that chapter's parts highlighted.

Why it matters

This story is invented.

A finance manager asks an AP worker to reconcile November. The worker starts the job. A few seconds later the machine restarts, before the worker has written down the job's ID. The worker restarts, sees no record of a job, and starts another. Two reconciliations now run on the same month. Both write exception reports. Both send a reviewer an email. The reviewer approves one, rejects the other, and the published report depends on which one finished last.

Nobody wrote a bad line of code. The handoff between the worker and the process had no rule for "started, but not yet written down". This chapter is about that handoff, and about the other places where one worker's many parts can step on each other.

Words this chapter uses

The words of Chapters 32 and 33 keep their meaning: durable, checkpoint, Durable Object, replay-safe, idempotency key, signal, release.

WordMeaning
Business processA job with defined steps, a start and an end, such as a month-end reconciliation
WorkflowA program that runs a business process as saved steps, each retried on its own
DelegateTo hand a process to something else to run, and keep track of it
Process IDA stable name for one run of a process, such as recon-acme-2026-11
Web eventA message another system sends your Worker over the web when something happens, also called a webhook
ScheduleA rule that starts work at a time, such as "06:00 on the 1st"
QueueA list of messages waiting to be handled, so the sender does not wait
OutboxA table where a step writes the events it must send, in the same save as its own state
ConsumerThe code that takes events from an outbox or queue and handles each one once
CoordinatorOne object per worker that holds what all its conversations share: budget, locks, the stop switch
RevokeTo stop a worker everywhere, at once
Operation IDThe ID sent with each message to a conversation; Pi Durable accepts each one once (Chapter 33)
AssignmentOne piece of work the worker was given, such as Ana's request to reconcile November
Cron TriggerCloudflare's schedule for a whole Worker, which calls it at set times, in UTC
Lifecycle jobA timer for one conversation, kept by Lifecycle, which owns the conversation object's alarm
LockA claim on a business record, such as Acme's payment run, so only one holder acts on it at a time

What you will build

Where you are. Chapter 33 gave you Brightline's AP worker: one Durable Object per conversation, three invoice tools, an approval that waits for days, and a cost per invoice.

What you build, with Claude Code, from your own spec and failure tests:

  1. A web event endpoint for invoices that arrive from the accounting system, and a month-end schedule.
  2. The reconciliation Workflow: ten steps, from fetching invoices to telling the worker it is done.
  3. A safe handoff: a stable process ID, an outbox and a Postgres consumer that accepts each event once.
  4. A review that waits inside the Workflow, separate from the per-invoice approval of Chapter 33.
  5. A coordinator object for the worker: one budget, locks on business records and one switch that stops everything.

By the end of this chapter, you can decide which work belongs in a conversation and which in a process. You can build the handoff so it never starts a job twice. And you can keep many conversations of one worker inside one set of limits.

In this chapter

  • 34.1 Two kinds of durability
  • 34.2 Choosing the right mechanism
  • 34.3 How work arrives: web events and schedules
  • 34.4 Build the reconciliation Workflow with Claude Code
  • 34.5 The handoff that can go wrong
  • 34.6 Approval at two levels
  • 34.7 Many conversations, one worker
  • 34.8 Mistakes, limits and how today's tools realize it
  • Lab 34 The worker delegates, the Workflow executes

What this chapter is built on

The chapter follows section 7 and section 6.3 of Panaversity's paper Building Affordable, Self-Improving AI Workers (29 November 2026), and appendices A2 and A6 of its technical companion. Workflow costs come from the paper's cost model, model.ts. The Workflow, Queue, Cron and coordinator code in this chapter was tested on Wrangler's local runtime on 30 November 2026, but not yet on a deployed account. Check each API against the installed documentation, as CLAUDE.md tells Claude Code to.

Owner
Panaversity