{"id":9129,"date":"2026-11-27T21:15:38","date_gmt":"2026-11-27T21:15:38","guid":{"rendered":"https:\/\/lockitsoft.com\/?p=9129"},"modified":"2026-11-27T21:15:38","modified_gmt":"2026-11-27T21:15:38","slug":"building-a-multi-agent-verification-loop-in-python-with-small-open-models","status":"publish","type":"post","link":"https:\/\/lockitsoft.com\/?p=9129","title":{"rendered":"Building a Multi-Agent Verification Loop in Python with Small Open Models"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/lockitsoft.com\/?p=9129\/#The_Rise_of_Multi-Agent_Architectures\" >The Rise of Multi-Agent Architectures<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/lockitsoft.com\/?p=9129\/#The_Technical_Constraint_Memory_and_Latency\" >The Technical Constraint: Memory and Latency<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/lockitsoft.com\/?p=9129\/#Implementation_Chronology_and_Methodology\" >Implementation Chronology and Methodology<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lockitsoft.com\/?p=9129\/#Evidence_of_Efficacy_A_Case_Study\" >Evidence of Efficacy: A Case Study<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/lockitsoft.com\/?p=9129\/#Industry_Implications_and_Future_Outlook\" >Industry Implications and Future Outlook<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/lockitsoft.com\/?p=9129\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"The_Rise_of_Multi-Agent_Architectures\"><\/span>The Rise of Multi-Agent Architectures<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In recent years, frameworks like AutoGen and LangGraph have surged in popularity, promising to revolutionize how software handles complex reasoning tasks. By allowing multiple autonomous agents to interact, developers can simulate a collaborative environment where one agent proposes a solution, another critiques it, and a final arbiter ensures the output meets quality standards. This architecture, often termed the Proposer-Critic-Judge (PCJ) pattern, is inspired by human peer-review processes.<\/p>\n<p>However, the industry has reached a point of diminishing returns. When developers deploy three distinct, large-scale LLMs to fulfill these roles, the memory requirements often exceed the capacity of consumer-grade hardware or standard cloud instances like the Nvidia T4 GPUs commonly available on platforms such as Google Colab. The challenge for modern engineers, therefore, is not merely architectural, but tactical: how can we implement these sophisticated loops while maintaining efficiency?<\/p>\n<h3><span class=\"ez-toc-section\" id=\"The_Technical_Constraint_Memory_and_Latency\"><\/span>The Technical Constraint: Memory and Latency<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The fundamental barrier to widespread multi-agent adoption is the &quot;token tax.&quot; Every additional node in a graph-based agent workflow necessitates new prompt processing, generation time, and API costs. When each agent is treated as a separate instance, the latency compounds, often leading to a degradation in user experience that outweighs the improvements in model accuracy.<\/p>\n<p>To solve this, a technique known as &quot;persona multiplexing&quot; has emerged. Rather than loading three independent, resource-heavy models, developers can utilize a single, high-performance open-source model\u2014such as the Qwen2.5-7B-Instruct\u2014and dynamically swap system prompts to shift the model\u2019s behavioral persona. By employing 4-bit quantization, the model\u2019s footprint is reduced to fit within the 16GB of VRAM available on standard GPU instances, allowing a single LLM to play the role of Proposer, Critic, and Judge sequentially.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Implementation_Chronology_and_Methodology\"><\/span>Implementation Chronology and Methodology<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The implementation of a PCJ loop requires a rigorous, step-by-step orchestration. The initial phase involves the selection of a capable foundation model. Qwen2.5-7B-Instruct has become a preferred choice due to its high reasoning capability relative to its parameter count. The process begins with the installation of essential libraries, specifically <code>transformers<\/code>, <code>accelerate<\/code>, and <code>bitsandbytes<\/code>, which facilitate the loading and quantization of the model.<\/p>\n<p>Once the environment is configured, the instrumentation of a measurement utility is required. A <code>generate_and_measure<\/code> function serves as the backbone of the system, capturing raw input\/output token counts and precise latency metrics. This data is vital for developers to quantify the &quot;token tax&quot; against the actual quality of the output. <\/p>\n<p>The three roles are then defined through distinct system prompts:<\/p>\n<ol>\n<li><strong>The Proposer:<\/strong> Tasked with providing an immediate, concise solution to the user&#8217;s prompt.<\/li>\n<li><strong>The Critic:<\/strong> Required to ignore the Proposer\u2019s answer initially, perform independent calculations, compare the results, and identify specific logical fallacies.<\/li>\n<li><strong>The Judge:<\/strong> Responsible for the final synthesis, either confirming the proposal or enforcing the corrections derived by the Critic.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Evidence_of_Efficacy_A_Case_Study\"><\/span>Evidence of Efficacy: A Case Study<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To test this framework, researchers utilized a classic logical trap: &quot;Bob is 20 years old. Alice is half Bob&#8217;s age. When Bob is 100 years old, how old will Alice be?&quot;<\/p>\n<p>When processed by a baseline single-agent model, the system often defaults to a superficial, proportion-based calculation (100 \/ 2 = 50), failing to account for the static nature of age differences. In a multi-agent loop, the Critic acts as a circuit breaker. By forcing the Critic to calculate the age gap (20 &#8211; 10 = 10) and then apply that constant to Bob&#8217;s future age (100 &#8211; 10 = 90), the system exposes the Proposer&#8217;s initial error.<\/p>\n<p>The data gathered from this test provides a stark insight into the cost-benefit analysis of multi-agent loops. The baseline, single-agent execution took 2.63 seconds and utilized 85 tokens. The full PCJ loop took 16.67 seconds and consumed 660 tokens. This represents a 6.3x increase in latency and a 7.8x increase in the &quot;token tax.&quot; While the raw metrics suggest a significant overhead, the qualitative outcome\u2014shifting from a logical fallacy to a factually correct answer\u2014demonstrates that the investment of time and tokens is a necessary cost for reliability.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Industry_Implications_and_Future_Outlook\"><\/span>Industry Implications and Future Outlook<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The broader implications for software engineering are clear: multi-agent loops should not be treated as a universal solution but as a tool for high-stakes reasoning. In tasks where accuracy is paramount, such as financial analysis, medical coding, or complex legal summarization, the &quot;token tax&quot; is an acceptable investment for the robustness it provides. Conversely, for routine, low-stakes queries, the overhead is prohibitive.<\/p>\n<p>Industry observers note that as models become more efficient, the overhead of these loops will likely decrease. We are seeing a move toward &quot;smaller, smarter&quot; models that are pre-optimized for specific roles, potentially eliminating the need for complex prompt-swapping multiplexing. Furthermore, hardware acceleration improvements, such as enhanced quantization techniques and faster inference engines, are expected to bring the latency costs of multi-agent loops down from seconds to milliseconds.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The Proposer-Critic-Judge verification loop represents a significant step forward in the quest for self-correcting AI systems. By leveraging persona multiplexing on small, open-source models, developers can now implement robust, high-accuracy workflows on hardware that was previously considered insufficient for multi-agent tasks. While the computational overhead remains a tangible factor, the ability to turn a failure into a verified success is a trade-off that will undoubtedly drive the next wave of AI development. As the ecosystem matures, the focus will shift from simply wiring agents together to optimizing the cost of their collaboration, ensuring that the promise of multi-agent intelligence is realized with both precision and efficiency.<\/p>\n<!-- RatingBintangAjaib -->","protected":false},"excerpt":{"rendered":"<p>The Rise of Multi-Agent Architectures In recent years, frameworks like AutoGen and LangGraph have surged in popularity, promising to revolutionize how software handles complex reasoning tasks. By allowing multiple autonomous agents to interact, developers can simulate a collaborative environment where one agent proposes a solution, another critiques it, and a final arbiter ensures the output &hellip;<\/p>\n","protected":false},"author":14,"featured_media":9128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[159,23,567,25,773,24,20,735,243,688,1331,1717],"class_list":["post-9129","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","tag-agent","tag-ai","tag-building","tag-data-science","tag-loop","tag-machine-learning","tag-models","tag-multi","tag-open","tag-python","tag-small","tag-verification"],"_links":{"self":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/posts\/9129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9129"}],"version-history":[{"count":0,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/posts\/9129\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/media\/9128"}],"wp:attachment":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}