DynaFlow: Teaching a Main Agent When to Collaborate and How to Wire the Work
Systems that combine several LLM agents usually fix the roles and the order of conversation in advance. Yet a simple question may need only one agent, independent subtasks can run in parallel, and dependent stages need reliable access to upstream results. Applying one fixed collaboration structure to every problem adds unnecessary communication, latency and computation.
DynaFlow is a framework in which the agent solving the task, the Main Agent, decides whether collaboration is needed this time, and if so writes a question-specific workflow as a JavaScript program, runs it, and uses the results to choose its next action. Only the Main Agent is trained; the sub-agents that do the delegated work stay fixed. The authors call the target capability "Free Orchestration": deciding when collaboration is useful and constructing task-specific workflows during problem solving. Source: Abstract, §1, pp. 1–2
Method 1: putting workflows into the Main Agent's action space
Figure 2 gives the overview. From left to right: (1) two-stage supervised fine-tuning (SFT) trains only the Main Agent; (2) the Main Agent chooses to answer directly, call a tool, or generate a JavaScript workflow; (3) frozen sub-agents collaborate according to the program; (4) outputs and execution traces are appended to the history and inform the next decision. The example query (which female artist guest-judged Under the Gunn, and when her music career started) is handled by one program that combines Wiki and web search, artist identification, retrieval of the start year, and a verification step. Source: Figure 2, p. 2
Equation (1) defines the action set:
is the set of ordinary tool calls, is the final-answer action, and is a single workflow action consisting of a JavaScript program written by the Main Agent and its invocation through the workflow tool . At turn , the policy produces action conditioned on the instruction , the question , and the history of previous actions and observations. Invoking a workflow returns the observation , which combines the program output with an execution trace recording the status and output of each sub-agent call. The Main Agent appends to the history; if it judges the information sufficient, it answers and stops, and otherwise it uses a tool or another workflow to verify, refine or extend the results. Algorithm 1 gives this loop as pseudocode. Source: §3.1, Eq. (1), Algorithm 1, pp. 3–4
The program interface is deliberately minimal. agent(prompt, options) launches one sub-agent and, when given a JSON schema, returns a validated structured object. parallel(thunks) runs calls concurrently, pipeline(items, stages...) pushes each item through dependent stages, and phase(title) labels a stage. Intermediate outputs are passed and transformed with ordinary JavaScript. Crucially, a sub-agent receives only the instructions and inputs specified by the program; the Main Agent's interaction history is not inherited automatically. The Main Agent must therefore state in code what information reaches each downstream stage. Execution happens in a resource-constrained runtime. Source: §3.1, Appendix B, Appendix F Figure 7, pp. 3, 12, 14
Two execution modes are evaluated. In Dynamic mode, the first decision chooses between a direct answer and a workflow. In Forced mode, the first substantive action must invoke a workflow, which measures workflow construction without the initial routing decision. In both modes, once a workflow is invoked the Main Agent is limited to planning, launching, monitoring, revising, assessing returned results and summarizing the final answer; substantive solving is delegated to sub-agents. The Forced prompt in Figure 7 also forbids the Main Agent from deriving the answer itself in its first turn or handing sub-agents a pre-solved answer. Source: §3.1, Appendix F Figure 7, pp. 3, 14
Method 2: two-stage SFT with defect-based selection
Training has two stages. Both update only the Main Agent and keep the sub-agents fixed.
Stage 1 (trajectory distillation). The teacher model GLM-5.3 Max generates trajectories with the same workflow interface, tools and fixed sub-agents. Only trajectories with a correct final answer that follow the delegation protocol, with substantive solving inside workflows, are kept. The supervised target is the Main Agent's first-turn output , where is its reasoning and is the workflow action. The loss in Eq. (2) is
Formula: swipe horizontally →
It supervises both the reasoning tokens and the action tokens, while instructions, questions and tool definitions are masked. The learning target is thus first-turn task analysis and workflow synthesis; behavior from the second turn onward is not taught directly. Source: §3.2, Eq. (2), p. 4
Stage 2 (high-quality data selection). Stage 1 examples satisfy correctness and protocol criteria but vary in orchestration quality. The authors report that evaluating the Stage 1 model revealed failures in information transfer and incorrect Main Agent judgments steering workflows toward wrong answers. An LLM judge therefore inspects the question and program for three defect types:
- Premise injection: the Main Agent presents answer-determining claims that go beyond the task givens as established premises.
- Verification defects: review instructions or output constraints steer a verifier toward an expected answer or restrict independent checking and revision. Verification is assessed only when a reviewing step exists.
- Information-flow defects: missing context, incorrect references, lossy transfer, or hard-coded substitutes for upstream outputs keep required information from reaching downstream agents.
The judge is deepseek-flash (thinking enabled, high reasoning effort, temperature 0). It receives the question, the first-turn program and any launch arguments, but not the Main Agent's reasoning, final answer, reference answer or execution results. Each reported defect must be backed by an excerpt from the program or arguments, and the excerpts are checked against the supplied text. Writing this selection as , Eq. (3) gives . Of 2,257 examples, 712 remained. Stage 2 continues from the Stage 1 checkpoint with the same loss and a smaller learning rate. Source: §3.2, Eq. (3), Appendix E, pp. 4, 13
Experimental conditions
Evaluation covers six benchmark sets with 688 questions: 30 each from AIME 2024, 2025 and 2026 (integer answers), 200 from multilingual mathematics PolyMATH, 198 from the graduate-level multiple-choice science set GPQA-Diamond, and 200 from multi-hop retrieval HotpotQA. The PolyMATH and HotpotQA subsets are sampled with seed 42, and HotpotQA uses web search. Source: §4, Appendix A, pp. 5, 12
The Main Agent backbone is Qwen3.5-27B, and in every setting the sub-agents use the same Base checkpoint without orchestration training. Both run with thinking enabled. Training data come from HotpotQA and BrowseComp: 2,257 examples in Stage 1 and 712 in Stage 2 (449 HotpotQA, 263 BrowseComp). The mathematics and GPQA question types are therefore not part of the training data. Training uses 4-bit NF4 QLoRA with LoRA rank 16 and 32, learning rates of (Stage 1) and (Stage 2), two epochs each, effective batch size 4, maximum sequence length 67,584, and no separate validation split. On two NVIDIA H100 80GB GPUs, Stage 1 took about 52 and Stage 2 about 17 GPU-hours, about 69 in total, excluding teacher trajectory generation, evaluation and LLM judging. At inference, the Main Agent has a 131,072-token context and 81,920 maximum output tokens, sub-agents have 65,536 maximum output tokens, and sampling uses temperature 1.0, top-p 0.95 and top-k 20. Source: Appendices A, C, D, Tables 3–4, pp. 12–13
Baselines use the same Qwen3.5-27B: CoT, CoT-SC aggregating five sampled answers, Self-Refine with iterative critique and revision, and the automated workflow method AFlow. AFlow reuses released workflows (the MATH workflow for AIME and PolyMATH, the HotpotQA workflow for HotpotQA and GPQA-Diamond) without new search on the evaluation tasks. Base + Web search is also included. The authors state explicitly that tool-free baselines lack retrieval access, so their HotpotQA results should be interpreted separately from search-enabled systems. Answers are extracted from the Main Agent's FINAL ANSWER line, and runs without a valid final answer count as incorrect. Source: §4, Appendices A, D, pp. 5–6, 12–13
Main results
Table 1 reports micro-averaged accuracy over all 688 questions. DynaFlow reaches 88.08% in Forced mode and 87.94% in Dynamic mode, 10.90 points above the strongest evaluated baseline, Self-Refine at 77.18%. The untrained Base scores 71.51% (Direct), 65.12% (Dynamic) and 75.87% (Forced). Source: Table 1, §5.1, pp. 5–6
- Mathematics. Forced mode solves all 90 AIME questions (100% on each year). On PolyMATH, Dynamic reaches 91.50% and Forced 90.50%, 3–4 points above the best baseline (Self-Refine, 87.50%). The authors' workflow analysis finds derivation, computation and verification stages combined, for example symbolic derivations paired with small-instance numerical checks that catch errors in intermediate expressions.
- Science (GPQA-Diamond). Forced reaches 84.85%, 7.07 points above Base Forced and above Base Direct (83.33%). Self-Refine (88.38%) and AFlow (87.37%) remain ahead. In failure cases, incorrect intermediate conclusions from sub-agents misguided later verification, and the Main Agent sometimes failed to prioritize correct evidence when synthesizing the final answer.
- Multi-hop retrieval (HotpotQA). Dynamic reaches 84.50% and Forced 83.50%, 6–7 points above Base + Web search (77.50%), and Forced also beats Base Forced (81.50%). The authors observe workflows that organize search around intermediate entities (for example, the city associated with a venue) and check that successive hops refer to the same entity, and offer this as a "plausible account" of the gains.
AI assessment. Much of the 10.90-point overall gap comes from HotpotQA. Back-computing correct counts from the Table 1 accuracies and question counts, on the 488 non-HotpotQA questions DynaFlow Forced scores about 89.96% (439 questions) and Self-Refine about 89.14% (435 questions), a gap below one point. On HotpotQA the tool-free baselines have no search, which is exactly the condition the authors say should be interpreted separately, and it weighs heavily in the overall average. In mathematics each AIME year has only 30 questions, so one question equals 3.33 points. The paper also does not report how many runs were performed per condition or the variance across runs.
Training stage versus execution mode
Tables 2 and 6 swap only the Main Agent. Overall accuracy is 71.51 / 65.12 / 75.87 for Base (Direct / Dynamic / Forced), 76.74 / 84.45 / 85.47 for Stage 1, and 77.18 / 87.94 / 88.08 for DynaFlow after Stage 2. Source: Tables 2 and 6, pp. 6, 15
Figure 3 shows, per benchmark, how Forced-mode accuracy changes relative to Base Direct. Without training, Base Forced drops by 16.7 points on AIME 2024, 23.3 on AIME 2025 and 2026, 4.0 on PolyMATH and 5.6 on GPQA-D; only HotpotQA, where workflows enable retrieval, improves (+34.0). In other words, asking a model that has not learned to orchestrate to use workflows makes it worse. After Stage 1, Forced matches or exceeds Base Direct on all six, and beats Direct within the same checkpoint by 8.73 points overall. The authors interpret this as orchestration training turning workflow access into effective collaboration, with gains beyond the trained Main Agent's standalone performance. Stage 2 further improves both Forced and Dynamic. Source: §5.2, Figure 3, pp. 5, 7
This comparison effectively serves as the paper's ablation. However, §3.2 itself says that an equal-size random-subset continuation control is required to separate the effect of curation from the effect of additional training, and no such result appears in the main text or appendices. The numbers in the paper alone therefore do not establish that the Stage 1 to Stage 2 improvement (85.47 to 88.08 in Forced mode) comes from defect-based selection (AI assessment). Source: §3.2, p. 4
How the workflows themselves changed
Figure 5 classifies Forced-mode programs along six dimensions (definitions in Table 5). For Base, 62.2% are "Single agent" workflows with one sub-agent, 87.4% pass no upstream output downstream, 85.0% have no dependencies, and 84.1% have no aggregation. After training, "Hybrid" workflows that combine parallel and sequential stages rise from 3.4% to 83.2% (Stage 1) and 85.6% (Stage 2), and "Consumed" programs, which pass upstream outputs and explicitly instruct downstream agents to use them, rise from 12.6% to 93.3% and 97.7%. Among dependency patterns, fan-in, where one agent combines several upstream results, reaches 49.0% in Stage 2; among aggregation strategies, "Correction/refinement" of upstream results grows from 28.1% to 35.9%. The average number of sub-agents per program falls slightly from 4.35 in Stage 1 to 4.16 in Stage 2. Source: §5.3, Figure 5, Table 5, pp. 7–8, 15
Figure 4 scores the first Forced-mode workflow on four criteria (task consistency, decomposition appropriateness, logical continuity, information-flow correctness) as 0 (major defect), 1 (minor weakness) or 2 (no defect). The share of defect-free workflows rises for task consistency from 73.3 to 83.3 to 86.0%, for decomposition from 85.0 to 93.4 to 96.1%, and for information flow from 78.5 to 89.9 to 91.3%. Major information-flow defects fall from 1.9% in Stage 1 to 0.9% in Stage 2. Logical continuity is already 95.0% for Base, which the authors attribute to Base's simpler workflows with fewer inter-stage dependencies. Scoring is done by deepseek-flash from the question and program only, without execution results. Source: §5.3, Figure 4, Appendix D, pp. 6–8, 13
AI assessment. These design-quality scores come from the same model (deepseek-flash) that selected the Stage 2 data, and the criteria overlap with the defect types. Part of the post-Stage 2 improvement may therefore reflect moving toward what the judge prefers. §3.2 says the judging rubric and agreement with manual annotation are described in Appendix E, but no agreement figure appears there.
Figure 6 breaks down the roles of executed sub-agents. On AIME, Solvers account for 49.7% and Verifiers 43.9%; on PolyMATH, 46.8% and 43.3%, together over 90%. Researchers make up 59.6% on HotpotQA, and GPQA-Diamond combines 41.6% Solvers with 15.7% Researchers. Verifiers account for 33.2–43.9% across all tasks. Roles are classified by keywords in node labels, with phase names as a fallback. The Main Agent also writes each sub-agent's instruction per question, specifying its objective, relevant inputs and how to use upstream results. Source: §5.3, Figure 6, Appendix D, pp. 8, 13
Deciding whether to invoke collaboration
The Dynamic–Forced accuracy gap narrows from 10.75 points for Base to 1.02 after Stage 1 and 0.14 for DynaFlow. In Dynamic mode, DynaFlow answers 47.1% of questions directly without a workflow and still reaches 87.94%, close to Forced at 88.08%. Including directly answered questions, it uses 2.44 sub-agents per question versus about 4.16 under Forced execution, a reduction of about 41%. Figure 1 plots "agent roles per question" on its horizontal axis and places Dynamic at 3.44 with 87.9%. The authors argue that adding agents does not necessarily improve performance, and that the choice between answering directly and running a workflow is itself part of orchestration. Source: §5.4, Figure 1, pp. 1, 8
The efficiency metric reported in the paper is sub-agent count; wall-clock time, token usage and cost are not reported.
Individual cases
Appendix H compares Base and DynaFlow workflows under Forced execution with fixed sub-agents. These are selected cases, not statistical claims.
- AIME 2026 palindrome counting (Figure 8). Base hands the problem to one solver, which returns 59 after an arithmetic error. DynaFlow runs enumeration, dynamic programming and inclusion–exclusion in parallel, then passes their outputs to a verifier that compares them and recomputes independently in Python. All three methods and the verifier obtain 62. The retry branch was not triggered.
- GPQA-Diamond reaction products (Figure 9). Base runs two analyses in sequence without passing results between them. DynaFlow assigns four research calls to distinct chemical constraints, has each reaction's candidate challenged, and gives the decision agent both the research evidence and the verification results (the figure shows the second invocation).
- HotpotQA person and year identification (Figure 10). DynaFlow gathers candidates through three search routes, deduplicates and ranks them under a top-three cap, assigns a resolution agent to each candidate, then verifies with an adversarial check and an independent redo. Calls without valid structured output are filtered out.
- AIME 2025 geometric optimization (Figure 11). DynaFlow builds the geometry in two parallel ways, compares the results of three optimizers, fits the expression, and checks it with two audits. A conditional repair step runs if fewer than two audits confirm; here both confirmed, so it did not run.
Limitations stated by the authors and future work
The paper has no separate limitations section; §6 (Discussion) states the open issues. The GPQA-Diamond failure analysis shows that correct intermediate results can be lost or overridden during verification and final synthesis. As future work, the authors propose training sub-agents for reliable information transfer and independent verification, and extending first-turn supervision to multi-turn trajectories that contain disagreements and erroneous results. They suggest this could strengthen the Main Agent's ability to assess conflicting outputs, identify errors, and choose actions for error recovery, workflow revision and final-answer selection. Source: §6, p. 8
Further caveats readable from the paper itself (AI summary): both the Main Agent and the sub-agents come from a single model line, Qwen3.5-27B, and replication on other models is not shown. Training data are built only from HotpotQA and BrowseComp, and the paper does not say how overlap between training data and the 200 evaluated HotpotQA questions was avoided. There is no control isolating the Stage 2 selection effect and no measurement of wall-clock time or token volume. The gains on mathematics, outside the training distribution, are interesting, but these six evaluations do not establish how general they are.
How this applies to autonomous agent development
What follows is AI assessment. Three design ideas from DynaFlow seem most transferable to practice.
- Make the information passed to sub-agents explicit. If sub-agents do not inherit the Main Agent's history and see only what the program passes, then "what reaches which downstream stage, and in what form" becomes something that can be inspected. The rise of "Consumed" programs in Figure 5 and the information-flow gains in Figure 4 indicate that this behavior can change with training.
- Select training data by orchestration defects, not only by correct answers. Premise injection, steered verification and lost information are also usable as checklist items when reviewing one's own multi-agent logs. Whether such selection actually improves performance, however, should be tested against an equal-size random selection in one's own setting.
- Treat whether to collaborate as a learnable decision. For the untrained model, forcing workflows sharply lowered mathematics accuracy. Rather than expecting a collaboration layer to help by default, measure it against direct answering in each execution mode.
At the same time, these results come from one 27B model line with fixed sub-agents and six problem types with clear correct answers. The paper does not show that they carry over to agents that write to external systems, run long jobs, or work on tasks whose correctness is hard to judge. Given that much of the headline gap stems from the search-access difference, it is sensible to compare direct answering, existing self-refinement and workflows under the same conditions on one's own tasks before adopting the approach.


