Agentic Coding in Practice: Role-Based Workflows and Adversarial Review
This article explains how to orchestrate AI coding agents as a team instead of relying on single-turn chat. It covers a minimal role set (Planner, Implementer, Reviewer, Verifier) with explicit output contracts, a checkable state machine that persists state and enforces gates, and an adversarial review process that treats finding defects as an independent goal. It also includes a lightweight scaffold layout, practical conventions, common anti-patterns, and the engineering practices needed to move AI coding from impressive demos to stable delivery.
1. The Problem: Why Smarter Models Do Not Deliver Proportionate Output
Many teams follow a similar curve after adopting AI coding tools: an impressive initial demo, followed by a plateau. The cause is usually not insufficient model capability, but an interaction model stuck in “single-turn conversation”: one context window, one role, one output. Real engineering collaboration never works that way. It consists of role separation, process constraints, handoff artifacts, and mutual verification.
Orchestrating agents as a team comes down to three things:
- Role separation: let the same model take on different responsibilities at different stages, with different evaluation functions and output contracts;
- Process enforcement: turn “requirements -> design -> implementation -> verification” into a checkable state machine rather than free-form work;
- Adversarial review: introduce an independent review role that stress-tests outputs with the explicit goal of finding problems.
Combined, these three form a tool-agnostic “thin scaffold”: it does not try to modify the model, it only adds engineering discipline around it.
2. Role Separation: Replace the “Universal Assistant” with Responsibility Boundaries
The biggest problem with a single role is conflicting goals: asked to both produce quickly and review strictly, the model tends to sacrifice the latter. The essence of role separation is splitting conflicting goals across different instances.
Recommended minimal role set:
- Planner: outputs only a structured plan and acceptance criteria, no implementation code;
- Implementer: makes changes strictly according to the plan, forbidden from expanding scope;
- Reviewer: read-only, raises and classifies issues against a checklist;
- Verifier: runs tests, reproduces issues, and reports repeatable experimental conclusions.
Each role should have an explicit “output contract”. For example, the planner must produce a task list and acceptance conditions:
# plan.yaml examplegoal: Add pagination and an idempotency key to the order query APIconstraints:- Do not change public library signatures- New logic must have unit test coverageacceptance:- Return a unified error code for invalid pagination parameters- Repeated requests return the first resulttasks:- id: T1desc: Define pagination parameter validation- id: T2desc: Introduce idempotency key storage and lookup
Passing information between roles through files rather than long conversations significantly reduces context drift.
3. Process Enforcement: Turn Collaboration into an Auditable State Machine
The key to process enforcement is giving every step an “entry condition” and an “exit condition”. A minimal, practical state machine looks like this:
BACKLOG -> PLANNED -> IMPLEMENTING -> REVIEWING -> VERIFYING -> DONE\-> REPLAN <----------------/
Engineering essentials:
- State persistence: state and handoff artifacts are written to disk (task lists, design notes, test reports), so any interruption can be recovered from;
- Single-step commits: each task corresponds to one small change, making rollback and localization easier;
- Gates: work cannot move from REVIEWING to VERIFYING until all “blocker” issues are cleared;
- Observability: write every state transition to a logging service, and use monitoring and alerting to track metrics such as rework rate and review issue density.
Illustrative process-driven pseudocode:
while state not in ("DONE", "ABORTED"):if state == "PLANNED":artifacts = planner.run(context())elif state == "IMPLEMENTING":artifacts = implementer.run(artifacts["plan"])elif state == "REVIEWING":findings = reviewer.run(diff(), checklist)if any(f.severity == "blocker" for f in findings):state = "REPLAN"; continueelif state == "VERIFYING":report = verifier.run(test_commands)if not report.passed:state = "REPLAN"; continuestate = next_state(state)persist(state, artifacts)
4. Adversarial Review: Make “Finding Problems” an Independent Goal
Adversarial review is not self-assessment by the model. It creates information asymmetry and role opposition:
- The reviewer receives only the diff and the acceptance criteria, not the implementer’s “explanation”, to avoid being persuaded;
- Use a tiered checklist: blocker (correctness/security/data consistency), major (maintainability/performance), minor (style);
- Require every issue to be reproducible or locatable to a specific code position, otherwise downgrade it to a suggestion;
- Require “counterexample construction”: the reviewer must provide at least one input or timing sequence that could trigger the defect.
Example review checklist:
[blocker] Can the idempotency key produce a race condition under concurrency?[blocker] Are pagination boundaries (0, negative, extremely large values) handled consistently?[major] Are the new branches covered by tests?[minor] Do the names follow existing conventions?
The benefit of this mechanism is that it turns “quality” from a matter of model self-discipline into an enforced process constraint.
5. Conventions for a Thin Scaffold
The goal of the scaffold is minimal intrusion, providing only “predictable ground”:
repo/.agent/roles/ # Role responsibilities and output contractschecklist/ # Review checklistsstate.json # Current state and task progressartifacts/ # Plans, designs, test reports
Four practical recommendations:
- Layer context: keep global conventions (coding standards, directory structure) resident, and load task context on demand to avoid wasting the window;
- Retrieval first: have the agent search before changing anything; retrieval can rely on code hosting platforms and general capabilities such as logging and monitoring;
- Small, rollback-friendly steps: task granularity should be “readable in one review”;
- Metrics-driven: track rework rate, number of review blockers, and time per task, and use data to decide whether to tighten gates.
6. Common Anti-Patterns and How to Avoid Them
- Role blending: the reviewer participates in implementation, leading to self-endorsement; keep read-only permissions.
- Empty process: all states exist but gates are ineffective; blocker issues must actually block transitions.
- Context bloat: stuffing all historical conversation into the window; replace conversational memory with handoff artifacts.
- Over-scaffolding: too many rules and high maintenance cost; stay thin and delete whatever can be deleted.
- Missing metrics: watching only output speed; also observe rework and defect density.
7. Conclusion
Orchestrating agents as a team is essentially using engineering discipline to constrain probabilistic systems. Role separation resolves conflicting goals, process enforcement resolves non-reproducibility, and adversarial review resolves self-certified quality. In environments with general capabilities such as container platforms, logging services, and monitoring and alerting, including Baidu AI Cloud, this tool-agnostic framework can be applied directly, moving AI coding from “impressive demo” to “stable delivery”.
