The Deska blog
One Agent Writes Code, Another Writes Tests
Learn how to improve software quality by having one agent writes code and another writes tests in a side-by-side multi-agent development workflow.
10 min read
The concept of dual-agent development is gaining traction as developers realize that a single AI context often suffers from confirmation bias. When one agent writes code and another writes tests, you create a natural adversarial relationship that mimics the traditional separation of concerns found in high-stakes engineering teams. This method ensures that the logic is validated by an entity that did not generate the bugs in the first place, leading to more resilient codebases and fewer regressions during refactoring.
The Problem with Single-Agent Contexts
When you ask a single AI agent to generate a function and its corresponding test suite, the agent often assumes its logic is correct. This leads to tests that validate what the code currently does rather than what the requirements specify. If the agent makes a boundary error in the implementation, it is highly likely to repeat that same boundary error in the test assertions.
By splitting these tasks, you force a synchronization point. The testing agent must read the implementation and the prompt requirements independently. If the coding agent misunderstood a requirement, the testing agent is much more likely to catch the discrepancy because it is approaching the problem from a verification perspective rather than a creative one.
Multi-Agent Workflow Architectures
There are several ways to implement a workflow where one agent writes code and another writes tests. The choice often depends on your local environment and how much visibility you need into the process.
Sequential Handoff
In a sequential handoff, the first agent completes the feature implementation and then passes the file paths to a second agent. The second agent is specifically prompted to act as a QA engineer. This method is straightforward but can be slow if the feedback loop requires multiple iterations to fix failing tests.
Parallel Execution on a Canvas
A more modern approach involves running agents side by side. In Deska, you can utilize the infinite canvas to open multiple panels. You might have one panel running Claude Code to handle the implementation while a second panel runs Codex CLI to generate the test files. This spatial layout allows you to monitor both processes simultaneously.
The Adversarial Loop
The most robust method is the adversarial loop. Here, the process follows a strict pattern:
- Agent A writes the implementation based on a specification.
- Agent B writes a comprehensive test suite.
- Agent B runs the tests and reports failures.
- Agent A adjusts the code until all tests pass.
- Agent B attempts to find edge cases that still fail.
Tooling Comparison for Multi-Agent Workflows
Different tools handle the orchestration of multiple agents with varying degrees of success. Some focus on fully autonomous swarms, while others prioritize developer oversight.
| Tool | Approach | Best For |
|---|---|---|
| AutoGPT | Fully autonomous loops | Experimental research |
| Deska | Side-by-side manual orchestration | Professional development |
| OpenDevin | Web-based sandbox | Collaborative open source |
| GitHub Copilot | Inline completions | Rapid single-file coding |
While tools like AutoGPT attempt to handle everything automatically, they often get stuck in infinite loops. Deska takes a different path by providing coding agents as modular panels. You can observe each agent in its own terminal and intervene if the logic drifts.
Practical Implementation with Deska
To set up a dual-agent environment, you start by organizing your workspace. You can open a code editor panel using the Monaco engine to view your source files. Then, you place two terminal panels side by side.
In the first terminal, you might start a session with Claude Code. In the second, you launch OpenCode. Because Deska is local-first, both agents have access to the same local file system without needing to upload your proprietary code to a third-party cloud sandbox. You can use Ask Deska to quickly open the necessary files or run build commands across the workspace using voice or chat.
Best Practices for Agent-Generated Tests
When an agent is tasked with testing someone else's code (or another agent's code), the prompts should emphasize specific testing philosophies.
- Focus on boundary conditions: Agents are excellent at identifying edge cases like empty strings, null values, or integer overflows if explicitly told to look for them.
- Requirement-first testing: Provide the original requirement document to the testing agent so it validates intent, not just implementation.
- Mocking external dependencies: Ensure the testing agent mocks API calls and database connections to keep the test suite fast and deterministic.
Managing these sessions can become complex, which is why agent threads are useful for keeping track of which agent is responsible for which part of the lifecycle. If you need to step away from your desk, the mobile app allows you to monitor the progress of long-running test suites through a secure relay that does not require exposing ports.
Frequently Asked Questions
Can two AI agents work on the same file?
It is generally better to have them work on separate files to avoid merge conflicts. One agent writes code in the source directory while the other writes tests in the test directory. If they must edit the same file, use a tool that supports real-time file synchronization and provides a clear undo history.
Which AI model is best for writing tests?
Models with high reasoning capabilities, such as Claude 3.5 Sonnet or GPT-4o, tend to excel at finding logical flaws. For the coding part, you might use a faster, more specialized model, but the testing agent should ideally be the most intelligent model available to you to ensure it catches subtle bugs.
How do I prevent agents from repeating mistakes?
Provide a "lessons learned" or a "coding guidelines" file in the context of both agents. When the testing agent finds a bug, it should explain why it occurred. You can then save these insights into notes within your workspace to inform future development cycles.
Get Started with Multi-Agent Development
Separating the concerns of implementation and verification is the most effective way to leverage AI in software engineering. By treating agents as specialized team members rather than general-purpose assistants, you increase the reliability of your output.
You can experiment with this workflow today. Deska provides the necessary infrastructure to run these agents in a unified, local environment. Download the app for Mac, Windows, or Linux at /download and start building your own multi-agent canvas.