The Flow Book
  1. Why Flow

One week at the support desk

  1. A payment that timed out
  2. What the run was told
  3. Writing the payments library
  4. Waiting for the manager
  5. The next morning
  6. When the process dies mid-call
  7. Fixing a bug in a half-finished run
  8. Three carriers at once
  9. Answering calls from your own service

Projects

  1. What people build
  2. A research agent you can check

The language tour

  1. Values, functions and blocks
  2. Records, choices and match
  3. Modules, libraries and Python functions
  4. Result, ToolProblem and ?

Appendix

  1. The flow command
Language reference ↗

What people build

The desk's programs fit on a screen. The orchestration code in a real agent product doesn't: a pull-request reviewer that falls back across models, a coding agent with a fix loop, a research bot that searches in parallel. Before you move a stretch of your own code into Flow, you'll want to see the rule from Why Flow hold up in a program of that size.

The Flow repository keeps Flow versions of published agent workflows in tests/corpus/, next to a write-up of each original and a set of scripted cases. They are ports, written to test the language against real workflows rather than to run in production. Their Tools come from libraries the test suite builds for them, so you can't run them on their own; the suite runs every program through its cases with flow run and flow resume, then replays each run with nothing connected and requires matched. Nothing in it calls a real model or service.

This chapter reads one excerpt from each, quoted exactly, and says what in it you have already seen.

PR-Agent's /improve: falling back across models

PR-Agent's /improve, as of version 0.50, splits a pull request into chunks, asks a model for suggestions on each, has a model score them and publishes those above a threshold. It falls back to the next model when one fails. The Flow version, pr-agent-improve.flow, keeps that, and the fallback is where the two layers of a Tool call earn their keep.

The program folds both layers into one type of its own, with a helper that peels them with x.map_err(f)?, as Result, ToolProblem and ? describes:

pub type Problem<E> { Refused(E), Unanswered(ToolProblem) }
flow answered<T, E>(reply: Result<Result<T, E>, ToolProblem>) -> Result<T, Problem<E>> =    Ok(reply.map_err(Unanswered)?.map_err(Refused)?)

Then the fallback tries one model after another:

flow with_fallback<T>(    models: List<llm.Model>,    call: (llm.Model) -> Result<Result<T, llm.ModelError>, ToolProblem>,    tried: Attempts,) -> Fallback<T> =    match models {        [] => Exhausted(tried),        [model, ..rest] => match answered(call(model)) {            Ok(value) => Answered { value, after: tried },            Err(problem) if eligible(problem) => with_fallback(rest, call, tried + [problem]),            Err(problem) => Fatal { problem, after: tried },        },    }

and one function decides which failures move on:

flow eligible(problem: Problem<llm.ModelError>) -> Bool =    match problem {        Refused(RateLimited) | Refused(Timeout) | Refused(Api(_)) => true,        Unanswered(_) => true,        Refused(BadOutput(_)) => false,    }

Here every ToolProblem moves on to the next model, the opposite of the refund in A payment that timed out. Asking a second model costs tokens; it doesn't pay anyone twice. The same three cases lead to a different decision, and both decisions sit in one match a reviewer can read. Every failed attempt stays in tried, so the result says which models failed before one answered.

Superpowers: no progress ledger

Superpowers' subagent-driven development works through a plan task by task: an implementer subagent makes the change, a reviewer checks it, and open findings go through up to five fix rounds. The original keeps a ledger file so a controller that loses its place can find it again. superpowers-subagent-driven-dev.flow has no ledger:

flow fix_rounds(s: FixState) -> Result<TaskRecord, Halt> = {    let record = TaskRecord { task: s.brief.task, fix_rounds: s.rounds, rulings: [], minor: s.minor }    guard s.open != [] else { return Ok(record) }    guard s.rounds < 5 else { return Ok(TaskRecord { rulings: s.open.map(tools.adjudicate), ..record }) }    let session = if s.rounds < 3 { s.session } else { tools.open_session(Stronger, s.brief).map_err(Unanswered)?.map_err(Agent)? }    let _ = tools.send(session, Fix(s.open)).map_err(Unanswered)?.map_err(Agent)? // the recheck, not the fixer's report, decides    let head = tools.current_head().map_err(Unanswered)?.map_err(Repo)?    let open = tools.recheck(s.open, tools.diff_between(s.head, head).map_err(Unanswered)?.map_err(Repo)?).map_err(Unanswered)?.map_err(Agent)?    fix_rounds(FixState { session, head, open, rounds: s.rounds + 1, ..s })}

The escalation is plain code: the round number is an argument, and it decides whether the findings go to the same session or a fresh, stronger one. Where the original's controller reads its ledger to find its task and round, a resumed Flow run is answered from its record up to where it stopped, as in The next morning, so the bookkeeping the ledger did has nowhere to live and no need to.

Claude Code's /feature-dev: one way to ask a person

Claude Code's /feature-dev builds a feature in seven phases and asks the user at several of them. cc-feature-dev.flow asks with one generic Tool, person.ask, and the type the program expects at each call decides what a valid answer is:

flow clarify(brief: agents.Brief, questions: List<Text>) -> Result<Outcome, Problem> = {    let answers: Text = match questions {        [] => "",        _ => person.ask("Before designing:\n${bullets(questions)}").map_err(Unanswered)?.map_err(Ask)?,    }    design(brief, answers)}

Here the answer is Text. Later the same Tool is asked for a design style, a Bool for approval and a fix policy, and each answer is checked against its type before the program sees it, as "Maybe" was in Waiting for the manager. Each question is a place where the run can wait with nothing running, for as long as the user takes.

LangGraph's human-in-the-loop guide: asking until the answer is valid

LangGraph's human-in-the-loop guide pauses a graph with interrupt() and resumes it with the person's answer. On resume, the node that paused runs again from its beginning, so LangGraph's documentation advises keeping effects after the pause or making them safe to repeat. lg-interrupt-resume.flow writes each pause as a typed call to a person, including the guide's loop that asks for an age until the answer makes sense:

flow ask_age(question: Text) -> Result<Int, Problem<person.AskError>> = {    let age = person.ask_number(question).map_err(Unanswered)?.map_err(Refused)?    guard age >= 0 && age <= 150 else {        return ask_age("'${age}' is not a valid age. What is your age?")    }    Ok(age)}

ask_number is declared to return an Int, so an answer that isn't a number never reaches the program and only the range is left to check. A resumed run serves every earlier answer from its record, so nothing before a pause runs its effect twice.

Temporal's AI agent: three signals become one call

Temporal's AI agent sample is a long conversation that pursues a goal, such as booking travel. The workflow waits for three signals, a user prompt, a confirmation and the end of the chat, and by default runs a tool only once the user confirms it. In temporal-ai-agent.flow the three signals become one call, next_event, whose answer says which it was:

flow wait(state: State) -> Ending =    match answered(tools.next_event(state.awaiting)) {        Ok(EndChat) => ChatEnded { history: state.history },        Ok(Confirm) => match state.awaiting {            AnyPrompt => wait(state), // a stray confirm does nothing, as in the source            Confirmation(request) => plan(State {                history: state.history + [ToolResult { tool: request.tool, reply: tools.run_tool(request) }],                awaiting: AnyPrompt,                ..state,            }),        },        // A new prompt while a confirmation is pending drops the pending tool.        Ok(Prompt(text)) => check(text, State { history: state.history + [User(text)], awaiting: AnyPrompt, ..state }),        Err(problem) => ChannelLost { problem, history: state.history },    }

Between turns the run is a call with no answer, so nothing stays running while the user thinks. run_tool appears in one arm only, the one where a confirmation arrives for a tool that is waiting for it.

Prime Agent's turn loop: steering as an ordinary call

Prime Agent's turn loop, as of August 2026, sends the conversation to the model, runs the tool calls it asks for and goes round again. Between turns it reads a steering queue, so a user can redirect the agent mid-run. In pa-agent-loop.flow that read is a Tool call like any other:

flow turns(context: List<tools.Entry>, pending: List<tools.Entry>, more: Bool) -> Ended = {    guard more || pending != [] else { return idle(context) }    let asked = context + pending    match answered(tools.turn(asked)) {        Err(problem) => ModelFailed { context: asked, problem },        Ok(message) => {            let replies = run_batch(message.calls)            let replied = asked + [Assistant(message)] + replies.map(flow(r) = ToolReply(r))            let continues = message.calls != [] && !all_terminate(replies)            match answered(tools.stop_after(message, replies)) {                Err(problem) => InboxFailed { context: replied, problem },                Ok(true) => StoppedByHarness(replied),                Ok(false) => match answered(tools.steering()) {                    Err(problem) => InboxFailed { context: replied, problem },                    Ok(steer) => turns(replied, steer, continues),                },            }        },    }}

What the user said mid-run is an answer in the record like the model's, so a replay of a steered run steers the same way. A failed model call ends the run with the exact context it was asked with, which is the first thing anyone debugging an agent wants to see.

The OpenAI Agents SDK research bot: searches started at once

The OpenAI Agents SDK's research bot has a planner turn a question into web searches, runs them all at once and hands the results to a writer. In oai-research-bot.flow, main starts every search before it waits for any:

pub flow main(query: Text) -> Outcome = {    let plan = match answered(research.plan(query)) {        Ok(plan) => plan,        Err(problem) => return PlanFailed(problem),    }    // Each task is spawned in fold's callback and handed back with the accumulator, so main owns them all.    let running = plan.searches.enumerate().fold([:], flow(started, (index, item)) =        started.insert(index, task.spawn(flow() = Arrived { index, item, reply: research.search(item) })))    collect(query, running, [], [])}

How many searches run is decided by the planner's answer. Each task carries its index beside its reply, so the program can take results in whatever order they finish, and the order it took them in is in the record, as Three carriers at once explains, so a replay takes them in the same order.

A coding workflow on Codex and git

examples/coding-workflow was written for Flow rather than ported. It hands a task to Codex, looks at the change with git, runs a real test command and asks a fresh Codex session to review, with at most two repairs. Its Tools come from Flow's first-party libraries for Codex, git and processes. The step after each change:

flow qualify(root: path.Path, base: git.CommitId, task: Text, command: process.Command, session: codex.SessionId, remaining: Int, repairs: Int, reviewed_sessions: List<codex.SessionId>) -> Result<Report, Failure> = {    let before = snapshot(root, base, repairs)?    guard before.patch != "" else { return Err(Failure { stage: "inspect-diff", reason: "agent made no tracked changes", repairs }) }    let tested = observe(process.run(command), "test", repairs)?    let after_test = snapshot(root, base, repairs)?    guard before == after_test else { return Err(Failure { stage: "test", reason: "test changed the repository; inspect it before continuing", repairs }) }

The program doesn't trust a report it can check. As the refund program looked the refund up, it reads the repository back, before the test, after it and again after the review, and a test that changed the repository ends the run instead of being believed. A failed or unanswered call ends the run with the stage it failed at, and nothing is sent twice. Its tests replace each Tool with a fake written in Flow, so they run without Codex or a model.

Reading them whole

Each program sits in tests/corpus/ beside a .md write-up of the original and a .json file of the cases it is run through, and examples/coding-workflow has a README with the input a live run needs. Read the write-up first: it says what the original does, where the port differs and why. A research agent you can check takes one larger program apart on your own machine.