Manuscript Offprint

arXiv:2608.24275

RePolicy: Reinforcement Learning for Safety-Policy Invocation in Agent Safeguards

Houcheng Jiang, Boxuan Zhang, Qiyong Zhong, Junfeng Fang, Xiang Wang, Xiangnan He

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Safeguarding language model agents requires assessing complete execution trajectories under context-dependent safety policies. Existing policy-aware safeguards mainly rely on prompting or supervised fine-tuning, limiting their ability to adapt to unseen trajectories and changing policy contexts. We propose RePolicy, an agent safeguard that learns safety-policy invocation through reinforcement learning. Given an agent trajectory and a dynamic policy library, RePolicy invokes the applicable policy and uses its content to produce a policy-grounded rationale and safety judgment. We construct PolicyTraj-20K to support supervised initialization, followed by GRPO with verifiable rewards and policy-context perturbation. Experiments across six agent safety benchmarks show that RePolicy achieves strong overall safety-detection performance and robust policy invocation under varying policy contexts. Our code is available at: https://github.com/jianghoucheng/RePolicy

1 INTRODUCTION

Large language model (LLM) agents are evolving from text-generating assistants into autonomous systems capable of planning tasks, invoking tools, and acting on external environments (Yao et al., 2023; Schick et al., 2023; Luo et al., 2025b; OpenAI, 2026a; Zeng et al., 2026). Accordingly, their safety risks have expanded from harmful content in isolated interactions to behavioral harms that emerge over complete execution trajectories (Wang et al., 2025; Qi et al., 2026; Kim et al., 2026; Shapira et al., 2026). Agent safeguards have therefore been developed to inspect agent behavior and prevent potential risks throughout task execution (Xiang et al., 2024; Luo et al., 2025c; Liu et al., 2026b;a). However, existing agent safeguards commonly make decisions under predefined risk taxonomies or safety policies, whereas no fixed policy set can adequately cover real-world deployments. Complex tasks span diverse tools and operational contexts; the same action may be subject to different constraints across user permissions, organizational requirements, and regulatory jurisdictions; and safety policies themselves may evolve over time (Chen et al., 2025). Consequently, recent studies have begun to treat safety policies as configurable external specifications and assess each trajectory against the policies relevant to its current context, demonstrating promising adaptability and interpretability (Xiang et al., 2024; Chen et al., 2025; Hoover et al., 2025; Li et al., 2026a). Despite their effectiveness, existing policy-aware safeguards are still built largely on prompting and supervised fine-tuning (Xiang et al., 2024; Chen et al., 2025; Hoover et al., 2025; Li et al., 2026a). Prompting can expose a model to safety policies, but does not directly optimize how the model uses them. Supervised fine-tuning can teach the model to imitate curated policy-use traces, yet the resulting capability is often bounded by the trajectory–policy distribution observed during training. Consequently, when facing unseen scenarios or new combinations of safety policies, a safeguard may struggle to determine which policies should be invoked and how their clauses should be applied.

Agentic reinforcement learning directly addresses this mismatch between supervision and deployment. By incorporating external capability use into model rollouts, it allows models to explore alternative

*Corresponding author: {xiangwang1223, xiangnanhe}@gmail.com.

Figure

Figure 1: Headline comparison on six agent safety benchmarks. We compare RePolicy-4B with representative agent safeguards using Unsafe F1 (%, ↑). The dashed line denotes the strongest external baseline on each benchmark, and the value on the right reports the performance difference between RePolicy-4B and this baseline.

reasoning and invocation trajectories and learn when and how to use these capabilities from outcome-based feedback (Jin et al., 2025; Feng et al., 2025; Zhang et al., 2026). We apply this principle to agent safeguarding: rather than treating safety policies as passive context, we regard them as callable capabilities that must be selected and applied during the safeguarding process. This perspective turns safety-policy invocation into an agentic reinforcement learning task whose behavior can be optimized directly through safeguard outcomes.

Building on this formulation, we introduce RePolicy, an agent safeguard that learns to invoke safety policies through reinforcement learning. Given an agent trajectory and a dynamic set of candidate safety policies, RePolicy identifies the applicable policies, analyzes the trajectory against their clauses, and predicts the violated clauses together with a safety label. We first initialize basic policy understanding and invocation capabilities with cold-start training. We then employ Group Relative Policy Optimization (GRPO) (Shao et al., 2024) with verifiable, rule-based rewards for output validity, safety-policy invocation, and safety prediction. To prevent the model from relying on superficial correlations, we further introduce policy-context perturbation, which augments each candidate set with irrelevant and decoy policies during training. This design requires RePolicy to distinguish policy applicability from the semantics of the current trajectory rather than assume that every provided policy is relevant.

Training RePolicy requires data that contain both diverse agent trajectories and fine-grained safety-policy supervision. However, existing resources are generally tailored to particular environments or risk types and do not jointly provide the trajectory-level judgments and clause-level safety-policy grounding required by our setting. To address this limitation, we construct PolicyTraj-20K, an agent safeguard dataset containing more than 20,000 safety-policy-annotated trajectories. The dataset systematically covers diverse tools, environments, and task scenarios and organizes its safety policies around agent operation scenes. Each trajectory is annotated with its applicable policies, relevant clauses, safety label, and decision rationale, providing unified data support for both supervised initialization and reinforcement learning.

We systematically evaluate RePolicy on six agent safety benchmarks: ATBench (Li et al., 2026b), R-Judge (Yuan et al., 2024), OpenAgentSafety (Vijayvargiya et al., 2025), ASSEBench (Luo et al., 2025a), HINTBench (Wang et al., 2026), and AgentHazard (Feng et al., 2026). We compare RePolicy against general-purpose language models and existing state-of-the-art agent safeguard methods (Liu et al., 2026b;a). As summarized in Figure 1, RePolicy achieves the strongest overall performance and ranks first on four of the six benchmarks, outperforming the strongest external baseline by up to 5.5 points. It also more accurately invokes relevant safety policies and identifies the clauses that support each safety judgment. Further ablation and robustness studies validate the contributions of reinforcement learning, policy-context perturbation, and fine-grained reward design. They also demonstrate that RePolicy can adapt to changes in safety-policy content, policy identifiers, and candidate policy sets.

References (54)