HarmonyGuard: Toward Safety and Utility in Web Agents via Adaptive Policy Enhancement and Dual-Objective Optimization

Yurun Chen, Xavier Hu, Yuhan Liu, Keting Yin, Juncheng Li, Zhuosheng Zhang, Shengyu ZhangarXiv 2025 · arXiv · OpenReview

Abstract

Large language models enable agents to autonomously perform tasks in open web environments. However, as hidden threats within the web evolve, web agents face the challenge of balancing task performance with emerging risks during long-sequence operations. Although this challenge is critical, current research remains limited to single-objective optimization or single-turn scenarios, lacking the capability for collaborative optimization of both safety and utility in web environments. To address this gap, we propose HarmonyGuard, a multi-agent collaborative framework that leverages policy enhancement and objective optimization to jointly improve both utility and safety. HarmonyGuard features a multi-agent architecture characterized by two fundamental capabilities: (1) Adaptive Policy Enhancement: We introduce the Policy Agent within HarmonyGuard, which automatically extracts and maintains structured security policies from unstructured external documents, while continuously updating policies in response to evolving threats. (2) Dual-Objective Optimization: Based on the dual objectives of safety and utility, the Utility Agent integrated within HarmonyGuard performs the Markovian real-time reasoning to evaluate the objectives and utilizes metacognitive capabilities for their optimization. Extensive evaluations on multiple benchmarks show that HarmonyGuard improves policy compliance by up to 38% and task completion by up to 20% over existing baselines, while achieving over 90% policy compliance across all tasks.

Introduction

As Large Language Model (LLM)-based agents transition from simple chat interfaces to autonomous web-browsing entities, they encounter a fundamental "Safety-Utility Trade-off." Agents must be useful (Utility)—successfully executing complex tasks like booking flights or managing repositories—while remaining safe (Safety)—avoiding malicious links, protecting private data, and resisting prompt injections.

Current approaches often suffer from single-objective bias, where safety-optimized agents become overly conservative and fail tasks, or utility-optimized agents become security liabilities. Furthermore, security policies are frequently buried in unstructured text, making them difficult to retrieve or update dynamically. HarmonyGuard addresses these gaps by treating safety and utility as a joint optimization problem within a dynamic, multi-agent architecture.

The HarmonyGuard Framework

HarmonyGuard utilizes a collaborative multi-agent architecture to decouple execution, policy management, and supervision.

The HarmonyGuard multi-agent architecture, illustrating the interaction between the Policy, Utility, and Web Agents.

The framework consists of three specialized components:

  • Policy Agent: Acts as the "legal department," automatically extracting and structuring security policies from unstructured documents (PDFs, HTML). It employs an Adaptive Policy Enhancement mechanism to update the policy database in real-time when new violations are detected.
  • Utility Agent: Serves as the "supervisor," monitoring the Web Agent’s reasoning using a Second-Order Markovian Evaluation Strategy. By evaluating the transition between the previous and current state, it detects policy violations or "goal drift" without the noise of full-trajectory history.
  • Web Agent: The "worker" that executes tasks. When the Utility Agent detects a mistake, it provides Optimization Guidance—metacognitive feedback that allows the Web Agent to self-correct.

Experimental Evaluation

The framework was evaluated on three primary benchmarks: ST-WebAgentBench (235 tasks focused on Consent, Boundary, and Execution), WASP (84 tasks involving plaintext and URL injection), and WASP (SoM) (a multimodal version for vision-capable agents).

Performance comparison showing HarmonyGuard reaching the Pareto front for policy compliance and task completion.

Key results include:

  • Policy Compliance Rate (PCR): Achieved over 90% compliance across all tasks, an improvement of up to 38% over existing baselines.
  • Completion under Policy (CuP): Task success while maintaining safety increased by up to 20%.
  • Pareto Optimality: HarmonyGuard consistently reaches the "Pareto front," demonstrating the optimal balance where safety cannot be improved without compromising utility, and vice versa.
  • Multi-Round Adaptation: The system demonstrates learning capabilities; by the third round of testing, the Policy Agent's refined database stabilizes performance against repeated attacks.

Conclusion

HarmonyGuard demonstrates that safety should not be a mere "guardrail" but an integrated part of the reasoning process. By utilizing second-order Markovian reasoning and adaptive policy enhancement, the framework effectively navigates the safety-utility trade-off. Future work will explore pre-emptive input detection, token-level monitoring, and broader multimodal defense mechanisms to handle threats in visual web content.

Summary updated

Abstract

Large language models enable agents to autonomously perform tasks in open web environments. However, as hidden threats within the web evolve, web agents face the challenge of balancing task performance with emerging risks during long-sequence operations. Although this challenge is critical, current research remains limited to single-objective optimization or single-turn scenarios, lacking the capability for collaborative optimization of both safety and utility in web environments. To address this gap, we propose HarmonyGuard, a multi-agent collaborative framework that leverages policy enhancement and objective optimization to jointly improve both utility and safety. HarmonyGuard features a multi-agent architecture characterized by two fundamental capabilities: (1) Adaptive Policy Enhancement: We introduce the Policy Agent within HarmonyGuard, which automatically extracts and maintains structured security policies from unstructured external documents, while continuously updating policies in response to evolving threats. (2) Dual-Objective Optimization: Based on the dual objectives of safety and utility, the Utility Agent integrated within HarmonyGuard performs the Markovian real-time reasoning to evaluate the objectives and utilizes metacognitive capabilities for their optimization. Extensive evaluations on multiple benchmarks show that HarmonyGuard improves policy compliance by up to 38% and task completion by up to 20% over existing baselines, while achieving over 90% policy compliance across all tasks. Our project is available here: https://github.com/YurunChen/HarmonyGuard.
BibTeX
@misc{chen2025harmonyguard,
  author = {Yurun Chen and Xavier Hu and Yuhan Liu and Keting Yin and Juncheng Li and Zhuosheng Zhang and Shengyu Zhang},
  title = {{HarmonyGuard: Toward Safety and Utility in Web Agents via Adaptive Policy Enhancement and Dual-Objective Optimization}},
  year = {2025},
  eprint = {2508.04010},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.04010},
}
Figure