Teaching Small Models Workflow Order Through Execution-Verified Repair

Language models are poor at putting steps in the right order once a task stops being a straight line. When a plan has parallel branches and steps that must wait on the outputs of other steps, GPT-4 drops from roughly 67% on linear step sequences to 52% on the dependency graph (Benchmarking Agentic Workflow Generation). Small models fine-tuned on 18,000 correct workflow graphs do well on the training environments but fail on held-out ones. We propose a different training signal. Instead of showing a compact student only correct graphs, we write each workflow as a short executable program in which ordering mistakes crash. We collect trajectories where a teacher writes such a program, runs it, reads the resulting error ("step book_hotel consumed flight_id before any step produced it"), and repairs it. We then distill those repair trajectories into a single 7B model.

The bet is that a model which has repeatedly seen why an order is wrong, stated by a deterministic checker, learns dependency reasoning that transfers across environments. A model that has only seen what right orders look like memorizes topologies instead. In this proposal, multi-agent decomposition is only the offline engine that generates data. Iterative code refinement supplies the supervision. Chronological coherence is the capability being measured.

Core Claim

The claim is narrow and testable. Take a fixed teacher, a fixed deterministic ordering oracle, and a fixed compute budget. A student trained on counterexample-and-repair trajectories will close more of the out-of-distribution gap on graph-structured workflows than a student trained on the same oracle-verified final workflows with the repair steps removed. It will also make fewer ordering violations on its first attempt, which is evidence that the repair behavior has been internalized rather than merely replayed. If the final-answer-only student matches it, the idea is wrong and repair traces add nothing.

The ordering oracle is the concrete piece that makes this possible. Following the trick in LTLCodeGen, which had an LLM write Python that calls a temporal-logic operator library and repaired it from interpreter tracebacks to reach 100% syntactic correctness, we represent a workflow as a Python program. Each node is a call to a stub tool with explicit named inputs and outputs, and parallel branches are expressed as concurrent calls. The interpreter then enforces data-flow order for free: consuming an output that has not been produced raises an error. Stub tools also check declared state preconditions, and in ALFWorld the real simulator checks them (you cannot place a mug you have not picked up). The oracle covers data-flow and state-precondition violations. It does not certify purely semantic orderings with no observable consequence, and we report results separately for those.

Relation to Prior Work

Several lines of work motivate the gap. Benchmarking Agentic Workflow Generation documents the graph gap and the out-of-distribution collapse of students trained on static graphs. It generates workflows in one pass, with no execution. We reuse its data, its step-order metric (longest increasing subsequence) and its graph-structure metric (maximum common induced subgraph), but change the training signal. Can Graph Descriptive Order Affect Solving Graph Problems with LLMs? shows that merely permuting how a graph is written out shifts accuracy by over 12%, which suggests models key on surface serialization. That is exactly the failure a crash-on-violation signal should push against. Older summarization work such as Improving Chronological Sentence Ordering by Precedence Relation found that explicit precedence constraints beat raw timestamp ordering (36% to 55% acceptable summaries on TSC-3). Our oracle is an executable version of that precedence idea.

Three distillation papers supply the method but differ in what they distill. Chain-of-Agents flattens multi-agent trajectories into one model and cuts tokens by 84.6%. AgentArk distills multi-agent debate, including with a process reward model. Plan2Evolve distills solver-verified PDDL plans into a 4B student that beats GPT-4o on long-horizon Blocksworld. The first two distill conversation verified at the task outcome, not at each ordering decision. The third needs a formal domain language. We distill execution-verified repairs over ordinary tool workflows, and we ask specifically whether the repair portion matters.

Multi-agent coding systems supply the teacher design. MapCoder (retrieve, plan, code, debug, with backtracking to alternative plans) and Self-collaboration Code Generation via ChatGPT (analyst, coder, tester) show that role splits help frontier models. Multi-Agent Code-Orchestrated Generation for Reliable Infrastructure-as-Code repairs against a typed resource-dependency graph. Two findings constrain us. MapCoder warns that LLM-written tests corrupt refinement, which is why our oracle is deterministic and never LLM-judged. Self-collaboration reports that role-play collapses below 13B parameters, which is why the student never runs the multi-agent protocol and only imitates its flattened output. AFlow searches over executable workflow code, but it scores candidates by downstream task success and never distills.

Research Program

We build the oracle first. For WorFBench's function-calling and problem-solving splits, tool schemas give input and output names, from which we generate stub functions automatically. For ALFWorld we wrap the environment's action preconditions. Gold workflows are compiled to programs, and every gold program is checked to run cleanly. Gold items that fail are logged and excluded, and this failure rate is itself a measurement of oracle coverage.

