Internal. Not a public API. Nothing new from the slim-hosts work is exposed to apps until it has shipped inside Think and AIChatAgent for a release and is shown correct (rfc-slim-hosts.md). It is not exported at all: Agent installs it and delegates its public methods to it.
It tracks and controls Cloudflare Workflows instances. Workflows is a separate product: the instances run on the Workflows service, not in the agent's Durable Object. This module is not an execution engine. It starts instances, sends them events, pauses, resumes, terminates and restarts them, and keeps a local record of each one. For durable multi-step work that runs inside the Durable Object (steps journaled in its SQLite, retries, durable sleeps), use Tasks instead. Use Workflows when the work should run outside the object, for long or heavy pipelines, or when you already have a Workflow.
Agent.runWorkflow() starts a Cloudflare Workflow instance on the agent's behalf, and the agent keeps a record of every instance it started. The control methods (sendWorkflowEvent, approveWorkflow, rejectWorkflow, terminateWorkflow, pauseWorkflow, resumeWorkflow, restartWorkflow, getWorkflowStatus) and the record queries (getWorkflow, getWorkflows, deleteWorkflow, deleteWorkflows, migrateWorkflowBinding) are one-line delegates to the Workflows Lifecycle capability in packages/agents/src/workflow-tracking/. The hooks stay on Agent: onWorkflowCallback, onWorkflowProgress, onWorkflowComplete, onWorkflowError, onWorkflowEvent, and the _workflow_* RPC methods AgentWorkflow calls. AgentWorkflow itself is in src/workflows.ts.
Agent installs it with the Worker env and a function that names the owner: a top-level agent by class and name, or a facet by its path from the root.
- Durable:
cf_agents_workflows, one row per instance started throughrun(): id, instance id, binding name, status, metadata, error, created/updated/completed times. The capability creates it on first use under the KV keycf_agents:workflows_schema_version. - In memory: nothing.
The Workflows service holds the real status of an instance. The row mirrors it and can lag: it changes when a control call reads the status back, when getWorkflowStatus() runs, and when an AgentWorkflow callback arrives (record()).
run() finds the Workflow binding in env, works out the origin callbacks route back to, and calls workflow.create() with the owner's identity in the params (__agentName, __agentBinding, __workflowName, __agentOrigin; built by workflowCreateOptions()). The origin is { kind: "agent", binding, name }, or for a facet { kind: "facet", rootBinding, path }. The binding is options.agentBinding or the env namespace whose name matches the class name (exact, or equal in kebab case). Then it inserts the row as queued.
onWorkflowCallback() calls record(callback) and then the matching hook. record() applies these rules:
progressmovesqueuedorwaitingtorunning.completeanderrornever overwriteterminatedorpaused. A pause or terminate that raced the workflow's own last report keeps the state the caller asked for.eventchanges nothing.
A subclass that overrides onWorkflowCallback() without calling super skips the record update, as before.
On start the capability warns about rows whose binding is not in env any more, usually a renamed binding, and suggests migrateWorkflowBinding().
approveWorkflow()andrejectWorkflow()send their event through the capability, not throughthis.sendWorkflowEvent(). A subclass override ofsendWorkflowEvent()no longer sees approvals.- The control methods read the record through the capability, not
this.getWorkflow(), so a subclass override ofgetWorkflow()changes what it returns, not which instance a control call acts on. - Pagination is keyset on
(created_at, workflow_id).totalcounts every match and ignores the cursor.