Building a Multi-Agent Verification Loop in Python with Small Open Models

The Rise of Multi-Agent Architectures
In the current AI landscape, the move toward agentic workflows represents a departure from simple prompt-response paradigms. By breaking down tasks into distinct, specialized roles—a design pattern often referred to as the Proposer-Critic-Judge architecture—developers can effectively force language models to simulate the cognitive processes of review and verification. While this architectural shift promises significant gains in accuracy, particularly for mathematical, logical, and code-generation tasks, it introduces what industry experts term a "token tax." This tax manifests as a compounding increase in computational latency and resource consumption, which grows linearly with every additional node incorporated into the agent graph.
The central challenge facing modern AI engineering is determining the "break-even point" where the cumulative cost of multi-agent verification justifies the improvement in output quality. As models like Qwen2.5-7B-Instruct become more capable at smaller parameter counts, they offer a viable middle ground: the ability to execute complex, multi-step reasoning without requiring the massive VRAM footprint of frontier-scale models like GPT-4o or Claude 3.5 Sonnet.
Implementing the Proposer-Critic-Judge Protocol
To implement this architecture on constrained hardware, such as the widely used Nvidia T4 GPU found in Google Colab environments, developers must employ "persona multiplexing." This technique avoids the prohibitively high memory requirements of running three separate model instances by loading a single, highly capable baseline model into memory—typically using 4-bit quantization to reduce its footprint—and dynamically swapping its system prompts to alter its behavior.
The workflow begins with the Proposer, which is instructed to provide a direct and concise initial response to the user’s prompt. Following the initial output, the Critic role is triggered. The Critic is explicitly directed to ignore the Proposer’s work, perform an independent, step-by-step calculation, and identify any logical inconsistencies. Finally, the Judge reviews the original task, the Proposer’s initial attempt, and the Critic’s findings to formulate the final, verified response.
Technical Chronology and Workflow
The implementation requires a structured Python environment. After ensuring the necessary libraries—transformers, accelerate, bitsandbytes, and torch—are installed, the model is initialized in 4-bit precision to maintain performance within a 16GB VRAM limit.
The core of the system is a measurement utility, generate_and_measure(), which acts as an instrumentation layer. This function tracks input tokens, output tokens, and the total wall-clock time required for each generation step. By capturing these metrics, engineers can quantify the "token tax" in real-time.
- Initialization: The model is loaded with a 4-bit configuration to maximize GPU efficiency.
- Persona Injection: The system prompts for the Proposer, Critic, and Judge are defined. The Critic, in particular, is forced to use "Chain-of-Thought" reasoning, which is essential for catching the subtle errors that often plague LLMs.
- Execution: The
run_verification_loopfunction automates the hand-off between the three agents. - Analysis: The output is compared against baseline metrics, revealing the exact latency and token consumption penalty.
Data-Driven Performance Evaluation
Testing this architecture with a classic trick question—"Bob is 20 years old. Alice is half Bob’s age. When Bob is 100 years old, how old will Alice be?"—highlights the efficacy of the verification loop. In a baseline, single-agent scenario, many models succumb to the "proportionality bias," calculating that if Alice is half Bob’s age at 20, she must be half his age at 100, resulting in the incorrect answer of 50.
In the controlled test, the Proposer produced the erroneous answer of 50. However, the Critic identified the flaw by calculating the constant age difference (10 years) between the two individuals. The Judge then correctly synthesized the findings, outputting 90 as the final answer. The instrumentation revealed a 6.3x increase in latency and a 7.8x increase in total token consumption compared to the baseline. While these metrics represent a significant overhead, they successfully converted a logical failure into a verified success.
Industry Implications and Future Outlook
The broader impact of the Proposer-Critic-Judge architecture on the software development lifecycle is substantial. For applications where accuracy is non-negotiable—such as financial auditing, legal document review, or automated medical triage—the 6x to 8x latency penalty is often a secondary concern compared to the risk of a "hallucinated" or logically flawed output.
However, the cost-benefit analysis suggests that this approach should be applied surgically. For routine queries or low-stakes information retrieval, the overhead of a full verification loop is inefficient and environmentally costly. Instead, developers are increasingly adopting "Adaptive Agentic Routing." In this model, an initial lightweight agent assesses the complexity of the incoming request. If the task is deemed "simple," the agent provides the answer directly; if the task is identified as "complex" or "logical," the request is routed through the full multi-agent verification loop.
Concluding Perspectives
The integration of small, open-source models into sophisticated, multi-agent frameworks represents a democratization of AI engineering. By removing the dependency on proprietary, closed-source models for complex reasoning, developers can maintain data privacy and reduce dependency on external APIs.
The transition from single-prompt LLM usage to managed multi-agent workflows is arguably the most significant trend in modern AI development. As seen in the Proposer-Critic-Judge experiment, the ability to "force" models to verify their own work—even at the cost of increased latency—is a foundational step toward more reliable and robust AI systems. As hardware acceleration improves and quantization techniques become more refined, the "token tax" will likely diminish, potentially making multi-agent verification the standard default for enterprise-grade applications. For now, the focus remains on intelligent, efficient routing and the careful orchestration of these "cognitive roles" to maximize accuracy without unnecessarily exhausting computational resources.