The teacher is a frontier-model team, used offline: a planner proposes subtasks and dependencies, a coder writes the program, the oracle runs it, and a debugger receives the plan plus the traceback, as in MapCoder. The debugger may either make a local edit or send the problem back to the planner for re-planning. Each episode is flattened, Chain-of-Agents style, into one trajectory: plan, program, error, diagnosis, repaired program, repeated until the program runs clean. We keep only trajectories whose final program runs clean and matches the gold dependency graph above a threshold. The oracle alone would accept wrong-but-consistent graphs, so this second filter is needed.

We then fine-tune a 7B open code model under matched token budgets, with the trajectory types varied across the arms described below. At test time the student is evaluated in two modes: without the oracle (first attempt only), and with it for up to four repair rounds, given the reported plateau after two to four iterations (Yan et al.).

Baselines

The naive reference point is the base 7B model prompted to produce the same program format with a few examples and no fine-tuning. It tells us how much any training helps.

The most direct existing competitor is supervised fine-tuning on WorFBench's gold graphs, the recipe Benchmarking Agentic Workflow Generation used for its 7B students. It is the strongest competitor on this specific question because it is the published answer to "how do you make a small model plan graphs," and its known weakness is the one we target. We rerun it on the same base model, with the same number of training tokens and the same learning-rate sweep, both in the original graph format and compiled into our program format, so that format is not confounded with signal. The file reports that these students failed to generalize to Seal-Tools and InterCodeSQL, but gives no numeric score. We therefore have no reported number on Lacuna for WorFBench-SFT 7B on the held-out sets and will reproduce it. The frontier reference is GPT-4's reported 52% on graph structure against roughly 67% on chains (Benchmarking Agentic Workflow Generation). We also run the multi-agent teacher itself at test time as an upper bound and report its calls and tokens.

The ablation that isolates the key ingredient is verified-final-only distillation. It uses the same teacher, the same oracle and the same filtered episodes, but trains on the final clean program with the error-and-repair turns deleted. Its token count is padded with additional verified finals so the two arms see equal data. Beating this arm by a margin exceeding seed variance on held-out graph score is the result the proposal lives or dies on. A second ablation replaces the multi-agent teacher with a single-agent teacher running the same generate-execute-repair loop at matched teacher compute. This tells us whether role decomposition contributes anything beyond the oracle. A third baseline is the untrained base model given oracle access at test time with the same four-round budget. It separates "the checker helps at inference" from "the student learned something."

Winning means two things. First, a higher graph-structure score on Seal-Tools and InterCodeSQL than both WorFBench-SFT and verified-final-only distillation. Second, a lower first-attempt violation rate on those held-out sets, at roughly one model call rather than the teacher's many.

Why not just…?

Why not just fine-tune on more correct graphs? This is the WorFBench recipe with more data. Its reported failure to transfer suggests the limit is the kind of signal, not the quantity. We test it directly: the verified-final-only arm gets more final programs than the repair arm, so if volume were the fix, that arm would win.

Why not just keep the oracle in the loop at test time and skip distillation? This is a real threat for any deployment where tool schemas are available. The oracle catches data-flow errors cheaply, and a base model with four repair rounds might suffice. Two things argue for distillation. The base 7B may not diagnose tracebacks well, which the self-collaboration small-model collapse hints at. And held-out settings often lack precise schemas to build stubs from. The test-time-oracle baseline settles the first point. Evaluating on the WikiHow open-grounded split, where no oracle exists, settles the second.

Why not generate repair data programmatically by corrupting correct workflows? Swapping two dependent steps and pairing the crash with the known fix needs no teacher at all. This may work as well as teacher repairs. If it does, the multi-agent teacher is unnecessary and we will say so. We therefore include a corruption-repair arm at matched tokens. Our expectation is that injected errors are cleaner than the errors models actually make, and that the resulting student will under-perform on its own natural mistakes. Only the experiment can show that.

Why not hand ordering to a topological sort or planner? A sort only orders a graph whose edges are already known. The hard part, as the chain-versus-graph gap shows, is inferring the edges from natural language. LTLCodeGen's 7.84% end-to-end baseline shows how badly formal translation fails without repair.

Decisive Checks

The primary result is the held-out graph-structure score on Seal-Tools and InterCodeSQL across all arms, over three seeds. It is paired with first-attempt violation rate, which the oracle measures directly. We also report in-distribution step-order and graph-structure scores to check that transfer is not bought with in-distribution losses.

Two further checks probe what was learned. For robustness to serialization, we shuffle the order in which tools and task facts are presented, following the permutation protocol of Can Graph Descriptive Order Affect Solving Graph Problems with LLMs?. A student that has learned dependencies should lose less than one that has memorized layouts. For errors the oracle cannot see, we score WikiHow ordering with the WorFBench metrics alone.

Cost is reported as calls and tokens per task against the teacher, alongside MapCoder's 16.7 calls per problem as a reference scale.

The idea is supported if the repair-trained student beats both WorFBench-SFT and verified-final-only on held-out graph score and first-attempt violations. It is refuted if verified-final-only or corruption-repair matches it.