a workflow in the back seat, nagging your agent through every step
Graph-based workflows for coding agents.
A workflow is a graph: states, the transitions between them, and the instructions for each. The agent you already use drives it from its own shell: it reaches a state and is told what to do there and which transitions are open, and anything else is refused with a reason. A long prompt describes the steps; this holds the agent to them.
paste into your coding agent
Install the backseat-ai skill: `npx skills add pottedmeat/backseat-ai --skill backseat-ai`. Then help me build a Backseat workflow for: [what you want done]. Interview me before you write anything: what the steps are, what has to be true before moving from each step to the next, and what a finished run produces. Then write the workflow, lint it, and walk me through one run.
paste into your coding agent
Install the backseat-ai skill: `npx skills add pottedmeat/backseat-ai --skill backseat-ai`. Then turn the workflow in [file, or paste it] into a Backseat workflow. First list the states and transitions you read in it, and ask me about anything it leaves open: which steps can repeat, what has to be checked before moving on, what counts as done. Don't add rules it doesn't state. Then write the workflow, lint it, and walk me through one run.
A workflow (a machine, in the code) is a TypeScript file in your project, driven through a small CLI (cli.ts, written into the project for you) from Claude Code, pi, opencode or whichever coding agent you use. The agent's commands are the ones under --drive. Nothing runs between calls.
The green signs on this page are snippets of one real workflow. A coding agent drives it, though the work is research: a lead agent that cuts a question into sub-tasks, sends a subagent, a worker, after each, and writes up what comes back.
$ node cli.ts --drive send 1b36b700…/task-1-3 search.results -{
"query": "Bass Pro Shops Springfield Missouri kids fishing pond Lake Springfield"
}Write a finding that answers `data.subQuestion` from the hits you gathered, listing only the sources you actually drew on. … ## To move to state: complete (The sub-task is finished, with a finding or a stated absence.) ### finding.submit → complete (The sub-question is answered.) summary: string // min length 80 sources: { url: string // uri title: string // min length 1 }[] // min 1 items ### finding.empty → complete (Nothing found supports an answer.) reason: string // min length 80 ## To move to state: searching (Queries are being worked one at a time.) ### search.resume → searching (The hits do not yet answer it.) queries: string[] // min 1 items, each: min length 3 --- 1b36b700…/task-1-3 · at summarizing · active
I've seen how you drive without me
Backseat came from wanting more from workflows that ran on instructions alone. Each was a long prompt describing the steps, and even a frontier model treated it as a description: mostly followed, never enforced. The want was a workflow that holds its shape whichever model is in it.
So the shape is written down and enforced. You decide what can happen: the states, the transitions out of each, the guard on each one (a condition that has to hold before it is offered), the schema it must be sent with. The model decides what does. The workflow is semi-deterministic: the steps and the routes between them are fixed, and the model's judgment fills the rest, what it does inside a step and, where more than one transition is open, which one it takes.
It is LangGraph with the roles reversed. A framework like LangGraph drives inference calls: your code calls the model at each node and reassembles the messages and context for the next. Backseat drives a conversation: the agent you are already talking to runs one command, reads what the workflow says, does the work with its own tools, and asks again.
What is enforced is the path. The workflow cannot stop an agent from walking away, and it does not see how the work was done. It never advances on anything but a transition it offered, sent with a payload that passed.
A model handed one step at a time, with its instructions and its schema, and refused with a reason when it strays, runs a workflow it could not have run from the prompt. It does not have to be a frontier model. Because each response carries only one state's instructions and data, a smaller model has a short, specific prompt at every step instead of one long one to keep in mind.
I'll tell you everything, once we're on the road
Most agents start under a wall of instructions: every rule, every step, every case, read before anything has happened and carried through everything after. Here there is nothing to read first. The agent starts the workflow as an actor, a running instance with an id of its own, and from then on it is told what it needs when it needs it: what to do in the state it is in, which transitions are open from there, and nothing about the rest of the workflow until it gets there.
the agent sees · the first call of the run: one instruction, one transition and its schema
$ node cli.ts --drive create deep-research… State the research question verbatim as you were given it. ## To move to state: planning (The question is known; this round needs sub-tasks.) ### brief.submit → planning (The question is stated.) question: string // min length 10 … --- 1b36b700… · at briefing · active
don't worry, I wrote it down
Everything the workflow knows lives in one ledger (context in the code): the question, the round it is on, the sub-tasks still queued, the findings so far, each kept as it was written for as long as the run lasts. A transition writes to it; a state reads from it. A state declares data: the part of the ledger the agent is handed while it is there, computed each time it arrives. A line written on the third call reads the same on the sixty-ninth, sixty-six calls and six workers later, so the agent is shown the ledger, not its recollection of it. What a state does not declare stays hidden.
context: () => ({ question: '', round: 0, … }), planning: { on: { 'plan.submit': { // Writes to the ledger. actions: assign(({ context }) => ({ round: context.round + 1, … })), }, }, // Reads the ledger for the agent: only these values reach it. The round shown is the one being planned. data: ({ context, event }) => ({ round: context.round + 1, maxRounds: context.maxRounds, … }), }, … reviewing: { // Sixty-six calls and six workers later: the ledger as written, down to what the workers reported. data: ({ context: { question, round, maxRounds, findings, unanswerable, failed } }) => ({ question, round, maxRounds, findings: withFiles(findings), unanswerable, failed }), … },
{
"question": "Where is the best place to take my kids fishing in Branson, MO?",
"round": 0,
"maxRounds": 4
}$ node cli.ts --drive send 1b36b700… brief.submit -{
"question": "Where is the best place to take my kids fishing in Branson, MO?"
}You are planning round `data.round` of at most `data.maxRounds`. Start broad: a first round maps the ground — which candidates, sources and angles exist — rather than trying to settle the answer, and later rounds add depth aimed at what it turns up. … ## Data - round: number 1 - maxRounds: number 4 … --- 1b36b700… · at planning · active
$ node cli.ts --drive send 1b36b700… research.review… ## Data - question: string Where is the best place to take my kids fishing in Branson, MO? - round: number 1 - maxRounds: number 4 - findings: array ```json [ { "actorId": "1b36b700…/task-1-1", "subQuestion": "Which Branson-area fishing spots are free or low-cost, with fishing docks, piers or bank access suitable for young children (e.g., Table Rock State Park dock, Moonshine Beach, Branson Landing)? Cover only access, safety and cost, not guided trips.", "sources": [ … ], "file": "…/task-1-1.md" }, … ] ``` … --- 1b36b700… · at reviewing · active
I'll tell you what to do when we get there
Every state and every transition carries a one-line description: a clarification of what it is, read while the agent is choosing. There are no instructions in it. Instructions are what a state hands the agent by being reached. So the agent commits to a transition before it reads a word of what it will be asked to do there, and the instructions for the roads not taken never enter its context. A state's instructions are also told which visit this is. The first visit explains the whole job; every return, with that explanation still in the agent's context, gets one line that points back to it.
searching: {
on: {
'search.results': {
target: 'summarizing',
// A clarification of the transition, read while choosing. No instructions here.
description: 'That was the last query.',
…
},
},
},
summarizing: {
// A clarification of the state, read while choosing. No instructions here.
description: 'Every query has been answered; the sub-task needs a written finding.',
// Handed to the agent on arrival. The function is given the ledger and which visit this is.
instructions: ({ visit }) =>
visit === 'first'
? 'Write a finding that answers `data.subQuestion` from the hits you gathered, …'
: 'Conclude on `data.subQuestion`: write the finding, say that nothing supports an answer, or resume the search.',
},$ node cli.ts --drive send 1b36b700…/task-1-3 search.results -{
"query": "Roaring River State Park trout fishing kids Cassville Missouri"
}… ## To move to state: summarizing (Every query has been answered; the sub-task needs a written finding.) ### search.results → summarizing (That was the last query.) …
$ node cli.ts --drive send 1b36b700…/task-1-3 search.results -{
"query": "Bass Pro Shops Springfield Missouri kids fishing pond Lake Springfield"
}Write a finding that answers `data.subQuestion` from the hits you gathered, listing only the sources you actually drew on. `data.question` is the research question it was cut from: it tells you what the finding will be read for, not what to answer. If the hits are too thin, or what the finding turns on rests on snippets you could still read at the source, resume the search with further queries instead. Say in the finding which facts came from snippets alone. If you have searched and nothing you found supports an answer, say so and give the reason: do not pad a finding out, and do not list a source you would not stand behind. A stated absence is worth more to the lead than a finding you do not believe.
…we're not taking the exit until you say which one and why
The agent takes a transition by sending its event, and the schema is what that event has to carry, its payload: printed under the transition while the agent is still choosing, so the proof is never a guess. It can be computed from the ledger, so what a checkpoint asks for can depend on where the run is.
const source = z.object({ url: z.url(), title: z.string().min(1) }) summarizing: { on: { 'finding.submit': { target: 'complete', description: 'The sub-question is answered.', // The checkpoint: no finding and no source, no leaving this state. schema: z.object({ summary: z.string().min(80), sources: z.array(source).min(1) }), … }, 'finding.empty': { target: 'complete', description: 'Nothing found supports an answer.', // The other way out, with its own proof: a reason, not a shrug. schema: z.object({ reason: z.string().min(80) }), … }, }, },
$ node cli.ts --drive send 1b36b700…/task-1-3 search.results -… ## To move to state: complete (The sub-task is finished, with a finding or a stated absence.) ### finding.submit → complete (The sub-question is answered.) summary: string // min length 80 sources: { url: string // uri title: string // min length 1 }[] // min 1 items ### finding.empty → complete (Nothing found supports an answer.) reason: string // min length 80 …
$ node cli.ts --drive send 1b36b700…/task-1-3 finding.submit -{
"summary": "All findings come from search-result snippets only; no pages were fetched. Shepherd of the Hills Fish Hatchery (483 Hatchery Rd, Branson, 417-334-4865) is the strongest kid option: …",
"sources": [
{ "url": "https://mdc.mo.gov/newsroom/mdc-invites-young-anglers-kids-fishing-day-june-7-shepherd-hills", "title": "MDC invites young anglers to Kids Fishing Day at Shepherd of the Hills" },
…
]
}The result is reported to the lead. Nothing further is asked of you here.
This actor is done. Nothing more can be sent.
---
1b36b700…/task-1-3 · at complete · donehold on, I've got a gadget for that
Some of the work in a workflow is not the agent's to do: a lookup, a call to a service, a judgment the workflow would rather make itself. Backseat puts that work on the transition, as an effect: it runs when the agent takes the transition, after the checks have passed. Whatever the tool brings back is attached to the event as its output, and the author decides what of it goes into the ledger and what goes straight to the agent. The agent sends the event and reads what came back; it never holds the tool.
briefing: {
on: {
'brief.submit': {
target: 'planning',
schema: z.object({ question: z.string().min(10) }),
// The effect: how many rounds the question warrants, judged from the question, not set by the agent.
effect: ({ event }) => judgeMaxRounds(event.question),
// event.output is what the effect returned. The actions keep the part the run needs later.
actions: assign({
question: ({ event }) => event.question,
maxRounds: ({ event }) => event.output.rounds,
}),
},
},
},
planning: {
// The landing state's data: the budget from the ledger on every visit, and once, from the effect, why it is what it is.
data: ({ context, event }) => ({
round: context.round + 1,
maxRounds: context.maxRounds,
...(event?.type === 'brief.submit' && { budget: event.output.budget }),
}),
…
},$ node cli.ts --drive send 1b36b700… brief.submit -… ## Data … - maxRounds: number 4 - budget: string Four rounds at most: the candidates have to be found first, then each examined in turn. … --- 1b36b700… · at planning · active
I looked it up. they're closed
While a guard can keep a transition from being shown, some reasons to refuse are only found partway through the transition: an effect, or an action writing to the ledger, finds one and says so in the author's words. The workflow rejects the event with that message, says the actor has not moved, and prints the arrival again, so the next call is the corrected one.
import { backseat, RejectedEvent } from 'backseat-ai' 'finding.submit': { target: 'complete', description: 'The sub-question is answered.', schema: z.object({ summary: z.string().min(80), sources: z.array(source).min(1) }), // The sources are checked at the source: a run once accepted a citation its own title called "page 404'd". // … effect: async ({ event }) => { … const gone = await Promise.all( event.sources.map(async ({ url }) => { … return status === 404 || status === 410 ? `${url} is gone (HTTP ${status}). Cite the page you read instead, or drop it and say what rested on it.` : null }), ) const reasons = gone.filter((reason) => reason !== null) if (reasons.length > 0) throw new RejectedEvent(reasons.join('\n')) }, … },
the agent sees · the worker's finding, refused on a source that is gone
$ node cli.ts --drive send 1b36b700…/task-1-3 finding.submit -{
"summary": "All findings come from search-result snippets only; no pages were fetched. …",
"sources": [
{ "url": "https://mdc.mo.gov/newsroom/mdc-invites-young-anglers-kids-fishing-day-june-7-shepherd-hills", "title": "MDC invites young anglers to Kids Fishing Day at Shepherd of the Hills" },
{ "url": "https://themissouritimes.com/shepherd-of-the-hills-hatchery-conservation-center-summer-activities/", "title": "Shepherd of the Hills Hatchery & Conservation Center summer activities" },
…
{ "url": "https://mdc.mo.gov/events/kids-fishing-day-shepherd-hills-hatchery-2019", "title": "Kids Fishing Day at Shepherd of the Hills Fish Hatchery" }
]
}Rejected: https://mdc.mo.gov/events/kids-fishing-day-shepherd-hills-hatchery-2019 is gone (HTTP 404). Cite the page you read instead, or drop it and say what rested on it. The actor has not moved. Conclude on `data.subQuestion`: write the finding, say that nothing supports an answer, or resume the search. … Offered — each shown in full on an earlier response in this state; call describe <event> to see one whole: - finding.submit → complete - finding.empty → complete - search.resume → searching --- 1b36b700…/task-1-3 · at summarizing · active
here's who to call and what to tell them
A subagent that needs a workflow of its own gets one, with a ledger of its own. The agent makes the call. It starts the subagent and tells it to run the listed command, which hands the subagent a workflow of its own, and that is the whole handoff, because once in the seat the subagent has a backseat driver of its own, with its own instructions, its own refusals and its own ledger, told only its input. While the subagents work, the agent carries on through the workflow. The first transition that needs what they produce is not offered until all of them have finished; sent anyway, it is refused, naming the subagents still out. Sent once they are back, it brings their work into the parent's ledger at the workflow's discretion. Only what the calling agent needs is surfaced to it.
import { researchTask } from './research-task.ts' // a machine of its own: the subagent's workflow // The roster: the machines this workflow can spawn, each under the name its spawns and collections use. actors: { researchTask }, … researching: { … // Spawned on arrival, as an entry action. entry: spawnChild('researchTask', { id: ({ context }) => `task-${context.round}-${context.dispatched}`, // For the agent: what this subagent was sent for, read out on the call that spawns it. about: ({ context }) => context.current?.subQuestion ?? '(no sub-question)', // For the subagent: the ledger its own workflow starts with. Nothing else of the parent's reaches it. input: ({ context }) => ({ subQuestion: context.current?.subQuestion ?? '', question: context.question }), }), on: { // The next sub-task: re-enter, and spawn again. 'task.next': { guard: hasPending, target: 'researching', reenter: true, actions: assign(takeTask) }, // Held until every subagent spawned here has settled. What enters the parent's ledger is the workflow's call. 'research.review': { guard: queueDrained, target: 'reviewing', actions: collectChildren('researching', 'researchTask', assign(…)), }, }, },
$ node cli.ts --drive send 1b36b700… plan.submit -This machine picked which of your proposed sub-tasks run this round, and in what order; those not picked are not run, and you may propose them again in a later round. For each one, spawn a subagent and tell it to run the listed command: each worker's searches and pages then stay out of your context, and the workers run side by side. Keep dispatching while another sub-task is offered, then wait until all of your subagents are complete before moving to review. ## To move to state: researching (Workers are being dispatched and are running.) ### task.next → researching (Another sub-task is waiting to be dispatched.) no payload ## Subagents to start - 1b36b700…/task-1-1 — Which Branson-area fishing spots are free or low-cost, with fishing docks, piers or bank access suitable for young children (e.g., Table Rock State Park dock, Moonshine Beach, Branson Landing)? Cover only access, safety and cost, not guided trips. `node cli.ts --drive snapshot 1b36b700…/task-1-1` --- 1b36b700… · at researching · active
$ node cli.ts --drive snapshot 1b36b700…/task-1-3You have been handed this actor for `data.subQuestion`. Propose 2-5 search queries that together answer it. Each must stand alone as a search string. `data.question` is the research question your sub-question was cut from: it is there so you know what your finding will be read for, and is not yours to answer. ## Data - question: string Where is the best place to take my kids fishing in Branson, MO? - subQuestion: string Are there stocked ponds, trout parks or hatchery attractions near Branson (Shepherd of the Hills Fish Hatchery, Bass Pro Shops, Lake Springfield, Roaring River State Park) good for kids? Cover only these hatchery and stocked-water options. ## To move to state: searching (Queries are being worked one at a time.) ### queries.submit → searching (The queries are chosen.) queries: string[] // min 2 items, max 5 items, each: min length 3 … --- 1b36b700…/task-1-3 · at briefing · active
sit down, I made a slideshow of the trip
Every call an agent makes lands in the trace: the state the actor was in, the transition it took or was refused and the reason, and what an effect brought back. The trace report draws each actor's journey from it, the states it stopped in and the calls answered from each. A run is assessed from the workflow's trace, never from the agent's account. That is how a workflow improves: a wrong turn sits under one state, so the instructions to fix are that state's. Fix them, run again, and the next report says whether it worked.
you see · the trace report for run 1, the lead's journey, with a refused call selected: task.next, sent when it was no longer offered
# machine root status started last call calls undeclared where 1 deep-research 1b36b700 done 2026-11-07 13:23 2026-11-07 13:26 72 completed Report which run? [1-1] 1 …/runs/1b36b700…/trace.html (72 calls)
1b36b700… doneoffered brief.submit
createcreatedsend brief.submit→ planningbrief.submit → planning
offered plan.submit
send plan.submit→ researchingplan.submit → researching
offered research.review
send task.nextstayed, spawned task-1-2send task.nextstayed, spawned task-1-3send task.nextstayed, spawned task-1-4send task.nextstayed, spawned task-1-5send task.nextstayed, spawned task-1-6send task.nextrejected not-enabledsend task.nextrejected not-enabledsnapshotstayedsnapshotstayedsend research.review→ reviewingresearch.reviewifqueueDrained → reviewing
offered round.again research.conclude
send research.conclude→ draftingresearch.conclude → drafting
offered draft.submit
send draft.submit→ citing.awaitingdraft.submit → citing
offered citations.submit
send citations.submit→ completecitations.submit → citing.checking then … → complete
Sent
payload
{}
Response
rejected
Left at
researchingactive
…
$ node cli.ts --drive send 1b36b700… draft.submit -… ## Data - draft: string Where to take your kids fishing in Branson, MO Short answer: for young or first-time anglers, start with the MDC-stocked ponds at Eiserman Park in Branson, where kids can fish free. For a classic Branson outing on real water, go to Lake Taneycomo, where Lilleys' Landing Resort and Marina lists dock fishing as free and the lake is stocked with trout. Top picks 1. Eiserman Park ponds (Branson). The Missouri Department of Conservation stocks two ponds here and kids fish free. Small, easy water suits young children. 2. Lake Taneycomo. Cold, stocked trout water with several access points, including Lilleys' Landing, the Fall Creek area, Branson Landing and the MDC Rockaway Beach access. Check dam water-release schedules and have children wear life jackets, as the current can change quickly. … --- 1b36b700… · at citing.awaiting · active
I storyboarded the whole trip
Backseat is built on XState, and Stately Studio draws XState: the states, the transitions between them, laid out and connected. Everything Backseat adds, the instructions, the payloads, the data, is rendered into the descriptions, so the drawing says what each state will say to the agent. It is for looking at. Nothing reads it back.
you run · one command, and a file per machine to import
$ node cli.ts stately
…/deep-research.stately.ts
…/deep-research.researchTask.stately.tsyou see · the lead machine drawn in Stately Studio, briefing through drafting


scoot over. I'm getting in the back
Paste one of the prompts at the top into your coding agent and you run nothing yourself: it installs the companion skill, runs init, and writes the workflow with you. To run the workflow, tell your agent to run node cli.ts --drive create <machine> and to follow what it prints. By hand, the one command is init: it sets the directory up as a project and, with no machine to find in your source, offers a starter: one state, one transition, then finished. Run it again any time; it finishes what is missing and leaves the rest alone. Every command is in the CLI reference.
… created package.json — my-agent updated scripts.typecheck — tsc $ npm install backseat-ai@^0.1.0 xstate@^5.32.6 zod@^4.5.4 … updated dependencies — backseat-ai xstate zod $ npm install -D typescript@^7.0.2 typescript5@npm:typescript@^5.9.3 @types/node@^26.4.1 … updated devDependencies — typescript typescript5 @types/node created tsconfig.json created cli.ts created my-agent.ts — the smallest machine: one move, then finished created machines.ts — registers my-agent ok node cli.ts --drive — fronts my-agent Set up. Start a machine with `node cli.ts --drive create <machine>`; lint with `node cli.ts lint`.