Separation of Duties for AI Code: Verifying Generated Changes With Role-Based Multi-Agent Review
Separation of Duties for AI Code: Verifying Generated Changes With Role-Based Multi-Agent Review
Most teams verify AI-generated code the way they verify their own: read the diff, run the test suite, ship if it is green. That habit holds up until the model that wrote the code is also the model you ask to check it. Verification gets stronger when you split the work across roles — and treat those roles as a control, not a prompt trick.
Self-review is a weak signal
When you ask a model to review code it just wrote, you are asking it to re-examine assumptions it has already committed to. If it misread the schema, it will misread the schema again in review. If it assumed a function was idempotent, the review will assume the same.
Imagine a model writes a retry wrapper around an HTTP call. Asked to review its own work, it reports that error handling looks solid. A second model, given only the diff and the interface contract, notices the wrapper catches a broad exception type and swallows a timeout that should have propagated. Same code, different question, different answer.
That gap is the point of separation of duties. It is standard practice in software testing and in any serious developer QA process: the person who builds the thing is not the only person who signs off on it.
Assign roles, not just prompts
A role is a scope, a model, and a definition of done. Four roles cover most changes:
- Author — writes the change and states the contract it is supposed to satisfy. - Adversarial reviewer — has one job: produce an input, sequence, or state that breaks the change. Not "review this," but "find the case where this fails." - Test author — writes tests from the specification, not from the implementation. Tests derived from the code inherit the code's mistakes. - Integrator — applies the change, runs the full suite, and reports what actually happened.
The important detail is what each role can see. Give the adversarial reviewer the artifact and the contract, not the author's reasoning. Reasoning is persuasive; you want the reviewer judging behavior.
This is where multi-agent collaboration earns its keep. Different models have different blind spots, so a reviewer that is not the author is a genuinely independent check rather than a second opinion from the same source. VIBA is built for this: you can run several models — ChatGPT, Claude, Gemini and others — in one shared session, assign each one a role, and approve key steps yourself as the work moves forward.
Make the output something you can check
Roles are useless if the result is a paragraph of reassurance. You want artifacts.
For a backend change, that means running the code against the actual repository rather than a snippet pasted into a chat window. Repo testing catches what only exists in context: the validator wired into the create path but not the update path, the import that resolves differently under the project's module settings, the test that passes because it was never actually invoked.
For a front-end change, UI testing against a running interface catches what a diff never will. A form validation change can be logically correct and still render its error message off-screen on a narrow viewport. A button can be disabled for the right reason and still be unreachable by keyboard.
Before a wider rollout, beta testing gives you a stage between "passes locally" and "in front of everyone." And when several checks fail at once, a ranked repair report matters more than a raw list — you need to know which failure to fix first, not just that there are eleven of them.
For example, you could run a change through three roles and get back a UI failure on error message placement, a repo test failure on the PATCH path, and a passing unit suite. The ranked report tells you the PATCH path is the one that will corrupt data, so it goes first.
Keep humans on the irreversible steps
Automation should carry the work up to the point where a mistake stops being cheap to reverse. Some changes deserve a human decision every time:
- Schema migrations and anything that rewrites existing rows. - Dependency upgrades that change transitive behavior. - Authentication, authorization, and permission boundaries. - Anything that moves money, deletes data, or calls an external system with side effects.
Approval at these points is not a lack of trust in the agents. It is a recognition that the cost of a wrong answer is asymmetric. A rejected change costs a few minutes; a dropped column costs a weekend.
Cost visibility belongs in the same conversation. When you can see spend per agent, a loop that keeps retrying shows up as an anomaly in the numbers rather than as a surprise on an invoice. That is a signal to stop and look, and it is one reason to run AI tools in a shared session where you can see what each one is doing.
Verification is a design decision
You do not verify AI-generated code by asking harder questions of the same model. You verify it by splitting the work into roles, requiring artifacts you can inspect, and keeping a human on the steps that cannot be undone. That structure is what turns multi-agent collaboration from a novelty into a control you can rely on.
If you want to try role-based verification with several models in one session, start at https://www.viba.guru.
See VIBA: https://www.viba.guru