“I need you to book a complete business trip for me.” I’ve seen this kind of request more than once, and the first version always hands it straight to a single Agent. It flip-flops between budget and preferences: a hotel just settled in one step gets overturned by the transport arrangement in the next, and in the end even the departure date changes. Each step’s reasoning looks sound in isolation; strung together, it’s a disaster.
The problem isn’t model capability. This task inherently requires fixing constraints first and then expanding details, and a greedy loop is inherently not built that way. After that experience I pulled planning out of the loop into a separate layer: first produce a verifiable plan, then let the executor run according to the plan.
Post 2/15 in this series · Previous: An Agent Is a Closed-Loop Control System · Next: Tool Calling Protocol: From Schema to Idempotency
Three Things a Greedy Loop Can’t Handle
The single-loop ReAct from post 1 is essentially a greedy strategy: each step looks only at the current observation and picks the locally optimal action. It works well when there are few steps and feedback is clear, but it has three structural weaknesses.
Constraint fixation. When the user says “budget under 3000, no red-eye flights,” that’s a global constraint, not the input to some step. In the loop it’s just an earlier message, and as observations pile in, it gets pushed out of the effective attention range.
Dependency ordering. To book a hotel you must first fix the dates and city; to get reimbursed you must first have an order number. These dependencies need to be explicit before acting; leaving them to the model’s on-the-fly judgment easily leads to out-of-order execution.
Parallelism. Three mutually independent queries can only run serially in the loop, paying two extra rounds of latency for nothing.
The value of the planning layer is turning these three things from “implicit judgments by the model” into “explicit data in the system.” It doesn’t make the model smarter; it moves part of the decision-making from probabilistic output to deterministic structure.
Conversely, don’t mythologize it either. A plan is a hypothesis based on current information, and it’s void the moment the environment changes. The most painful class of bug I’ve seen is an executor strictly executing an outdated plan to the end: step three has already proven the file doesn’t exist, yet it’s still parsing it per the original plan.
Three Plan Representations, I Only Use One
| Representation | Output | Execution | Main problem |
|---|---|---|---|
| Chain-of-thought / ReAct | Natural-language reasoning + single-step actions | Fed back step by step | No global constraints, easy to spin in place |
| Plan-and-Solve | Numbered step list | Sequential execution | No dependency info, can’t parallelize, hard to backtrack when the plan is wrong |
| Structured DAG | Step graph with dependencies, inputs/outputs, and validation conditions | Topological scheduling + local retry | High generation cost, schema must be maintained |
I basically never use pure natural-language plans. Text like “first check the weather, second book the meeting room” still has to be parsed again by the execution layer, and the parsing itself can go wrong, which just passes the ambiguity one layer downstream. Now I always require the planner to output structured JSON with fixed fields; if validation fails, regenerate, and never proceed with a vague plan.
1 | { |
These four fields are ones I added over and over: depends_on lets the scheduler parallelize s2 and s3; produces declares what this step writes into shared state; done_when turns “done” into an executable judgment; requires_confirmation marks irreversible actions at the planning stage rather than discovering them at execution time.
I insist on writing placeholders like $s1.date explicitly, rather than letting the executor guess “where in the previous step’s result the date is.” Parameter resolution goes to code; the model only declares dependencies.
How to Split: Three Approaches and One Granularity Criterion
Generating the plan is itself a model call. Its input should be the task description, the list of available tools and their costs, and known constraints—not an entire conversation history. I keep the planner’s context very clean, usually just these three items plus a few few-shot examples.
Splitting falls into three approaches by task type.
Split by dependency, suited to process-type tasks. Ask top-down “to accomplish X, what inputs must exist first,” until the leaf nodes are single tool calls; the output is naturally a DAG.
Split by entity, suited to batch processing. A hundred tickets, each an independent subtask; the plan writes the template once plus a data list. Here checkpoints must be fine-grained down to individual records, otherwise a half-success state can’t be recovered—the side-effect ledger from post 1 applies here too.
Split by hypothesis, suited to exploratory tasks. First list several possible causes, give each a verification step, and the result determines the subsequent branch. This kind of plan is essentially a decision tree, and the scheduler must support conditional edges.
The granularity criterion is very practical: every step should have a checkable completion condition. If a step can only be written as “analyze the situation,” it either needs further splitting or shouldn’t be given to the planner at all—it belongs back in single-step reasoning. Another signal is parameters: if a step needs to assemble parameters on the fly from the natural-language output of several earlier steps, then produces wasn’t declared clearly.
I usually limit top-level steps to 3 to 8. Beyond 8, the model starts missing dependencies on its own when generating the plan. If it’s really that complex, it must be layered—but how much layering is appropriate, I don’t yet have a hard criterion; my current default is to split by “a sub-plan can be independently accepted.”
Scheduler: The Plan Is Data, Execution Is Code
With a DAG, the execution layer needs no model involvement until a step fails.
1 | def run_plan(plan, state, max_replans=2): |
The most easily underestimated part is resolve. Placeholder resolution must be strict: referencing a nonexistent field must fail immediately, rather than passing a None downstream for the model to guess. I’ve been burned: $s2.flights[0].price silently becomes None when s2 returns an empty array, and it propagates all the way to the ordering step before blowing up.
check only does deterministic checks: field existence, count lower bounds, regex, numeric ranges. Don’t use a small model to judge “whether this step went well”—that just introduces another probabilistic link. Global constraints (budget, time window) I recompute after each step is submitted, and stop early if exceeded, rather than settling the total after the plan finishes.
Replanning Triggers Must Be Hard-Coded
The biggest risk of a static plan is “executing to the end,” so triggers must be explicitly enumerated, not left to the model to feel something is off:
- A step still fails to satisfy
done_whenafter consecutive retries; - The observation conflicts with the plan’s premise, e.g., the plan says “read the config file” but the file doesn’t exist;
- The user changes constraints mid-way;
- The global constraint check fails;
- A tool or action requirement appears that isn’t declared in the plan.
Replanning doesn’t mean throwing away the whole plan and starting over. The context passed back to the planner contains only: the original goal, completed steps and their outputs, the failure reason, and the remaining budget. Don’t stuff the full execution log back in—that anchors the new plan to the old path. plan_version increments each time, and any checkpoint referencing an old-version output is immediately judged unrecoverable; forcing continuation across incompatible versions is usually more expensive than rerunning from scratch.
The number of replans must be capped. I have seen an Agent replan more than a dozen times on “if the search fails, try a different search method,” generating a plausible-looking new plan each time. When the cap is reached, it should stop and hand the current state to a human, rather than continue burning tokens to look busy.
The benefits are real, and so are the costs
The benefits are direct: global constraints do not drift away or get lost with context; independent steps can run concurrently, cutting latency noticeably—what you save is the wait for the slowest query, not the average; each step has done_when, so failures can be traced to a specific node and retried locally; and the plan is pure data, so it can be diffed, cached, and manually pre-reviewed. In scenarios involving external side effects, requires_confirmation makes dangerous actions visible before execution.
The costs cannot be ignored either: one or more extra model calls, on the order of hundreds of milliseconds to several seconds of additional wait; schema and placeholder parsing must be maintained long-term—change a tool’s signature and the plan template must change with it; and for highly uncertain exploratory tasks, planning ahead is often just making things up, and it is better to let ReAct look as it goes. Planning quality also depends heavily on the quality of tool descriptions: if the tool list is vague, the plan will certainly be vague.
My rule for choosing: if there are real dependencies between steps, or global constraints exist, or actions are irreversible, add a planning layer; if the path is determined entirely by observations and the number of steps is expected to be within five, do not. The two modes can coexist in the same system, decided by a very thin routing check—but do not let the model decide which one to use; that hands the architecture decision back to probability again.
The other half of planning is “how actions get executed.” The plan says flight.search; how that tool is defined, how parameters are validated, and how failures are fed back is for the next post. Back to your current plan: for how many steps is the completion condition something that can be checked with one line of code? If the answer is “not many,” fix that first—it is far more effective than switching models.
Comments