AI Coding Agent Dynamic Workflows: From Executors to Orchestrators
This article explains how AI coding agents are shifting from executing predefined task flows to acting as dynamic orchestrators that generate tailored workflows before execution. It covers the role of the Harness, when dynamic workflows are useful, how they run, common orchestration patterns, and practical examples such as reproducing flaky tests, running code review pipelines, and performing security attack-surface analysis. It also summarizes key design factors, common pitfalls, evaluation metrics, and recommendations for teams adopting this approach.
1. The Core Shift: From Executors to Orchestrators
AI coding agents are going through a role change: instead of acting as “executors” that complete a single task through a predefined process, they are becoming “orchestrators” that can assemble an execution plan on the fly for a specific problem.
In the industry, the outer system that drives a large language model is often called a Harness. It generally includes prompts, callable tools, a decision loop, context and state management, termination conditions, and error-recovery logic. In the past, this kind of system was usually designed in advance by a development team for general coding scenarios: reading code, modifying code, running tests, and continuing to fix issues based on errors. That was already good enough for most tasks.
However, the same predefined process often performs noticeably worse on several other types of tasks:
- Intermittent defect reproduction: requires frequent repetition and parallelism, as well as actively introducing perturbing conditions;
- Large-scale codebase investigation: requires breaking down the problem first and then aggregating the results;
- Code review: requires multiple perspectives to inspect changes in parallel;
- Security analysis: requires proposing hypotheses and verifying them one by one.
These tasks share a common trait: the goal is clear, but the path to reaching it varies from case to case. A single hard-coded process struggles to cover all these differences at once.
A dynamic workflow means the agent first decides, before execution, “What kind of task is this, and what execution structure does it need?” It then generates a dedicated orchestration plan and executes within it immediately. A useful analogy is that, when facing a new task, the agent first assembles a suitable “team,” clarifies responsibilities and handoff methods, and then starts working.
Note that “assembling a team” here refers to division of labor and collaboration at the orchestration level. It is different from framework-level multi-agent collaborative programming. The two can be combined, but they solve different problems.
2. How Dynamic Workflows Run
From a runtime perspective, a dynamic workflow contains four key stages:
- Diagnose: The agent analyzes the task goal, input materials, and acceptance criteria. It determines what category the task belongs to, where the difficulty lies, and which tools may be needed.
- Generate: The agent produces an executable orchestration plan that defines phase boundaries, parallelization methods, tools used in each step, how results are passed and aggregated, and under what conditions the workflow ends.
- Execute: During execution, the agent collects evidence step by step. If a branch does not work, it returns to the plan level and adjusts it—for example, by adding a verification round, changing the search angle, or narrowing the investigation scope—rather than blindly retrying.
- Persist and reuse: After the task is completed, the workflow can be saved and reused in similar tasks. Individuals encounter different problems, but the handling approach for similar problems can often be shared, such as “reproducing intermittent failures,” “batch review before commit,” or “attack-surface mapping for a core module.” The more workflows a team accumulates, the less it needs to start from scratch when facing new tasks.
In practice, it usually appears as executable orchestration code or a structured configuration that includes task decomposition rules, input/output conventions for each step, parallel strategies, and termination conditions.
The difference from traditional workflow orchestration lies in who designs it. In traditional approaches, humans write and fix the process during development, while the agent only executes along a predefined track. Dynamic workflows hand orchestration itself to the agent, which generates it according to the specific situation of each task. The trade-off is that this places higher demands on the agent’s planning ability and the reliability of the orchestration code.
3. Common Orchestration Patterns and Design Points
Different tasks suit different orchestration structures. Below are several common patterns and their design points.
1. Repeated Validation
Typical scenarios: intermittent defects, performance jitter, and issues related to timing dependencies.
Approach: Repeatedly execute the same operation in an isolated environment until the issue is reproduced or a maximum attempt count is reached. Randomization factors can also be introduced, such as shuffling execution order, adjusting concurrency, or injecting delays.
Design points:
- Isolated environment: avoid interference between repeated executions;
- Per-run timeout: prevent a single stuck execution from blocking the entire workflow;
- Total budget control: set upper limits on total attempts and total duration;
- Preserve the full scene on failure: include environment configuration, input data, and logs.
2. Fan-Out and Aggregation
Typical scenarios: codebase investigation, cross-module impact analysis, and batch checks across multiple files.
Approach: First split a large problem into several non-overlapping subproblems. Assign them in parallel to multiple execution units. Each unit handles only its own portion. Then aggregate and deduplicate the results to form an overall conclusion.
Design points:
- Divide by module or by problem type, and minimize overlap between subtasks;
- Define a unified output format to make later aggregation easier;
- The aggregation stage should verify whether conclusions from different subtasks are consistent. If conflicts appear, return to the source and re-check.
3. Pipeline
Typical scenarios: code review, document generation, and pre-release checks.
Approach: Split the work into a series of connected stages where the output of one stage becomes the input of the next. For example: “collect changes → review by perspective → summarize and rank → output report.” Each stage should have a quality gate. If it does not pass, it must be sent back for repair, and problems should not be allowed to flow forward.
4. Hypothesis Falsification
Typical scenarios: root-cause analysis, security analysis, and troubleshooting difficult issues.
Approach: First list several hypotheses that may be true. Then design a decidable verification method for each hypothesis and try to refute it one by one with evidence. The key to this pattern is falsification: only a judgment that is either disproved or confirmed by evidence counts as a conclusion. The temporary absence of a counterexample does not mean a hypothesis is valid.
5. Multi-Role Collaboration
Typical scenarios: complex tasks where planning and execution need to be separated.
Approach: Define roles such as planner, executor, and reviewer, each focused on one type of work. The planner breaks down the task and decides the order. The executor carries out concrete operations. The reviewer independently checks whether the execution results meet requirements. Roles hand off through structured intermediate artifacts rather than relying on lengthy conversations.
4. Example 1: Reproducing an Intermittent Test Failure
Assume a test fails about once every 50 runs. When it fails, it leaves only a vague error message, making it difficult to locate the cause by simply reading the code.
Statistical premise:
- If each run is independent and the failure probability is constant at 1%, then the probability of not observing a failure after
nconsecutive runs is0.99^n. - To make that probability lower than 5%—that is, to have about 95% confidence of observing at least one failure—you need about 300 runs (
ln(0.05) / ln(0.99) ≈ 298). - In practice, failures are often related to factors such as concurrency, execution order, and machine load. Simply repeating the same execution may not be enough. Those conditions also need to be changed actively.
Dynamically generated orchestration approach:
# Illustrative orchestration code generated by the agent for flaky-test reproductiondef reproduce_flaky_test(hypotheses, max_rounds=400, parallelism=8, min_repros=3):for hyp in hypotheses: # Test each hypothesisruns = [prepare_run(hyp, seed=i) # Each run has an isolated environment and independent seedfor i in range(max_rounds)]results = run_in_parallel(runs, workers=parallelism, timeout_s=60)failures = [r for r in results if r.failed]if len(failures) < min_repros: # Not enough evidence; park the hypothesis for nowlog(f"{hyp.name}: No stable reproduction observed; more samples or new conditions are needed")continuereport = {"hypothesis": hyp.name, # Example: unsynchronized shared cache"repro_rate": len(failures) / max_rounds,"evidence": [f.artifact_path for f in failures[:5]], # Logs, stack frames, and scene snapshots"minimal_case": shrink(failures[0]), # Automatically shrink the reproduction case}return report # Stable reproduction found; stop immediatelyreturn {"status": "unresolved", "tried": [h.name for h in hypotheses]}
This example illustrates several points of the pattern:
- Each experiment uses an independent seed, so results are reproducible;
- Execution is parallel, but each run has a timeout;
- A hypothesis is considered valid only after enough failures have been observed;
- Once stable reproduction is achieved, the workflow stops immediately, automatically shrinks the reproduction case, and outputs a conclusion with evidence.
Another common approach can also be added here: when the failure rate is very low, actively searching for the failure condition is often more effective than blindly repeating the test. For example, one can use the test framework’s built-in “repeat run” option or reorder tests in a specific sequence to increase the probability of triggering the issue.
5. Example 2: A Code Review Pipeline
When a change involves dozens of files, the agent can easily lose balance: it may examine the first half carefully but become increasingly perfunctory in the second half, or only spot superficial issues that are easiest to detect.
Dynamically generated orchestration approach:
review = {"input": collect_changes(against="main"), # Collect the list of changed files and diffs"stages": [{"name": "Partition", "output": "Diff segments split by directory or functional module"},{"name": "Review", "mode": "parallel", # Review from multiple perspectives in parallel"views": ["Correctness", "Test coverage", "Concurrency and boundary conditions", "Security and permissions","Maintainability", "Performance and resource usage"],"output_schema": ["file", "line", "severity", "reason", "suggestion"]},{"name": "Summarize", "task": "Merge duplicates, sort by severity, and unify wording"},{"name": "Verify", "task": "Check each finding against the source code and remove unsupported claims"},],"gate": "Produce the final report only after no high-severity items remain and verification passes",}
In this pipeline, the Verify stage is especially important. Large language models can easily turn guesses into conclusions—for example, claiming that a certain place “may have a concurrency issue” even though there is no shared state in the code. With an independent verification stage, every item in the report corresponds to an actual code location, allowing reviewers to make decisions directly based on the findings.
6. Example 3: Security and Attack-Surface Analysis
A typical security analysis approach is to first enumerate possible attack entry points and then verify them one by one. An agent can generate an orchestration plan like the following for a target module:
- Identify entry points: List all locations that receive external input, including interfaces, messages, files, and configurations;
- Trace data flow: Follow the path from input to usage and check whether validation and filtering are performed along the way;
- Generate hypotheses: For each entry point, propose possible risk hypotheses, such as “a parameter is not checked for length” or “a query condition can be tampered with”;
- Verify one by one: Construct minimal inputs to verify each hypothesis. Hypotheses that can be refuted by evidence are excluded directly. Only the remaining ones proceed to later manual review;
- Output conclusions: Each conclusion should state the relevant entry point, data path, and verification method, so security personnel can judge whether it constitutes a real risk.
The value of this orchestration lies in turning “experience-based scanning” into “checklist-based verification.” It provides broader coverage and produces conclusions that are easier to audit.
7. Key Elements in Designing Dynamic Workflows
- Context budget: Investigation-type tasks often generate more information than can fit into a single context window. The workflow can specify that each execution unit reads only the files or snippets it needs, while staged conclusions are passed upward as summaries. When necessary, work artifacts can be written to files or sent to a log service for unified storage, allowing later stages to retrieve them as needed.
- Termination conditions: Each stage should define clear completion criteria, such as “find at least 3 reproducible failures,” “all hypotheses have been verified,” or “reach the maximum number of rounds or the maximum duration.” A workflow without termination conditions can easily fall into endless retries.
- State and isolation: Parallel execution units should ideally run in separate directories, environments, or containers to avoid issues such as file overwrites, port conflicts, or cache pollution.
- Least privilege: The workflow should only grant the permissions required to complete the current task. Write operations and high-risk commands require explicit confirmation. Orcheation code generated by the agent is essentially code that will be executed, so basic checks should be performed before execution, and high-risk steps should preferably run in environments with isolation capabilities.
- Observability: Record the inputs, outputs, duration, and conclusions of each stage. This makes troubleshooting easier and also provides data for evaluating the strengths and weaknesses of different orchestration approaches.
- Incremental generation: For complex tasks, there is no need to generate the complete workflow at the very beginning. One can first generate a minimal version, test it, and then gradually extend it based on the results.
8. Practical Advice and Common Pitfalls
Practical Advice
- Start with simple tasks: First try the approach in scenarios with clear task boundaries and easily verifiable results, such as reproducing intermittent defects, batch checks, and document organization;
- Define the task clearly: Clearly explain the goal, constraints, accessible materials, and acceptance criteria to the agent. Orchestration quality often depends on how complete this information is;
- Manually review key outputs: This is especially important for final reports and code changes. Human oversight remains essential;
- Turn effective workflows into team assets: Manage them centrally, maintain versions, and periodically remove leftover sensitive information.
Common Pitfalls
- Overestimating applicability: For tasks such as single-file edits or simple Q&A, direct conversation is often faster. Applying a complex workflow only increases cost;
- Looking at conclusions without evidence: Conclusions from workflows still need to be checked against the original materials, especially for judgments involving security and correctness;
- Ignoring execution cost: Large-scale parallelism can significantly increase compute resource consumption. Budget limits should be set according to the value of the task.
9. How to Evaluate the Value of Dynamic Workflows
After introducing a new way of working, data should be used to judge whether it actually brings benefits. Comparison can be made across the following dimensions:
- Effectiveness: Whether the task achieves its goal and whether the conclusions hold up under verification;
- Efficiency: The time required to complete the task and the number of human interventions;
- Cost: Whether compute resource consumption stays within budget;
- Stability: Whether repeated runs on similar tasks produce consistent results.
A practical approach is to select a representative set of tasks, execute them with both the default process and dynamic workflows, record the above metrics, and compare the results. If the advantage is not obvious, go back to the workflow design and look for the cause. Often, the termination conditions, context division, or verification stage still need adjustment.
10. Conclusion
Dynamic workflows represent an evolution in human-agent collaboration. In earlier models, humans wrote rules and the agent executed them. In the default-process model, the agent completed tasks along a predefined path. In the dynamic-workflow model, the agent designs its own execution plan based on the task at hand. The role of humans also changes: instead of writing every rule step by step, they propose goals, define boundaries, set acceptance criteria, and take responsibility for the results.
For this capability to be genuinely useful, three things are key: clearly describing task goals, constraints, and acceptance criteria; maintaining necessary review over agent-generated workflows and conclusions; and turning validated approaches into reusable team assets. When these are in place, AI coding agents can grow from “helping you write a piece of code” into “helping you systematically solve a category of problems.”
