arXiv(opens in a new tab)cs.CRAug 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2608.24022

What Guides the Agent? Adjudicating Unauthorized Behavior via Localizing Behavior-Guiding Instructions

Yichao Gao, Yumo Zhang, Yunhao Yao, Haohua Du, Puhan Luo, Ruiqi Li, Zhiqiang Wang

Abstract

LLM agents integrated with external resources gain complex task capabilities, yet the unified natural-language context channel makes them vulnerable to injection attacks: untrusted external data may be dynamically parsed as behavior-guiding instructions during LLM inference, thereby subverting the agent's decision. Existing defenses primarily rely on static input/output-level detection or isolation of overtly malicious content, yet fall short of identifying injections that, though seemingly benign, actively subvert the model's decision-making process.

We propose AttnLocate, a runtime framework for fine-grained localization of context spans that genuinely influence tool-calling decisions, i.e., behavior-guiding instructions. AttnLocate casts this localization problem as an object detection task, aiming to detect the distinctive activation traces induced by behavior-guiding instructions within the attention matrix. Specifically, we design a multi-head, multi-layer attention aggregation scheme to construct a token-level feature space tailored for object detection. Then, a 1-D U-Net equipped with an anchor-free detection head is deployed to detect these spans. Finally, based on the authority of the provider from which the detected behavior-guiding spans originate, AttnLocate dynamically adjudicates malicious invocation attempts. We evaluate AttnLocate across ten agent configurations from five LLM families, covering scenarios involving indirect prompt injection and tool poisoning. AttnLocate achieves a mean IoU of 0.743, an average AUROC of 0.956, and a 0.934 true-positive rate at 0.067 false-positive rate. It also transfers effectively across unseen models and supports authority policy adaptation without retraining.

1 Introduction

Large language model (LLM) agents have rapidly evolved from conversational chatbots to autonomous decision-making systems that interact with external resources, e.g., tools, databases, and APIs. By integrating natural language reasoning with tool invocation capabilities, these agents achieve remarkable performance across complex tasks (Zhao, Jin, and Cheng 2023). However, the very interface that enables this flexibility, i.e., the unified natural-language context channel, also introduces a critical vulnerability: injection attacks. In such attacks, untrusted external content (e.g., tool outputs, metadata fields) is dynamically parsed by the LLM as part of its input context and may

Figure

Figure 1: Illustration of an external resource injection attack and AttnLocate's defense mechanism. AttnLocate localizes behavior-guiding spans and then adjudicates unauthorized behaviors based on its origin.

be misinterpreted as behavior-guiding instructions, thereby subverting the agent's intended decision and causing unauthorized tool execution (OWASP GenAI Security Project 2025; OWASP Foundation 2025). For example, as illustrated in Fig. 1, an attacker injects a malicious instruction into an external resource, causing the agent to disregard the user's benign request to read /tmp/hello.txt and instead invoke ReadFile on the sensitive SSH private key ~/.ssh/id_rsa.

Extensive work has been proposed to defend against such injection attacks: Static scanning reduces exposure by detecting or removing suspicious content before it enters the model's input context, structurally separating instructions from data (Chen et al. 2025; AI 2025; He et al. 2025) Architectural defenses provide system-level containment by isolating untrusted components, explicitly separating control and data flows (Debenedetti et al. 2025; Wu et al. 2025), or decoupling trusted planning from constrained execution (Li et al. 2026). Behavior-auditing methods mediate agent executions and constraining unsafe actions under explicit policies (Jing et al. 2025). While these methods can mitigate attack exposure or reject unsafe outputs, they are incapable of identifying context spans that, despite appearing benign, are nonetheless interpreted as behavior-guiding instructions.

∗^{*}Corresponding author.

Copyright © 2027, Association for the Advancement of Artificial Intelligence (www.aaai.org). All rights reserved.

and consequently distort the model's decision-making process. Recently, attribution-based methods (Wang et al. 2026b, 2025c, 2026a) have been proposed to estimate influence at fixed granularities (e.g., passages or metadata fields), but their coarse units entangle a short malicious instruction with its benign carrier. Therefore, a robust defense must go beyond detecting overtly malicious content and perform fine-grained identification of both the span that is functionally interpreted as an instruction and its originating provider.

Thus, we propose AttnLocate, a runtime monitoring framework that performs fine-grained localization of behavior-guiding instructions within the agent context and adjudicates unauthorized invocation behavior based on the origin of the behavior-guiding span (Figure 1). AttnLocate is built on a key observation: during LLM generation, tokens that genuinely influence the decision exhibit distinctive activation patterns in the attention matrix, patterns that are qualitatively different from general contextual salience or attention sinks.

Challenge. Three challenges must be addressed to achieve a robust localization and adjudication system. C1: attention does not directly indicate behavioral influence, as it is corrupted by noise and exhibits substantial variance across different heads/layers. C2: instruction spans have uncertain boundaries and variable lengths, making token classification inadequate for localization. C3: The legitimacy of an behavior depends on policy configuration and the authority of the external resource provider, thus requiring policy-adaptive adjudication mechanism.

AttnLocate Design. We first design a multi-head, multi-layer attention aggregation mechanism to extracts token-level feature vectors capturing complementary dependence patterns while suppressing head/layer variance (Addressing C1). AttnLocate then casts the behavior-guiding instruction localization as an object detection task over the attention matrix, employing a 1D U-Net backbone with an anchor-free detection head for variable-length span boundary prediction. This is further reinforced by a sink-aware regularization to mitigate the impact of attention noise (Addressing C2). Finally, an authority arbiter adjudicates unauthorized behavior based on the source provider of the localized span and a configurable authority policy, enabling policy-adaptive adjudications for different scenarios (Addressing C2).

We evaluate AttnLocate across ten agent configurations from six model families against different injection attacks: MCPTox(Wang et al. 2026c) for tool poisoning(Beurer-Kellner and Fischer 2025) and InjecAgent(Zhan et al. 2024) for indirect prompt injection(OWASP GenAI Security Project 2025). AttnLocate achieves an average mIoU of 0.743 for localizing behavior-guiding instructions and attains 0.956 AUROC and 0.934 recall for adjudicating unauthorized behavior. AttnLocate also generalizes to unseen models and supports policy adaptation without retraining.

Our main contributions are as follows:

• We formulate the detection of unauthorized agent behavior as a dynamic instruction-localization problem and demonstrate that attention patterns provide evidence for identifying the exact context spans that guide tool-call decisions.

• We propose AttnLocate, a novel framework combining attention aggregation, a 1-D U-Net with sink-aware objectness regularization, and an authority-based arbiter to jointly localize and adjudicate unauthorized instructions.

• We conduct extensive experiments on two injection scenarios, demonstrating superior localization (behavior-guiding span) and adjudication (unauthorized behavior) performance, strong cross-model generalization, and configurable authority policy adaption.

References (32)