Dynamic Workflows: A New Approach to Solving Ultra-Long-Context Tasks

    This article examines why single-agent LLM systems struggle with large-scale engineering tasks such as migrating hundreds of thousands of lines of code, and introduces the dynamic workflow paradigm—a multi-agent architecture that decomposes complex work into a dependency-aware task graph, executes it in parallel, validates each step automatically, and maintains shared state across sessions. It covers the core design layers, key practical decisions, suitable use cases, and implications for engineering organizations, with references to a real-world migration of 750,000 lines of code completed in 11 days with a 99.8% test pass rate.

    Dynamic Workflows: A New Approach to Solving Ultra-Long-Context Tasks

    Introduction: When a Single Agent Can’t Finish the Job

    As LLM-driven programming tools evolve, developers have grown accustomed to delegating tasks like writing functions, fixing bugs, and reviewing code to AI agents. But the real engineering world contains another class of problems that has long remained outside the reach of automation: a runtime migration touching hundreds of files, a defect investigation spanning an entire service cluster, or an architecture proposal that must be stress-tested from multiple angles before it can be adopted.

    These tasks share a common trait—their scale exceeds what a single conversation can coordinate. Limited by context windows, attention decay, and state persistence, a single agent handling such tasks often shows an “early focus, late slack” pattern: the first half maintains rigorous reasoning and coding style, while the second half begins to show omissions, drifts, and even contradictions with earlier decisions.

    Recently, a new paradigm called Dynamic Workflows has emerged in the industry, specifically targeting tasks that “a single agent cannot finish in one run.” One widely discussed real-world case: a large runtime project used this approach to migrate approximately 750,000 lines of code from one systems-level language to another in about 11 days, with the existing test suite passing at close to 99.8%. The engineering significance behind that number deserves a detailed breakdown.

    Why Single-Agent Mode Fails

    Before discussing the new paradigm, it is important to understand the boundaries of the old one. The failure of single-agent mode can be attributed to three root causes:

    1. Physical limits of the context window

    No matter how large the window becomes, the code, dependencies, build configurations, and test cases of a large service can easily reach millions of tokens. Trying to cram all of that context into a single prompt is neither economical nor practical.

    2. Attention decay during long-range reasoning

    Even if the context fits, the quality of model reasoning degrades in later portions of long sequences. A common symptom in migration tasks: a core abstraction is modified early on, but files that reference it later are not updated in sync, causing compilation errors to snowball.

    3. Lack of structural self-verification and correction

    A single agent typically “thinks and acts” in a linear fashion, with no independent role reviewing its output. In a migration spanning hundreds of files, any miscomprehension accumulates and amplifies over time.

    Core Architecture of Dynamic Workflows

    The essence of dynamic workflows is to convert an oversized task into a decomposable, schedulable, and verifiable directed task graph, executed collaboratively by multiple agent instances. Its key design can be broken into four layers.

    2.1 Task Decomposition Layer: From Fuzzy Goals to Atomic Units

    The workflow entry point is a high-level goal (e.g., “migrate this codebase to the target language”). The orchestrator recursively decomposes the goal into a task tree:

    1. Goal: Full codebase migration
    2. ├── Subtask 1: Build dependency graph, identify module boundaries
    3. ├── Subtask 2: Migrate modules sequentially by dependency order
    4. │ ├── Migrate core scheduling module
    5. │ ├── Migrate network I/O module
    6. │ └── Migrate utility function set
    7. ├── Subtask 3: Migrate test suite and adapt assertions
    8. └── Subtask 4: Full regression and performance baseline comparison

    The critical decomposition principle is to make the lowest-level tasks as atomic as possible: a single agent can complete them within a manageable context, and the output can be mechanically verified (e.g., compilation passes, unit tests pass).

    2.2 Parallel Scheduling Layer: Dependency-Aware Multi-Agent Execution

    Once the task graph is generated, the orchestrator decides which nodes can run in parallel based on dependency relationships. For example, migrating utility modules that have no interdependencies can be dispatched to multiple executor agents simultaneously; but upper-level modules that depend on core abstractions must wait until their predecessor nodes complete and pass verification.

    The core problem this layer must solve is state consistency: parallel executors cannot arbitrarily modify shared interfaces. A common practice is to “freeze first, then propagate” shared contracts (type definitions, interface signatures)—the contract is defined and locked in advance, and subsequent tasks can only consume it, not change it.

    2.3 State Management Layer: Cross-Session Memory and Context Engineering

    A single agent’s session is short-lived, but a workflow may last for days. Therefore, an explicit state management mechanism is required:

    • Structured artifacts: After each task, the output includes code diffs, structured summaries, and pitfall records, not just natural language conversation.
    • Retrievable experience base: Insights discovered by earlier tasks (e.g., the correct way to handle a certain syntax mapping) are saved and injected into the prompts of later tasks.
    • Resumable execution: If any task fails or is interrupted, it can resume from the corresponding node in the task graph, rather than starting over.

    2.4 Verification Loop Layer: Make Machines the First Judge

    The reason the test pass rate reached close to 99.8% is that automated verification backs every step. The completion criterion for each atomic task is not “the agent says it’s done,” but “the compiler passes, relevant test cases pass, and static checks show no new warnings.” When verification fails, the failure information is fed back to the executor agent for retry; if it exceeds a threshold, it escalates to a higher-level planning agent that re-evaluates the decomposition plan.

    This “execute–verify–feedback” loop shifts the human role from line-by-line reviewer to process supervisor and final decision-maker.

    Key Design Decisions in Practice

    To implement a similar mechanism in your own team, several design decisions deserve careful consideration.

    1. Task granularity: too coarse stalls, too fine over-manages

    If granularity is too coarse, a single task again exceeds context capacity; if too fine, orchestration overhead and interface friction erode the benefits. The rule of thumb: the optimal atomic task size is “one focused session can complete it + one automated verification can confirm it,” typically corresponding to one module or one class of files.

    2. Migration order: bottom-up, dependency-first

    For language migration tasks, migrate the lowest-level libraries first that are most depended upon, so upper-level modules always have a usable dependency environment. The quality of the dependency graph construction directly determines the upper bound of parallelism.

    3. Contract-first: freeze interfaces to reduce parallel conflicts

    Before parallel agents start modifying, a planning agent produces the target language’s interface contracts (types, function signatures, error code conventions), which are confirmed and locked after manual or high-confidence verification, serving as the common constraint for all subsequent tasks.

    4. Keep human decision points

    Not every node should be fully automated. Decision points involving semantic ambiguity, breaking changes, or architectural trade-offs should be designed as collaboration nodes where “the agent provides multiple options with trade-off analyses, and a human makes the final call before continuing.”

    Applicable Scenarios and Boundaries

    Dynamic workflows are not a silver bullet. They are especially suitable for three types of tasks:

    • Large-scale mechanical refactoring: language migration, framework upgrades, API version switches
    • Wide-area investigation tasks: service-wide defect hunting, security vulnerability scanning and fix recommendations
    • Multi-perspective solution evaluation: the same solution is independently reasoned by multiple agents from different angles (performance, maintainability, cost) and then cross-examined

    Conversely, for tasks that are tightly coupled, highly creative, or have vague objectives (e.g., designing a brand-new domain architecture from scratch), premature mechanical decomposition may lock down the exploration space. In such cases, a more iterative, high-frequency human–machine interaction model works better.

    Implications for Engineering Organizations

    From an engineering management perspective, the shift driven by this paradigm is profound: the bottleneck in R&D is moving from “speed of writing code” to “maturity of task definition and verification systems.” Teams need to build capabilities such as machine-verifiable completion criteria, clear service boundaries and dependency documentation, and stable automated test assets. These are exactly the fundamentals that engineering effectiveness efforts have emphasized over the past years—the advent of the agent era simply amplifies their returns by an order of magnitude.

    For teams that want to build such automated pipelines in the cloud, it is practical to use a general container platform to host agent execution environments, object storage to accumulate task artifacts and experience bases, message queues to decouple scheduling between task nodes, and logging and monitoring services to make the whole pipeline observable. General cloud product categories offered by providers like Baidu AI Cloud can supply elastic compute and reliable infrastructure support for such multi-agent engineering pipelines; teams can combine them as needed, avoiding the need to reinvent the wheel.

    Conclusion

    11 days, 750,000 lines, 99.8% test pass rate—the real meaning of this set of numbers is not “agents can replace engineers,” but that when tasks are correctly decomposed, state is correctly managed, and output is correctly verified, multi-agent collaboration can reach unprecedented engineering scale. Dynamic workflows represent not a single product feature but an emerging new paradigm in software engineering. For developers, now is the best time to understand its principles, run small-scale experiments in their own contexts, and accumulate organizational-level engineering assets.