Automate AI Code Building and Review with Multiple Agents
Job to be done: Automate unsupervised AI code building and review using multiple AI agents
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Entrepreneur
Automate the creation and review of backend API endpoints for your startup's MVP, ensuring they adhere to your design specifications and handle edge cases correctly.
- 9-5 employee
As a data analyst, automatically generate and review Python scripts for routine data cleaning tasks, ensuring they correctly handle missing values and data type conversions according to company standards.
- Student
For your final year project, automatically generate and review Python scripts for data processing, ensuring they meet your project's technical specifications and performance targets.
What you’ll get
You will learn a structured approach to using multiple AI agents for building and reviewing code automatically. This method ensures that AI-generated code is trustworthy and meets specific requirements, even when you are not actively supervising the process. It’s useful for projects where you want to leverage AI for development but need robust checks to maintain quality and correctness.
Tools you need
- AI Code Generation Model (paid): An AI model capable of writing code based on detailed specifications. This is typically accessed via an API or a paid subscription service.
- AI Review Agent (paid): A separate AI model or instance tasked with reviewing the code generated by another AI, checking for correctness against specifications and performance targets.
Steps
-
Define the Plan and Specification: Clearly outline the task, including detailed steps, design decisions, and which AI agent will handle which part. Ensure the specification is precise, covering edge cases like empty inputs and error messages. The author emphasizes that “agreed-but-fuzzy” is not sufficient; the spec must be buildable without further human input.
- What to do: Write down a detailed plan for the code you want the AI to build. Include requirements, desired outcomes, and how to handle potential issues. This plan will be the primary guide for the AI agents.
- What you should see: A document or text file containing a precise, unambiguous plan for the code development task.
-
Assign Tasks to AI Agents: Based on the plan, assign specific coding tasks to a “builder” AI agent and review tasks to a separate “reviewer” AI agent. The author suggests matching the AI model’s capabilities to the task’s complexity, using cheaper models for simpler tasks and more advanced ones for complex judgment calls.
- What to do: Prepare prompts for your AI agents. One prompt will instruct the builder AI to write code according to the spec. Another prompt will instruct the reviewer AI to check the generated code against the spec and performance targets.
- What you should see: You will have distinct prompts ready to be sent to your chosen AI tools.
-
AI Builds the Code: The “builder” AI agent generates the code based on the precise specification. The author stresses that the agent that builds the code should not be the one to declare it finished or correct.
- What to do: Send the building prompt to your AI code generation tool. Provide the detailed specification as part of the prompt.
- What you should see: The AI generates code. This code should be presented clearly, ready for the next step.
-
AI Reviews the Code: A separate “reviewer” AI agent examines the code produced by the builder. This review focuses on correctness against the agreed-upon specification and adherence to any performance targets (like speed).
- What to do: Send the generated code and the review prompt to your AI review agent. The prompt should instruct it to verify the code against the original specification and any stated performance goals.
- What you should see: The reviewer AI provides feedback, highlighting any discrepancies with the spec, bugs, or performance issues.
-
Iterate or Finalize: If the reviewer AI finds issues, the process may loop back to step 3 with corrections, or the builder AI might be prompted to fix specific issues. Once the reviewer is satisfied, the code, along with corresponding tests and documentation, can be considered ready.
- What to do: Based on the reviewer’s feedback, either refine the builder’s prompt to fix errors or, if the code passes review, proceed to package it with tests and documentation.
- What you should see: Either corrected code that passes review, or a complete package of code, tests, and documentation that aligns with the initial specification.
Original source
This workflow is based on practices described by tomlee in their blog post “The DevOps Team That Never Sleeps” on the DEV Community platform. The author shares a battle-tested playbook for using AI agents in a DevOps context to automate code building and review.
Notes & variations
- Free-tier alternatives: While the author uses advanced AI models that are typically paid, you could experiment with free tiers of AI coding assistants. However, be aware that free tiers might have limitations on complexity, speed, or the ability to handle nuanced review tasks. For example, some free AI chat interfaces can generate code, but may not have dedicated review capabilities.
- Common pitfall: A major pitfall is not making the initial specification precise enough. If the requirements are vague, the AI builder will guess, leading to incorrect code that the reviewer might also miss if the spec itself is flawed. Always ensure edge cases and error handling are explicitly defined.
- Tip for better results: Treat code, tests, and documentation as a single, inseparable unit. Ensure that any documentation generated by AI includes runnable examples that also serve as tests. This creates a strong feedback loop where documentation errors are caught as code bugs.