Deploy with Vercel Workflows
Orchestrate a durable agent run with host-owned model and tool steps.
Use @yolk-sdk/vercel-workflows when a run can outlive one request or pause for human input.
Workflow wrapper
import { createHook } from 'workflow'
import { runVercelAgentWorkflow } from '@yolk-sdk/vercel-workflows'
export async function runAgentWorkflow(input: { request: unknown; context: unknown }) {
'use workflow'
return await runVercelAgentWorkflow({
input,
runModelStep,
runToolBatchStep,
closeStream,
writeError,
awaitInput: async awaitingInput => {
using hook = createHook<unknown>({ token: awaitingInput.hookToken })
return await hook
}
})
}runModelStep, closeStream, and writeError are app-owned 'use step' functions.
runToolBatchStep may also be a step, or it may orchestrate separate tool steps and independent
child Workflow starts. Keep provider calls, tool IO, storage, and Effect work inside steps; do not
wrap a whole child loop in one parent step. See
Independent child orchestration.
Code mode
Run code mode calls inside your tool-batch step, never in the
'use workflow' function. Executor decorators applied outside ResolvedToolSet.execute, such as a
Workflow stop or run-admission check, do not see nested calls; pass the same check to
makeCodeModeTool as beforeNestedCall.
Calls applied from a staged tool plan bypass both
those decorators and beforeNestedCall: pass the same check to makePlanReviewTool as
beforeCall. A step redelivered while a plan applies waits for the running apply when the review
step is resolved with the same tool ledger scope on every delivery; keep ledger entries as long as
the review receipts.
Tool steps run at least once
Vercel's queue can deliver a tool-batch step again after a crash, or while the first execution is
still running, even with the default noWorkflowStepRetry. Supply a durable tool ledger, scoped
to the Workflow run, where your step resolves tools:
// Fragment from your tool-batch step module. `modules`, `context`, `makeRunToolLedger`,
// `workflowRunId`, and `stepDeadlineMs` are host-owned.
import { Effect } from 'effect'
import { resolveTools } from '@yolk-sdk/agent/tools'
// Inside the 'use step' function:
const toolSet = await Effect.runPromise(
resolveTools(modules, context, {
ledger: { store: makeRunToolLedger(workflowRunId), deadline: () => stepDeadlineMs }
})
)makeRunToolLedger is your ToolLedgerStore (for example Postgres); see
Ledger writes. Ledgered calls (by
default every non-read tool plus the built-in subagent tool, code mode scripts included) then
return their stored result, wait for the running execution, or report that an abandoned call may
already have been applied; they never run twice under the same ledger key. Include custom
delegation tools with isLedgered. Read calls still re-run. The package itself never builds tool
sets, so there is nothing to configure on runVercelAgentWorkflow.
deadline bounds only waiting for a duplicate execution; it does not stop a call that runs.
Recording a call's outcome can take up to about 15 s after the call returns (three 5 s attempts),
so set stepDeadlineMs to leave that finalization time before the function budget ends. Keep
the store's operations interruptible (for example Effect.tryPromise passing the AbortSignal to
the driver): the ledger's timeouts cannot cut uninterruptible store work.
Durable stream rule
Use distinct finalization paths:
AgentEnd: durable completion commit -> AgentEnd -> closeStream
AgentError: failure commit/mapping -> AgentError -> writeError-owned close
AgentAwaitingInput: persist pending HITL -> emit pause -> release writer lock, do not close -> resumeUse sequenceDurableAgentEvent for deterministic event ids without IO,
writeDurableAgentEvent for id + NDJSON write, and commitThenWriteTerminalEvent for terminal
barriers. The helper never decides closure from an event tag. The loop closes only successful runs;
writeError must write the safe final error and close failure paths.