DynaFlow: A Main Agent Writes Code for Its Team of Sub-Agents and Solves Every AIME 2024-2026 Problem

DynaFlow orchestration

Hard tasks are increasingly handled not by a single neural network but by a team of AI agents: one searches for information, another does the work, and a third checks the result. Researchers from the National University of Singapore have shown, however, that such a team does not make answers more accurate on its own. Without skilled multi-agent orchestration, it even makes them worse. When the researchers let an untrained Qwen3.5-27B use sub-agents, its accuracy dropped from 72% to 65%.

The problem was that the model did not know how to lead agents. Most often it handed the whole task to a single agent. At the same time, when it did build a team, the agents barely shared results: only 13% of the time did one agent’s output reach the next one. To teach the model to lead, the researchers built the DynaFlow framework. The main agent first assesses the task. It then solves simple ones by itself. For hard ones, it assembles a team of agents and writes a short script that spells out who does what, who passes results to whom, and who checks them.

What DynaFlow achieves after training

Both the main agent and its helpers run on Qwen3.5-27B, but in different versions. The authors fine-tuned the main agent to lead a team of sub-agents, with the teacher model GLM-5.3 Max as a guide. The sub-agents are a frozen copy of Qwen3.5-27B, and each one gets its own role and instructions from the main agent. As a result, after training the model answers almost half of the questions (47%) on its own, without helpers. On average, it calls 2.4 helpers per question instead of 4.2.

This saves compute, since each helper is a separate model run, and accuracy barely changes: 87.94% versus 88.08% when it always calls the team. In addition, it solves all 90 AIME olympiad problems from 2024-2026 correctly. Training took about a day and a half on two H100 GPUs. The authors released the code on GitHub under the MIT license. It runs DynaFlow on any model available through an API. Worked examples are on the project page.

Multi-agent orchestration and accuracy: overall accuracy versus the average number of agent roles per question for untrained Qwen3.5-27B, DynaFlow, and the CoT, CoT-SC, Self-Refine and AFlow methods
More agents is not better: the untrained model drops to 65.1% in Dynamic mode, while DynaFlow holds 87.9%

Why multi-agent orchestration should adapt to the task

Orchestration describes how agents split the work: who does what, in what order, and how they exchange results. Usually, developers fix it in advance, and it stays the same for every task. Yet a simple question needs only one agent, independent subtasks run faster in parallel, and at dependent stages each agent must receive the previous one’s result. The authors call the needed ability Free Orchestration: the model decides whether it needs a team and builds one for the task as it goes.

How multi-agent orchestration works in DynaFlow

At each step, the main agent picks one of three actions: answer, call a tool such as web search, or write a script for a team. The authors call this script a workflow. It is a JavaScript program in which agent calls a sub-agent, parallel runs several calls at once, and pipeline chains dependent stages. A sub-agent sees only what the script passes to it and knows nothing of the main agent’s reasoning. The main agent receives the result and a log of each sub-agent’s answers. Then, based on them, it decides whether to answer, double-check, or launch a new workflow.

Four panels: two-stage SFT of the main agent, the choice between an answer, a tool call and a JavaScript workflow, workflow execution by frozen sub-agents, and results and traces returned to the history
The main agent chooses an action, and frozen sub-agents run the script and return the results

Three modes

The authors tested DynaFlow in three modes:

  • in Direct, the main agent answers by itself, with no tools or sub-agents;
  • in Dynamic, it chooses between a direct answer and a workflow;
  • in Forced, it must launch a workflow.

In the last two modes, the main agent only plans and sums up, while the sub-agents do the solving and checking.

How the main agent was trained

The authors trained the main agent on ready-made examples (supervised fine-tuning) in two stages. In Stage 1, the teacher model GLM-5.3 Max solved tasks with the same sub-agents. Records of its solutions, meaning its reasoning and the scripts it wrote, became training examples. The authors kept about 2,000 correct solutions from HotpotQA and BrowseComp, two sets of questions that require web search. The model learned only how to break down a task and write the first workflow.

