Smart Swarms for Secure Code

Author: Denis Avetisyan


A new approach leverages collaborative agents and game theory to dramatically improve the efficiency and accuracy of identifying software vulnerabilities.

This paper presents a strategic, heterogeneous multi-agent system integrating cloud-based language models with local verification to minimize the cost of vulnerability detection.

Achieving both high accuracy and low computational cost remains a central challenge in automated code vulnerability detection. This paper, ‘Strategic Heterogeneous Multi-Agent Architecture for Cost-Effective Code Vulnerability Detection’, introduces a novel approach leveraging a game-theory-inspired, heterogeneous multi-agent system composed of cloud-based large language model experts and a local adversarial verifier. Our experiments demonstrate that this architecture achieves a 77.2\text{%} F1 score at a cost of \$0.002 per sample, significantly outperforming both single-expert LLMs and traditional static analysis. Can this game-theoretic framework guide the design of more efficient and reliable multi-agent systems for broader software engineering applications?


The Inevitable Complexity of Detection

Contemporary software development consistently yields increasingly complex codebases, presenting a substantial challenge for traditional vulnerability detection techniques. These methods, often relying on pattern matching or static analysis, struggle to differentiate between benign code structures and genuine security flaws within the intricate logic of modern applications. Consequently, a high rate of false positives-incorrectly flagged vulnerabilities-burdens security teams with the tedious task of manually verifying countless alerts. Simultaneously, critical vulnerabilities can be inadvertently missed, creating significant security risks. The sheer volume of code, coupled with the use of dynamic languages and complex frameworks, overwhelms these conventional approaches, necessitating more sophisticated and context-aware security solutions to effectively identify and mitigate threats.

Accurate vulnerability categorization is paramount for effective remediation, yet automated systems consistently struggle with this task despite the existence of standardized frameworks like the Common Weakness Enumeration (CWE). While CWE provides a consistent language for describing vulnerabilities, translating complex code behavior into these standardized categories requires nuanced understanding that current automated tools often lack. These systems frequently misclassify vulnerabilities due to ambiguities in code, contextual dependencies, and the subtle differences between similar weaknesses, leading to inefficient security efforts and potentially leaving critical flaws unaddressed. The difficulty lies not in the existence of a classification system, but in reliably and consistently applying it to the ever-evolving landscape of modern software development, necessitating continued research into more sophisticated automated analysis techniques and improved machine learning models.

The pressure to deliver software quickly often forces a compromise between comprehensive security testing and timely releases. Thorough vulnerability analysis, encompassing techniques like static and dynamic code review, penetration testing, and fuzzing, is a resource-intensive undertaking demanding skilled personnel and significant time investment. However, dedicating sufficient resources to these processes can slow down development cycles, potentially causing missed market opportunities or hindering innovation. This creates a persistent quality-cost tradeoff: organizations must balance the desire for highly secure software with the need to iterate rapidly and respond to evolving user demands. Consequently, security assessments are frequently curtailed or streamlined, increasing the risk of deploying software with undetected vulnerabilities, and necessitating ongoing monitoring and patching efforts post-release.

A Symphony of Specialized Agents

The implemented MultiAgentSystem utilizes a cooperative framework to enhance code analysis by distributing tasks among specialized agents. The CodeAnalyst agent focuses on understanding code structure and functionality, while the SecurityExpert agent specifically identifies potential vulnerabilities and security flaws. Complementing these, the DebugExpert agent concentrates on locating and diagnosing runtime errors. This division of labor allows for a more comprehensive analysis than would be achievable with a single monolithic system, as each agent can apply focused expertise to its designated area of responsibility. The agents operate in concert to provide a holistic assessment of the codebase, improving both the speed and accuracy of the analysis process.

DeepSeekV3 functions as the central control mechanism for the Multi-Agent System, responsible for task decomposition, agent assignment, and result aggregation. It leverages a large language model architecture to process code analysis requests and distribute sub-tasks to specialized agents – CodeAnalyst, SecurityExpert, and DebugExpert. Crucially, DeepSeekV3 provides the core reasoning engine for vulnerability identification, interpreting agent outputs and synthesizing a comprehensive analysis report. This orchestration includes managing communication between agents, resolving conflicts in their findings, and prioritizing potential vulnerabilities based on severity and impact. The model’s inherent reasoning capabilities enable it to not only detect vulnerabilities but also to provide contextual explanations and suggest remediation strategies.

