Agents → Planning styles (ReAct, plan-then-execute, search)

Agent Planning Styles Explained: Scripts vs Free-Form Agents

What it is

Four points on a spectrum from "code decides" to "model decides":

StyleHow it worksPredictabilityCost varianceUse when
Scripted workflowCode defines the steps; LLM calls fill in the intelligence at each stepHighLowThe path is knowable — most production tasks
Plan-then-executeLLM produces a full plan upfront; runtime executes it, optionally replanning on failureMedium-highLow-mediumMulti-step tasks with a knowable structure but variable specifics
ReAct (reason + act, interleaved)Model reasons, picks one tool, observes, reasons againLowHighExploration where each observation changes the next step
Tree/graph search (ToT, LATS)Explore multiple branches, evaluate, backtrackVery lowVery highSteps are cheap and reversible, and the solution space needs searching

The source file's guidance is the whole lesson: production systems are mostly scripted workflows with LLM steps inside them. The literature over-represents free-form agents because they're interesting; production over-represents scripts because they're testable, cheap, and debuggable.

A useful reframing: every step you can move from "the model decides" to "the code decides" is a step you can unit-test, cache, budget, and monitor.

How to implement

  1. Start scripted. Write the workflow as code: retrieve → extract → validate → decide → draft → check. Each step is a call site with its own prompt, tier, schema, and eval (model selection & tradeoffs, prompt versioning & evaluation).
  2. Add plan-then-execute where the sequence varies but the step types don't: an LLM selects and orders steps from a fixed catalogue (task decomposition), the runtime executes them.
  3. Add ReAct only for the sub-problem that genuinely needs it — often a research or lookup phase inside an otherwise scripted flow. Bound it hard (single agent loop, cost & step budgets).
  4. Avoid tree search in production unless steps are cheap, reversible, and evaluable — it multiplies cost by the branching factor and is rarely justified outside code generation and puzzle-like domains.
  5. Make the boundary explicit: a scripted workflow that calls a bounded agent for one step is a normal, healthy architecture.
  6. Measure: task success, cost, and step count per style on the same golden set before choosing (agent evals).

Small example

# --- Scripted workflow: the default. Structure in code, intelligence in the steps. ---
def handle_claim(claim_doc, caller):
    fields   = extract("claim_extract", claim_doc, ClaimFields)              # fast tier + schema (structured outputs & tool use)
    policy   = retrieve_policy(fields.policy_id, caller)                     # deterministic lookup
    if not policy:
        return refuse(RefusalReason.NO_RELEVANT, {...})                      # Refusal / no-answer path
    eligible = decide("eligibility", fields, policy)                         # reasoning tier, CoT (chain-of-thought)
    if eligible.confidence < 0.7:
        return escalate_to_human(fields, eligible)                           # Human-in-the-loop
    draft    = generate("claim_response", fields, policy, eligible)
    return reflect(draft, criteria=RESPONSE_CRITERIA, max_rounds=1)          # Loop-back / reflection

# --- Plan-then-execute: sequence chosen by the model, from a fixed catalogue ---
STEP_CATALOGUE = {"search_docs": search_docs, "query_warehouse": query_warehouse,
                  "read_document": read_document, "summarise": summarise}

def plan_then_execute(goal, caller, max_steps=6):
    plan = json.loads(llm("plan", PLAN_SYS.format(steps=list(STEP_CATALOGUE)),
                          [{"role": "user", "content": goal}]).text)["steps"][:max_steps]
    state, executed = {}, []
    for i, step in enumerate(plan):
        if step["op"] not in STEP_CATALOGUE:                                  # no invented steps
            return {"status": "invalid_plan", "step": step}
        try:
            state[f"s{i}"] = STEP_CATALOGUE[step["op"]](step["args"], caller, state)
            executed.append(step)
        except Exception as e:
            rp = replan_on_failure(plan, step, str(e), max_replans=1)         # Loop-back / reflection
            if rp["status"] != "replanned":
                return {"status": "failed", "executed": executed, "reason": rp["reason"]}
            plan = rp["plan"]
    return synthesise(goal, state, executed)