A correct answer does not mean the team was well organized. So in Stage 2, DeepSeek-V4.1-Flash acted as a judge and searched the teacher’s scripts for three types of errors.

  1. The main agent hands sub-agents unverified claims as facts.
  2. The instructions push the checking agent toward an expected answer instead of an honest check.
  3. The needed data never reaches the next agent. The authors call this an information-flow defect.

After filtering, 712 examples remained, and the authors continued training on them. Fine-tuning used QLoRA, which compresses Qwen’s weights to 4 bits, freezes them and trains only small added matrices, about 117 million parameters out of 27 billion.

Results

The authors evaluated DynaFlow on 688 problems from six benchmarks: AIME 2024-2026 olympiad math, multilingual math in PolyMATH, graduate-level biology, chemistry and physics questions in GPQA-Diamond, and HotpotQA, where the model builds the answer over several search steps. They compared DynaFlow with four approaches built on the same Qwen3.5-27B. In CoT, the model simply reasons step by step. CoT-SC produces five answers and picks the most common one. Self-Refine critiques and fixes its own answer. AFlow uses ready-made multi-agent workflows that an automatic search found in advance. Self-Refine was the best of them: 77.18% versus 88.08% for DynaFlow in Forced mode.

Accuracy table on AIME 2024-2026, PolyMATH, GPQA-Diamond and HotpotQA: CoT, CoT-SC, Self-Refine, AFlow, untrained Qwen3.5-27B and DynaFlow in Direct, Dynamic and Forced modes
Accuracy (%) on six benchmarks, all methods on Qwen3.5-27B

The biggest gain came in math, even though all training examples were search tasks: on PolyMATH, accuracy rose from 70.00% to 90.50%. In other words, the model seems to have learned how to organize teamwork, and this skill does not depend on the domain. On HotpotQA, the baseline methods have no search, so a fairer comparison is the same Qwen with web search. Even then, DynaFlow beats it by 6-7 percentage points.

Without training, the team only gets in the way. The untrained main agent (Base in the charts) in Forced mode loses to itself in Direct mode everywhere except HotpotQA, where the workflow gives access to search. On AIME 2025 and 2026, it loses 23.3 points on each. After training, Forced is no worse than Direct on all six benchmarks.

Bar chart of the accuracy change in Forced mode relative to Base, Direct on six benchmarks for Base, Stage 1 and DynaFlow
Without training, workflows lower accuracy on almost every benchmark

DynaFlow’s weak spot is GPQA-Diamond: 84.85% versus 88.38% for Self-Refine. Here, one sub-agent’s error throws off the next check, and the main agent also does not always pick the right arguments for its answer.

How multi-agent orchestration changes after training

The scripts themselves show why training helps. Before training, only 3.4% of scripts were hybrid, combining parallel and sequential stages. After training, by contrast, 85.6% were. The share of scripts that pass one stage’s result to the next with an explicit instruction to use it rose from 12.6% to 97.7%. Filtering examples in Stage 2 cut serious information-flow defects in half, from 1.9% to 0.9%.

How multi-agent orchestration changes after training: six heatmaps of execution structure, role specialization, dependency pattern, output reuse, aggregation strategy and sub-agent count for Base, Stage 1 and Stage 2
Six structural properties of scripts for Base, Stage 1 and Stage 2

The team also adapts to the task. In math, over 90% of calls go to solvers and verifiers, while on HotpotQA 59.6% go to researchers who look for information. For example, on a palindrome-counting problem from AIME 2026, the untrained agent gave everything to one solver and got it wrong: 59 instead of 62. DynaFlow launched three solvers with different methods plus a verifier, and all four got the correct answer, 62.

Multi-agent orchestration in DynaFlow on an AIME 2026 problem: one Base solver on the left, and on the right three parallel DynaFlow methods, enumeration, dynamic programming and inclusion-exclusion, whose results a verifier checks
Base and DynaFlow on the same AIME 2026 problem

Limitations

The authors did not fine-tune the sub-agents, so overall quality is capped by their own errors, as GPQA-Diamond shows. The main agent also learned only the first step and never learned to handle conflicting sub-agent answers. The main takeaway: multi-agent orchestration depends above all on how carefully agents pass, check and refine intermediate results between stages.


bnr2mob
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted