This paper proposes VulAgentRL, an agent reinforcement learning cross-procedural vulnerability detection framework that uses the code property graph (CPG) as a dual carrier: the CG serves simultaneously as a reasoning query interface and a reward verifier, solving the problems that traditional single-function vulnerability detectors cannot access cross-function context, and that result-only rewards easily lead to evidence-free prediction degradation.
Vulnerabilities in real-world scenarios often span multiple functions, yet the vast majority of current learning-based vulnerability detectors operate by classifying individual functions in isolation. The paper's statistics on real CVE samples show that 71.7% of vulnerable functions require evidence from outside the function itself to be correctly classified.
In existing related work on vulnerability detection, code property graphs (CPGs) have long been used as input to graph neural network-based detectors, but prior to this paper's publication, no public research had used the CPG simultaneously as an interaction/operation interface for LLM agents and as a reward verification carrier.
To verify whether a reward mechanism relying solely on the final verdict is sufficient to support effective training of a vulnerability detection agent, the researchers set up a controlled experiment group in which a GRPO policy was trained using only the correctness of the verdict result as the sole reward signal. They observed that under this training mode, the agent policy clearly drifted toward over-predicting that samples contain vulnerabilities: among paired test samples consisting of a vulnerable version and its corresponding patched version, 31.7% of pairs were simultaneously judged as vulnerable by this policy, compared with only 19.0% for a policy trained with the full composite reward; the policy trained with only the final verdict reward achieved a classification correctness of just 27.7% on paired samples, far below the 37.8% achieved under the composite reward scheme.
VulAgentRL's policy module no longer performs single-function vulnerability classification in isolation. Instead, through a multi-turn interaction loop, it issues typed queries against the project's CPG to obtain the necessary information—such as callers, callees, and data-flow paths—required for the final verdict.
The framework's most core differentiating design is a verifiable evidence-anchored reward mechanism. To address the flaw that using only the final verdict as reward causes the agent to degrade into evidence-free prediction, its reward scoring dimensions are no longer limited to the final vulnerability judgment result, but also cover the supporting evidence output by the agent as well as the corresponding CWE category.
Leveraging the persistent integer IDs that Joern assigns to each CPG node, the same graph used by the policy's queries can be compared via exact set matching against teacher annotations, directly verifying whether the evidence references output by the agent are accurate, making the evidence-level reward signal fully deterministic and automatically verifiable.
VulAgentRL's first stage is supervised fine-tuning for reasoning and tool use, which adopts a moderate ground-truth disclosure design: for vulnerable functions, the demonstration agent is given only the CWE category identifier as a directional hint, without vulnerability descriptions, locations, or related evidence; for safe functions, no hint is provided at all. This design avoids demonstration trajectories degenerating into post-hoc rationalization of known conclusions, while also preventing demonstration resources from being largely wasted on ineffective exploration due to full information shielding. Since the GRPO algorithm can only fine-tune an existing tool-call distribution and cannot induce reasonable tool-use behavior from a policy that never makes tool calls at all, SFT initialization is a necessary prerequisite for the subsequent reinforcement learning stage to converge properly.
VulAgentRL's reinforcement learning stage uses GRPO with a CPG-based verifier. Its reward evaluates the match between the agent-generated detection report and the demonstration ground truth at three granularities: verdict result, supporting evidence, and CWE category. All reward components are pure rule-based operations on labels or CPG node sets, with no learnable reward model. This fully rule-based reward design makes the reward signal completely deterministic and computationally cheap, and avoids the drift problem common to learned reward functions.
The loss function used in GRPO optimization is , where is the importance sampling ratio and is the clipping threshold. A core feature of this training loop is that the reward computation step directly queries the same CPG graph the agent interacted with to complete evidence-anchored verification, closing the loop between agent tool calls and reward verification. The policy tuned in this stage is the final VulAgentRL model.
Under a strict evaluation protocol, VulAgentRL outperforms all compared baseline approaches, and its performance on both core metrics—pairwise correctness and accuracy—surpasses frontier closed-source large models. Pairwise correctness is a highly constrained evaluation metric: a sample pair is judged correct only when the model simultaneously and correctly identifies both the vulnerable function and its corresponding patched version; this rule effectively filters out many over-prediction approaches that tend to label all functions as vulnerable. The approach's performance advantage persists in out-of-distribution scenarios and under class imbalance, while it makes fewer total external tool calls than the baseline version trained only with supervised fine-tuning.
The paper adopts a progressive ablation experiment design to verify the independent contribution of each technical component: starting from an untrained base model with only a tool-call interface, it successively adds the first-stage supervised fine-tuning, GRPO training using only the final verdict reward, GRPO training with the CWE category term added, and finally the evidence alignment term to obtain the complete composite reward function. With each newly added design component, the model's final performance improves accordingly, and the complete experimental results confirm that all proposed modules contribute positively to the final detection performance.
This study uses the language-agnostic code property graph (CPG) as its underlying foundation, and two natural directions for future exploration follow: one is cross-language vulnerability detection evaluation covering more programming languages, and the other is extending the existing graph-verified detection capability to vulnerability repair task scenarios.
The paper's authors have publicly released the complete implementation pipeline, the accompanying datasets, and the agent's step-by-step interaction trajectories, supporting future research on LLM agents for the security domain.