Dynamic Workflows for LLMs: The Engineering Evolution of Orchestration Logic
This article examines dynamic workflows as an engineering approach to orchestrating large language models for large-scale, long-running software tasks. It traces the progression from single-session agents to subagents, agent teams, and finally code-driven dynamic workflows, explaining the context-window and attention-dilution bottlenecks that limit model-based orchestration. The core shift is moving the orchestration plan from natural-language decisions into executable code executed by a separate runtime, so the model is only invoked at predefined nodes with trimmed, high-signal input. The article includes a pseudocode skeleton, five engineering benefits, a five-stage practice for large-scale code migration, and the risks and boundaries of the approach. The main takeaway: when task scale exceeds context capacity, the answer is a different orchestration paradigm—describe the flow in code, carry state in a runtime, and protect attention with aggregated summaries.
Introduction: When Task Scale Breaks the Context Boundary
In late May 2026, a leading AI research organization released a new flagship model alongside a research preview capability for complex task orchestration called dynamic workflows. The motivation is a pain point repeatedly confirmed in engineering practice: in legacy systems spanning hundreds of thousands of lines of code, tasks such as defect investigation across an entire service, framework migrations touching hundreds of files, and technical designs requiring multi-perspective stress testing all exceed what a single conversation round can coordinate.
A widely cited practice case: a core team behind a scripting runtime used about 11 days to complete a code migration of roughly 750,000 lines of a systems programming language, while maintaining a 99.8% pass rate on the existing tests. The dynamic workflow mechanism handled the primary orchestration work. The significance of this number is not speed, but that it proves programmatic orchestration can reliably drive ultra-large-scale, long-cycle software engineering tasks.
1. The Four-Layer Evolution of Collaboration: Where the Bottleneck Is
To understand the positioning of dynamic workflows, it helps to lay out the collaboration layers that AI coding tools already have.
The first layer is single-session mode. A single agent instance advances serially, owning the context from reading requirements to producing results. Its advantage is a short, highly controllable chain; its drawback is that throughput is limited by a single context window.
The second layer is the subagent mode. A main agent spawns multiple helper agents responsible for retrieving files, reading code, and executing commands, then returning conclusions. This layer introduces parallelism, but the aggregation point remains singular.
The third layer is the agent team mode. Multiple independent coding agent instances work in parallel and can exchange information with one another, suited to division of labor with clear responsibility boundaries.
The fourth layer is the dynamic workflow. The first three layers share a structural bottleneck: the orchestrator is always the large model itself. It must decide, round by round, “who does what next,” and every subtask’s returned result must first enter the main model’s context and be fully read before subsequent actions can be decided.
This leads to two inevitable problems. The first is capacity: the intermediate products of dozens of parallel tasks (log fragments, file contents, test results) rapidly crowd out window space. The second is attention dilution: massive process information drowns out the decision criteria that actually matter, and the model’s effective reasoning quality decays as task scale grows.
2. The Core Paradigm Shift: Writing the Plan into Code
The idea behind dynamic workflows can be summarized in one sentence: migrate the orchestration plan from natural-language decisions to executable code.
Concretely, the model no longer schedules round by round itself. Instead, it first outputs a script that hard-codes the loop structure, conditional branches, failure retries, and intermediate-result aggregation, then hands it to a separate runtime for execution. The runtime handles scheduling and state management, and the model is only invoked at nodes predefined by the script—each invocation facing trimmed, high-signal information.
A schematic script skeleton follows (pseudocode):
// Orchestration script generated by the model and executed by a separate runtimeconst targets = await discoverFiles({ pattern: "**/*.rs", limit: 800 });const results = await mapLimit(targets, 16, async (file) => {const plan = await callModel({ role: "planner", input: summarize(file) });const patch = await callModel({ role: "coder", input: plan });return verify(file, patch); // compile + unit tests});const summary = await callModel({role: "reviewer",input: aggregate(results) // return only the aggregated summary, not the full logs});
Three design points in this code are key: concurrency is explicitly controllable; context is trimmed and aggregated before entering the model; and failure branches are decided by code rather than by the model on the spot.
3. Engineering Value: Why Scripts Are More Reliable Than Conversations
First, determinism improves significantly. Loop counts, concurrency limits, and retry policies are code semantics, unaffected by the model’s improvisation, so tasks are reproducible and auditable.
Second, the context budget is controllable. Intermediate products stay on the runtime side, and only aggregated summaries flow back to the model, fundamentally alleviating window expansion.
Third, the cost structure is better. The number of model calls and the input size are statically determined by the script, making it easy to estimate resource consumption in advance and to compress overhead through caching and incremental strategies.
Fourth, long tasks are recoverable. Script state is persisted by the runtime, so an interrupted task can resume from a checkpoint, whereas a purely conversational long task often has to start over once context overflows.
Fifth, the human-machine collaboration interface is clearer. The script itself becomes a readable, reviewable, version-controllable artifact, and engineering leads can review whether the orchestration strategy is sound before execution.
4. Implementation Practice: A Large-Scale Code Migration Example
Using dynamic workflows for cross-language migration can be broken into five stages.
Stage one, asset inventory. Use a read-only script to enumerate files, dependencies, and build targets, producing a structured list and avoiding blind searching by the model in noise.
Stage two, batch partitioning. Split batches by dependency topology rather than file count, ensuring low internal coupling and independent verifiability within each batch—this is key to containing failure propagation.
Stage three, the generation-and-verification loop. Each batch runs three steps: generate a patch, compile, and run tests. If verification fails, retry with the error information; once a threshold is exceeded, mark it for human intervention.
Stage four, aggregation and convergence. The runtime aggregates the results of each batch, clusters the failures, and hands them to the model for root-cause analysis, rather than feeding all logs back.
Stage five, regression gatekeeping. Full tests and performance-baseline comparison are run together at the end, forming a deliverable acceptance report.
Three lessons from practice are worth emphasizing: higher concurrency is not always better and must match build resources and downstream service quotas; the verification step must be genuinely executable, otherwise errors accumulate and amplify across batches; and human checkpoints should be placed at semantic decision points, not mechanical execution points.
5. Risks and Boundaries
Dynamic workflows are not a cure-all. They require that tasks can be clearly partitioned and have automated verification means; for exploratory tasks with highly ambiguous requirements and subjective acceptance criteria, the benefits are limited. Script generation itself can also be wrong, so static review and sandbox isolation are needed. In addition, observability at the orchestration layer must be built in advance, using general-purpose logging services and monitoring and alerting capabilities to track the status of each batch; otherwise, the cost of locating problems in long tasks is extremely high.
Conclusion
From single-session to subagents, then to agent teams and dynamic workflows, the main thread of evolution has always been to move uncertainty from the execution layer up to the planning layer and to make planning results engineering-manageable. For developers, the real insight to build is this: when task scale exceeds context capacity, the answer is not a bigger window but a different orchestration paradigm—describe the flow in code, carry state in a runtime, and protect attention with aggregated summaries. In the engineering practice of cloud platforms such as Baidu AI Cloud, this kind of layered design where “the model handles judgment and code handles the flow” is becoming a foundational paradigm for building reliable automated R&D systems.