HeterogeneousAgentAllocation within the MultiAgentSystem dynamically distributes computational resources based on each agent’s specialized function. The CodeAnalyst agent receives priority for tasks involving static code analysis and feature extraction, while the SecurityExpert agent is allocated resources for vulnerability pattern matching and exploitability assessment. DebugExpert receives targeted resources during runtime analysis and error traceback procedures. This allocation strategy avoids resource contention and ensures that each agent can efficiently perform its designated tasks, leading to improved overall system performance and more focused expertise in identifying and resolving code-related issues.

The Crucible of Adversarial Validation

To validate agent accuracy and reliability, a localized adversarial testing framework is implemented utilizing Qwen3 as a dedicated verifier. This process, termed the VerificationProcess, involves Qwen3 actively challenging the outputs generated by other agents. Specifically, agents’ responses are subjected to scrutiny by Qwen3, which assesses their validity and identifies potential errors or inconsistencies. This adversarial setup functions as a continuous feedback loop, forcing agents to refine their reasoning capabilities and minimize the occurrence of false positive results, ultimately enhancing the overall system performance and trustworthiness.

The adversarial testing framework implemented utilizes a challenge-response dynamic designed to refine agent reasoning capabilities and minimize false positive identifications. By subjecting agent outputs to verification, the system actively encourages more robust analytical processes. This iterative process directly impacts key performance indicators; specifically, it increases Precision – the proportion of correctly identified vulnerabilities among those flagged – and Recall – the proportion of actual vulnerabilities successfully detected. The combined effect of improved Precision and Recall is a more reliable and accurate vulnerability detection system, minimizing both missed threats and inaccurate alerts.

The system’s performance was evaluated on a balanced vulnerability detection dataset, resulting in a 77.2% F1 score. This metric represents a harmonic mean of precision and recall, indicating a strong balance between minimizing false positives and false negatives in vulnerability identification. The achieved F1 score demonstrates the efficacy of the adversarial testing architecture, specifically the integration of Qwen3 as a local verifier, in improving the overall accuracy and reliability of the vulnerability detection process compared to single-agent approaches.

ShapleyValue is utilized to quantify the contribution of each agent within the adversarial testing system to the overall system performance. Derived from cooperative game theory, ShapleyValue calculates the average marginal contribution of an agent across all possible coalitions of other agents. This provides a fair and accurate assessment of each agent’s individual impact on the final decision, moving beyond simple accuracy metrics. The resulting values allow for the identification of highly valuable agents and those with limited contributions, facilitating optimization of the agent ensemble and resource allocation. Specifically, a higher ShapleyValue indicates a greater influence on correctly identifying vulnerabilities or improving the precision of the system’s output.

Rigorous evaluation of the system’s vulnerability detection capabilities was conducted using the NIST Juliet Test Suite, a widely recognized standardized benchmark. This testing demonstrated the system’s ability to accurately identify vulnerabilities present within the test suite’s code examples. Importantly, the system achieved a 100% Common Weakness Enumeration (CWE) match rate, indicating that all identified vulnerabilities were correctly classified according to the CWE standard. This performance was realized through the integration of diverse expert perspectives within the adversarial testing framework, allowing for comprehensive vulnerability identification and classification.

The Inevitable Evolution of Security Ecosystems

Traditional vulnerability detection often relies on singular, exhaustive scans or limited penetration testing, proving both costly and frequently incomplete. The MultiAgentSystem introduces a paradigm shift by framing security assessment as a cooperative game between specialized AI agents. These agents, each possessing unique expertise – such as fuzzing, static analysis, or symbolic execution – collaboratively explore a system’s attack surface. This approach not only accelerates the identification of vulnerabilities but also improves accuracy by leveraging the strengths of diverse techniques. Unlike traditional methods that treat security as an adversarial battle against a monolithic system, the cooperative game fosters a more comprehensive and efficient exploration, resulting in a significant improvement in the quality and speed of vulnerability detection while optimizing resource allocation.

