· 9 min read · 1606 words

When to Use a Deterministic Workflow Instead of an AI Agent: A Step-by-Step Guide

We started strictly agent-first, then watched a prompt-orchestrated agent skip approval gates and fabricate verification with zero tool calls. The three-question process test and three-shape step rule (code, one tool-less schema turn, or autonomous worker) we now use.

Part 1 of Deterministic Workflows vs Autonomous AI Agents in LangGraph.

When to Use a Deterministic Workflow Instead of an AI Agent: A Step-by-Step Guide

Earlier this year, our platform default was strictly agent-first. Our June architecture decision record for software upgrade planning made it an explicit rule: no hand-written outer graph. A frontier model runs in a loop, chooses tools, delegates to subagents, and decides when it is finished. Any determinism the product needed would live inside the tools themselves.

Three months later, that exact product was a hand-written LangGraph StateGraph with only a single autonomous agent step left inside it, plus a third hybrid shape we had not even named in June.

This is the decision rule we earned from that migration: how to decide at the process level whether you need a workflow or an agent, and how to decide at the step level between plain code, a single tool-less schema-bound model turn, and a full autonomous worker agent.


Start agent-first, but write down what would change your mind

I want to be fair to our June self. Starting agent-first was a sensible default. Every agent on our shared harness built the same way meant one review surface, one set of framework features, and zero bespoke per-agent graph code to maintain.

What made that June decision record genuinely useful was a single sentence in its "rejected options" section: it rejected a hand-written outer graph unless measurements showed that tool-level determinism was not enough. That sentence turned "should this be a workflow?" from a philosophical taste argument into an evidence threshold.

Two months later, the evidence showed up in production reviews and evaluation runs:

  • The orchestrator model reported impact analysis as complete and verified in a run where it had made zero tool calls.
  • A code review found that our scope approval gate lived in prompt text and "failed open" (nothing stopped analysis from starting without approval).
  • A feasibility stop was a field inside a prose report instead of an actual pause.
  • Services ran one after another purely because the prompt asked nicely.

None of those were model-quality bugs. A smarter frontier model obeys instructions more often, never always. When step sequence, human gates, and fan-out live in prompt text, correctness depends on a probabilistic model choosing to honor your contract on every single turn.


The process-level test: three questions

Following the clean distinction in Anthropic's Building effective agents (a workflow routes models and tools through predefined code paths; an agent directs its own loop), we turned the choice into three binary questions about the process:

Question Build a deterministic workflow if... Build an autonomous agent if...
Is the step sequence known up front? The order is a contract you can draw before the run starts The next step depends on what the model discovers
Are there mandatory human gates? A person must approve before the next phase may execute Approvals are advisory or absent
Is the parallel fan-out known? You can name the units of parallel work up front The model decides what to split and when

When all three answers point left, the process is a workflow, even when several steps inside it still need an LLM.

Crucially, we did not spin up a separate workflow engine or move orchestration into the web app's backend (which would have broken our thin harness principle, cut off IDE and API callers, and forced us to build auth, checkpoints, and human gates twice). A workflow on our platform is simply a registered agent whose create_graph() method returns a compiled StateGraph instead of a Deep Agent loop. Across our whole platform today, roughly a quarter of registered agents are hand-written graphs (our specialist router and our upgrade workflows), while the other three quarters remain autonomous agents.


The step-level rule: three shapes, not two

Choosing a workflow settles the outer shell. It does not tell you which steps inside the graph deserve a model.

Our first September graph kept three model steps: discovery, impact analysis, and planning. Within two weeks, two of the three were replaced by plain Python:

  • Discovery was three lookups. Classifying services sounded like reasoning until we opened the hood: source version sat pinned in deployment config, target version was calendar arithmetic plus the latest published patch, and service classification came straight from a rule-based tool. As the engineer who replaced it put it, the model added only one thing the tools lacked: "the ability to answer differently on a second run." Better yet, removing the model immediately exposed two silent tool-configuration bugs that the model had been papering over.
  • Planning was a compiler. Turning verified impact findings into structured upgrade plans was ordering, grouping, and templating. We compiled a captured impact report both ways and diffed them before deleting the planner worker. The deterministic compiler runs roughly ten times faster than the impact worker step and needs unit tests instead of LLM judges.

And then a third shape emerged on mobile upgrades. Rule-based classification left a handful of mobile screens labeled "unknown" with low confidence. The graph could select those exact screens and pack the exact source files that decided them, yet plain regex rules could not read arbitrary UI code. Spinning up a full autonomous worker agent would have dragged in a tool loop and reopened a second discovery pass we had just deleted.

