Manuscript Offprint

arXiv:2608.25711

Reassembling Distributed Risk: Trajectory-Conditioned Action Generation for Multi-Turn Agent Safety

Yanbo Dai, Zhenlan Ji, Zongjie Li, Shuai Wang

Abstract

Tool-using LLM agents extend security risks beyond generated text to actions that affect external systems. Under multi-turn decomposition attacks, a harmful objective can be distributed across individually plausible requests and tool calls, becoming apparent only from the accumulated trajectory. Existing defenses either rely on auxiliary online reasoning to recover long-horizon security evidence or assess actions after generation, often incurring additional inference cost or depending on runtime-specific action representations.

We propose Reassembling Distributed Risk (ReDiR), a generation-time defense that conditions action generation on trajectory-level security evidence. Before each action, ReDiR compresses the current trajectory into a compact latent safety representation and injects it into the frozen base model. The representation is learned through same-model, cross-view supervision, where safe behavior from an explicit task view provides supervision for recovering distributed safety evidence from the original multi-turn trajectory. This design enables ReDiR to integrate cross-turn security information directly within the generation process without relying on a separate action-level safety module. We evaluate ReDiR on two agent-safety benchmarks across three model families and eight held-out tool domains. ReDiR reduces attack success rates to below 8%, transfers to unseen tool domains, and preserves benign fidelity with low computational overhead.

1 Introduction

LLM agents increasingly act rather than merely answer. By combining a language model with external tools, an agent runtime can translate model outputs into actions that modify external systems [21, 31, 49]. This coupling gives model decisions consequences beyond the conversation. Harmful text can often be filtered before it reaches a downstream system, but a dispatched action may change external state in ways that are difficult to reverse [15, 50]. Agent safety must therefore govern executable behavior, not only generated text, and constrain unsafe actions before they take effect [5, 9].

(a) Multi-Turn Attacks

(b) Reassembling Distributed Risk

Figure

Figure 1: (a) The adversary distributes a destructive command across helper functions and composes them in the final turn. (b) ReDiR re-encodes the trajectory before each action; once the harmful objective becomes apparent, the safety latents steer the model to FINISH instead of executing the command.

Multi-turn execution, which emerges as a prevailing paradigm in contemporary agent applications [40, 44, 47, 57], makes this problem substantially harder. A harmful objective can be decomposed into locally plausible requests and actions, with its harmful intent becoming apparent only over the full interaction trajectory [11, 17, 19, 43]. Evidence of risk may span prior user requests, tool observations, and the state changes they induce, making isolated-step judgments insufficient. Moreover, a safe textual response does not guarantee safe execution: a model may produce a refusal message while still emitting a policy-violating tool call [5]. Multi-turn agent safety is therefore a trajectory-level, action-grounded problem: the next action must be controlled based on evidence accumulated throughout the preceding interaction.

Consider a terminal agent that receives a destructive instruction distributed across three turns. As shown in Figure 1 (a), the requester first asks the model to create a helper function that returns "rm -rf", and then asks for another helper function that returns "/". These turns do not themselves execute the destructive operation, but together define the components of a command executed later. In the final turn, the agent is instructed to invoke both functions and pass their outputs to os.system, thereby executing the composed command rm -rf / [19]. Inspecting only the final turn shows merely the use of previously defined helper functions, without revealing the command fragments they return. Likewise, each earlier turn exposes only a partial component of the eventual command, insufficient to determine its overall effect. Evaluating the consequence of the resulting action thus requires reconstructing the command from information distributed across the interaction history. Once executed, such an action may induce state changes that are difficult or impossible to reverse [9,29]. Effective control must therefore aggregate trajectory-wide evidence before generating the next consequential action.

Limits of Post-Generation Action Checking. Existing defenses operate at several useful layers. System-level mechanisms can isolate components, constrain information flow, or enforce explicit policies [8,32,45]. Runtime guards instead inspect generated actions before dispatch and can block unsafe actions [7,14,23,46]. Complementary approaches incorporate memory or trajectory-level reasoning to recover safety-relevant evidence from earlier steps [12,42]. These mechanisms provide valuable protection, but typically separate trajectory reasoning from action generation. This separation leaves safety decisions to downstream checks on generated actions [23,25], which must interpret runtime-specific tool schemas and argument formats. Because these vary across tools and agent frameworks, transferring a defense often requires runtime-specific adaptation [19]. Generate-then-check defenses also add an online safety step after action generation [25]. These limitations motivate integrating trajectory-level safety control directly into generation, allowing accumulated evidence to shape the action before it is produced [16].

Reassembling Trajectory Evidence. Prior work suggests that harmful semantics can remain detectable in a model's hidden states even when its generated behavior is unsafe [54]. More broadly, internal representations can encode behaviorally relevant concepts and compact contextual information that can be used to guide subsequent generation [4,51,55,60]. These findings motivate consolidating risk evidence distributed across a multi-turn trajectory into a compact latent representation before the next action is generated. Conditioning generation on this representation allows accumulated risk evidence to shape the next action directly, without relying on a particular tool schema or action format.

We introduce Reassembling Distributed Risk (ReDiR), a generation-time defense that conditions action generation on trajectory-level safety evidence. Before each action, ReDiR compresses the current trajectory into a compact latent safety representation that guides the base model (Figure 1 (b)). ReDiR learns this representation through same-model, cross-view supervision: safe target behavior is elicited from the base model under a view where the task objective is explicit, and the safety encoder is trained to recover the corresponding signal from the original multi-turn trajectory. This allows distributed risk evidence to directly shape the next action. The latent representation is thus encouraged to capture cross-turn safety semantics without encoding tool-specific schemas or action formats.

We evaluate ReDiR on MT-AgentRisk [19] and AgentDojo [9] across three popular LLM, Qwen3.5-9B [37], Ministral-3-8B-Instruct [20], and Gemma-4-E4B [35] against MAGE [42] and ToolShield [19]. Using supervision from a single tool domain, ReDiR reduces attack success rate to below 8%, substantially outperforming the strongest competing defense, whose attack success rate remains around 20% to 34%. ReDiR further generalizes to eight held-out tool domains, maintaining an attack success rate below 7% while preserving benign behavior. It also maintains high benign fidelity with minimal memory overhead, while its early safe-termination mechanism improves efficiency by reducing end-to-end runtime on harmful tasks by up to 89% relative to the base agents.

We summarize our contributions as follows:

• Conceptually, we identify trajectory-conditioned representation as a useful abstraction for multi-turn agent safety, where safety-relevant evidence distributed across turns is aggregated before the next action is generated. This view connects trajectory-level safety evidence directly to action generation through the base model’s latent representation space.

• Technically, we introduce ReDiR, which learns compact trajectory-conditioned safety representations from audited same-model, cross-view action targets and injects them into a frozen base model before action generation. Its training procedure further combines selective corrective training with benign-behavior retention to improve safety while minimizing unnecessary changes to benign behavior.

• Experimentally, we evaluate ReDiR on two agent-safety benchmarks, across three model families and eight held-out tool domains. ReDiR reduces attack success rates to below 8%, transfers to unseen tool domains, and preserves benign fidelity with low computational overhead.

References (57)