The system establishes a novel approach to software security by strategically integrating focused expertise with persistent adversarial testing. This combination moves beyond traditional, often exhaustive, vulnerability scans, instead prioritizing targeted assessments informed by specialized knowledge domains. Consequently, development teams realize a significant improvement in cost-efficiency, as resources are directed toward the most critical risk areas, rather than broad, potentially unproductive searches. The result is a more streamlined development cycle that doesn’t compromise on quality; rigorous testing, guided by expert insights, proactively identifies and addresses vulnerabilities earlier in the process, leading to more secure and resilient software.

The architecture driving this multi-agent security system extends beyond the realm of vulnerability detection, offering a potent framework for tackling a diverse array of complex reasoning challenges. The core tenets – fostering collaboration between specialized agents, leveraging distinct expertise, and implementing continuous verification protocols – represent a broadly applicable problem-solving strategy. This approach mirrors successful paradigms in fields like scientific discovery, where interdisciplinary teams and iterative testing are crucial, and in logistical optimization, where specialized agents manage distinct facets of a complex system. By shifting from monolithic, generalized AI to a network of focused, collaborating agents, this system provides a scalable and adaptable model for any task requiring nuanced reasoning, continuous improvement, and the integration of diverse knowledge domains – suggesting potential applications in areas ranging from medical diagnosis to financial modeling.

The future of cybersecurity increasingly relies on a synergistic partnership between artificial intelligence and human intellect. Rather than replacing security professionals, AI-powered agent systems are poised to become invaluable collaborators, proactively scanning for vulnerabilities and augmenting human expertise. These systems continuously analyze code, network traffic, and system behavior, identifying potential threats before they can be exploited. This proactive approach shifts security from a reactive posture-responding to incidents after they occur-to a preventative one, significantly reducing risk and associated costs. By handling the tedious and repetitive aspects of threat detection, these agents free up human experts to focus on complex problem-solving, strategic planning, and the nuanced judgment that AI currently lacks, ultimately creating a more robust and resilient security landscape.

The pursuit of robust vulnerability detection, as outlined in this work, acknowledges an inherent instability. The system isn’t built; it evolves through interaction-a game of adversarial verification. Robert Tarjan observed, “A good algorithm should be like a good joke: easy to understand, but hard to follow.” This holds true here; the heterogeneous multi-agent approach, while conceptually straightforward, creates a dynamic where vulnerabilities are discovered not through brute force, but through emergent behavior. The system’s cost-effectiveness isn’t guaranteed by design, but arises from the probabilistic interplay of its agents. Stability is, after all, merely an illusion that caches well, and this architecture embraces that reality.

What Lies Ahead?

This work, framed as a strategic architecture, is more accurately understood as the seeding of a complex adaptive system. The reliance on game-theoretic incentives and heterogeneous agents presumes a level of predictability in both attacker and defender behavior that history consistently denies. Monitoring is, after all, the art of fearing consciously; the system will inevitably reveal the limits of its prophecies as new failure modes emerge. The true cost-effectiveness will not be measured in initial deployment, but in the rate at which these revelations accumulate-and the system’s capacity to absorb them without catastrophic cascade.

The integration of cloud-based large language models introduces a particular fragility. These models are, at present, black boxes trained on the past, offering no guarantee of generalization to novel vulnerabilities. The local verifier acts as a crucial, if imperfect, constraint, yet its efficacy depends on a continuous adversarial dance. That is not a bug-it’s a revelation. The system’s longevity will hinge not on achieving perfect detection, but on establishing a robust feedback loop between verification, model retraining, and the inevitable emergence of unforeseen exploits.

Future efforts should focus less on optimizing for specific vulnerability classes and more on cultivating systemic resilience. True resilience begins where certainty ends. The challenge is not to build a secure system, but to grow one – a system capable of learning, adapting, and failing gracefully in the face of an unknowable future. The architecture described herein is merely a starting point – a carefully constructed garden awaiting the unpredictable forces of evolution.


Original article: https://arxiv.org/pdf/2604.21282.pdf

Contact the author: https://www.linkedin.com/in/avetisyan/

See also:

2026-04-25 23:25