So we formalized a three-shape rule for every single step inside a workflow:

What the step needs Step shape
One right answer given the inputs (lookups, arithmetic, templates, rule checks) Plain code or a deterministic tool (zero model calls)
Bounded judgement over context the graph can select and pack up front One tool-less, schema-bound model turn (prompt + context + schema in, validated object out)
Open-ended investigation requiring its own tools to decide where to look next Autonomous worker agent

Two-panel architecture diagram showing the 3-question process test (Workflow vs Agent) on the left and the 3-shape step-level decision tree (Plain Code, One Tool-Less Schema Turn, Autonomous Worker) on the right.

Left: three questions separate workflows from autonomous agents at the process level. Right: inside a workflow, each step picks one of three shapes, with a clear escape hatch back to an agent if a bounded turn starts needing tools.

Notice the pattern that makes Shape 2 (the single tool-less turn) safe in production: the model proposes, and fail-closed Python rules decide what the graph is allowed to accept. Never trust prompt prose to enforce invariants on the model's returned JSON:

# Simplified from the mobile screen review validator
def validate_correction(c: Correction, *, platform: str) -> Correction:
    """Fail closed: low confidence and illegal promotions revert to UNKNOWN."""
    label = c.to_label if c.to_label in KNOWN_LABELS else "UNKNOWN"
    if c.confidence == "low":
        label = "UNKNOWN"
    if c.target == "module" and label == "MODIFIED":
        label = "UNKNOWN"  # domain invariant enforced in code, never prose
    if (
        c.target == "screen"
        and label == "CUSTOM"
        and platform in {"android", "ios"}
        and not c.override
    ):
        label = "UNKNOWN"
    return c.model_copy(update={"to_label": label})

If the reply fails JSON validation altogether, every affected screen simply stays UNKNOWN and logs why. One bad model call costs a single screen review, never the whole run.


Two boundaries that kept us from over-building graphs

Once a team discovers how clean StateGraph feels compared to babysitting an unruly orchestrator prompt, the pendulum can swing too far the other way. Two explicit rules kept us grounded:

  1. A gate becomes structural only when the runtime can read a signal for it. Out of six approvals in our product requirements, three became real interrupt() nodes and three stayed as prose until a worker emits a machine-readable signal the graph can inspect. A structural gate with no signal behind it is just prompt text wearing a costume.
  2. A fixed entry point and fixed output schema do not make a process a workflow. Our backend, web, and mobile developer agents accept structured ask/plan calls and emit structured implementation plans, yet answering architectural questions and writing plans require open-ended contextual search. They stayed autonomous agents. So did per-service impact analysis inside the upgrade workflow itself.

There is also a real maintenance price to pay when you pick a graph. Across our entire agent repository, our two workflow graphs account for roughly nine-tenths of all agent Python code (autonomous agents stay tiny and live in skills, as I covered in Building on Deep Agents: Keep the Harness Thin). A single nested inventory sub-workflow spent roughly a month in code review, and reviewers had to read Python state transitions instead of Markdown prose.


What I am still going back and forth on

I am still split on how early a team should pull out the StateGraph knife. Writing our June rule as "agent-first until measurements prove otherwise" prevented premature engineering, yet looking back as the person running evals, two of our first three model steps (discovery and planning) were never judgements. Asking the step-level question on day one would have saved weeks of writing eval datasets for steps that should have been Python functions from the start.

I also still notice a subtle trap with Shape 2 (the tool-less schema turn): because its packed input packet and reply often live inside a local node variable instead of graph state, teams end up evaluating it only through noisy full-workflow runs instead of replaying the turn directly. Deciding the step shape without deciding its evaluation interface at the same time leaves half the win on the table.


Pick the shape with its test in mind

When you design an agentic system, do not argue over "workflows vs agents" as an ideology. Run the three process questions, then walk every step through the three-shape table: one right answer is code, bounded judgement over pre-packed context is one tool-less schema turn with fail-closed rules, and open-ended search is an autonomous worker.

Every step shape carries its own testing bill: graph edges get sub-second unit tests, single turns get tight input-output evals, and only the truly open-ended workers pay for LLM judges.

Next in this series: Building Deterministic LangGraph Workflows: StateGraph, interrupt() Gates, and Durable Jobs, on wiring real human-in-the-loop approval gates that survive two-day waits and killed pods.

Related writings