# --- ReAct: only for the phase that needs it, and bounded ---
def research_phase(question, caller):
    return run_agent(question, caller, tools=[SEARCH_TOOL, READ_TOOL],
                     tool_impls=IMPLS, system=RESEARCH_SYS,
                     budget=Budget(max_steps=5, deadline_s=25, max_usd=0.15))   # Single agent loop, cost & step budgets

Pros

  • Scripted: testable, cacheable, cheap, predictable latency, easy to debug, easy to roll back. Failures localise to a step.
  • Plan-then-execute: adapts sequence to the goal while keeping execution deterministic; the plan is reviewable before it runs (human-in-the-loop).
  • ReAct: handles genuinely unknown paths; self-corrects from observations.
  • Search: finds solutions that greedy approaches miss, on problems where that matters.

Cons

  • Scripted: can't handle inputs the designer didn't anticipate; every new case is code.
  • Plan-then-execute: a bad plan executes faithfully to a bad outcome; needs plan validation (task decomposition).
  • ReAct: high cost and latency variance, harder evals (trajectory, not just output), more failure modes (loops, drift, wrong tool).
  • Search: cost multiplied by branching; needs a reliable evaluator, which is usually the hard part.

When to use each

  • Scripted: document processing, extraction, classification, standard RAG Q&A, form filling, approvals — i.e. most of what production systems do.
  • Plan-then-execute: multi-source reports, workflows whose step order depends on the request, batch jobs with variable structure.
  • ReAct: investigation, debugging, open-ended research, multi-system troubleshooting — and usually only for one phase of a larger scripted flow.
  • Search: code generation with tests as the evaluator, planning problems with cheap simulation, optimisation over a discrete space.

When NOT to use

  • Don't use ReAct as the default architecture. It's the most expensive, least predictable option, and most tasks don't need it.
  • Don't use tree search without a cheap, reliable evaluator and reversible steps.
  • Don't script a genuinely open-ended research task — you'll write an ever-growing if-tree that's worse than an agent.

Production at scale

The ratchet goes one way: from model-decides to code-decides. As you learn what the model actually does, promote recurring patterns into scripted steps. A system that started as a free-form agent and is now 80% script is a healthy, maturing system — not a retreat.

Hybrid is the production norm: a scripted spine with one or two bounded agentic phases. Route to the agentic phase only when a complexity signal justifies it (routing, routing & escalation), so the average request pays scripted-pipeline cost.

Cost variance is the architectural decision. Scripted: p99 ≈ p50. ReAct: p99 can be 20× p50. If your product needs predictable unit economics or latency SLOs, that alone decides it.

Evaluation differs by style. Scripted: per-step evals plus end-to-end (component vs end-to-end). Plan-then-execute: plan quality separately from execution. ReAct: trajectory evals — right tools, right order, reasonable cost (agent evals). Choosing a style commits you to an eval strategy.

Observability differs too. A scripted workflow is a known DAG you can dashboard per step. An agent produces a different graph every run; you need trace search and aggregate trajectory statistics (observability & tracing).

Latency budgets: scripted flows can be parallelised deterministically (independent steps concurrently); agent loops are inherently serial per step. For interactive latency, this often decides the architecture.

Failure containment: in a script, a failed step has a defined fallback. In an agent, failure handling is emergent — which is why bounded budgets and forced finalisation (single agent loop) matter so much more there.

Migration path: instrument an agentic system to log its trajectories, cluster them, and you will find that a handful of paths cover most traffic. Those become the script; the tail keeps the agent.

Prod checklist

  • Default to a scripted workflow; each step has its own prompt, tier, schema, and eval
  • Agentic phases isolated, bounded, and entered only via a complexity signal
  • Plan-then-execute constrained to a fixed step catalogue; plans validated before execution
  • Cost and latency p50/p99 measured per style before committing
  • Eval strategy matched to style (per-step / plan quality / trajectory)
  • Trajectory logging and clustering to identify paths worth promoting to script
  • Independent scripted steps parallelised; agent phases time-boxed
  • Defined fallback for every scripted step; forced finalisation for every agent phase

Metrics to watch

MetricWhy
p50 vs p99 cost and latency by styleThe core trade-off
Task success by style on the same golden setWhether the flexibility is earning anything
Agentic-path routing rateCost containment
Trajectory clustering: top paths as % of trafficCandidates for scripting