AgentSys: Secure and Dynamic LLM Agents via Explicit Hierarchical Memory ManagementAgentSys: Secure and Dynamic LLM Agents Through Explicit Hierarchical Memory Management
AGENTSYS defends against indirect prompt injection with hierarchical isolation, achieving an ASR of 0.78% on AgentDojo with GPT-4o-mini.
The adversary can influence observations returned by any tool, but cannot modify the executor or environment state transitions. The goal is to make injected instructions persist across reasoning cycles after entering working memory and change subsequent policy. Indirect prompt injection refers to a deviation in actions and/or observations of a poisoned trajectory relative to a clean trajectory. The victim system is an LLM agent with a context window as working memory that can call external tools.
- LLM agents write all tool outputs and reasoning traces into the context, so indirect prompt injections are repeatedly processed in subsequent steps, and verbose content also reduces utility. Existing defenses mostly harden on this already bloated memory, or trade isolation for rigid constraints.
- AGENTSYS separates the main agent from short-term workers that process tool outputs. The main agent declares a JSON-style intent in advance and only accepts parseable structured return values; raw output stays in an isolated context. The worker's recursive command calls are gated by a validator that does not see the raw output, and after rejection they are cleaned and retried within budget.
- On AgentDojo, AGENTSYS with GPT-4o-mini has an ASR of 0.78% (no defense 30.66%) and benign utility 64.36%. On ASB, the ASR is 4.25%. Isolation alone gives an ASR of 2.19%, and under PAIR it is 2.06%. Benign utility for four models is lower than no defense.
- The authors note that the validator may falsely allow or falsely reject, string fields can still carry adversarial content, and the schema for exploratory tasks may be too strict or too loose. The evaluation covers AgentDojo and ASB with six base models; the paper does not report the retry budget value, the PAIR attacker model name, or the number of repetitions.
- Evaluated models
- GPT-4o-miniGPT-4oGPT-5.1Claude-3.7-SonnetGemini-2.5-ProQwen-2.5-7B-Instruct
- Benchmarks
- AgentDojoASB
- Metrics
- Benign UtilityAttacked UtilityASRDefense Quality
Researchers from Washington University in St. Louis and Johns Hopkins University propose AgentSys, which defends LLM agents against indirect prompt injection using explicit hierarchical memory management, reducing attack success rate to 0.78% on AgentDojo. The main agent derives a worker agent running in an isolated context for each tool call; external data and subtask reasoning traces do not enter the main agent's memory, and only return values passing JSON validation can cross the isolation boundary. Recursive tool calls are gated by a validator, and when rejected, enter a bounded sanitize-restart recovery process. On ASB, the attack success rate is 4.25%, benign task utility is 64.36%, slightly higher than the no-defense baseline of 63.54%, and the attack success rate is 0 on tasks with at least 4 tool calls. Ablation experiments show that retaining only context isolation reduces the attack success rate to 2.19%; against manually constructed and PAIR iteratively refined adaptive attacks, the attack success rates are 1.43% and 2.06%, respectively.
Why it was selectedThe paper borrows the idea of operating system process isolation to manage agent memory, reducing the attack success rate to 0.78% on AgentDojo, and compares with ten defenses.
Paper analysis
What problem does this paper attempt to solve?
Injections in tool outputs persist in the context; AGENTSYS uses hierarchical memory isolation to shrink the attack surface.
Indirect prompt injection, once in context, persists across steps, and verbose observations also reduce utility.
- Scenario: The authors argue that agents must call tools to read external content such as emails and web pages to complete multi-step tasks; injected instructions can hijack behavior after retrieval, leading to unauthorized operations or data theft.
- Existing shortcomings: The authors claim that model-layer, detection-layer, and system-layer defenses all harden under the premise that "observations are fully written into memory." The first two layers cannot prevent irrelevant content from entering and persisting; system layers often trade isolation for predefined call stacks or rigid constraints, limiting dynamic decomposition.
- Authors' observation: Without defense, earlier injection yields higher ASR: in Table 1, for trajectory length 4, rounds 1/2/3 are 60.53%, 15.38%, 5.88%. The authors claim that in Figure 4a, baseline short-task utility is 44.46%, long-task 19.08%, a 57% drop.
- Threat model:
- Victim system: an agent executing user task q, with toolset T, and working memory as the context window.
- Capabilities: can influence observations returned by any tool, cannot modify the executor, nor change environment state transitions.
- Goal: to make instructions persist across reasoning cycles after entering memory and alter subsequent policies; the success condition is that the contaminated trajectory deviates from the clean trajectory in actions and/or observations by more than 0.
- Consequence classification: control-flow manipulation (changing paths or tool selection) and data-flow manipulation (changing tool parameters). The paper does not characterize the adversary as white-box or black-box.
- Proposed method: AGENTSYS has the main agent derive isolated workers for tool calls; external data and subtask reasoning do not directly enter the main memory, only deterministic JSON-parsed return values can propagate upward. The validator and sanitizer are additional mechanisms, triggered by events.
What related research exists?
The authors categorize existing defenses into three layers: model, detection, and system, and argue that they all default to retaining all observations.
The authors organize indirect prompt injection defenses into three layers and argue that they all operate on already accumulated working memory.
Model-layer robustness
- Structured alignment: StruQ, SecAlign, Meta SecAlign modify instruction-tuning data so that the model distinguishes user instruction slots from external data slots and follows only the former.
- Inference-time control: Spotlighting uses delimiters or encoding markers for untrusted text; Mixture-of-Encodings uses multiple character encodings for external payloads; DefensiveTokens prepends a few tokens to requests; Chen et al. use attack-as-defense to emphasize user instructions.
- Paper's critique: The authors claim such methods cannot prevent verbose outputs and stale observations from entering and persisting, and argue that stronger instruction following also increases sensitivity to prompt injection.
Detection-based guardrails
- Classification and localization: ProtectAI, PIGuard, DataSentinel, Attention Tracker use external classifiers to flag suspicious segments; other work localizes injections beyond detection to enable targeted sanitization.
- Paper's critique: The authors claim detection can be evaded, false positives remove legitimate information and reduce utility, and overhead increases with memory length.
System-layer control
- Isolation and dual models: IsolateGPT uses per-application sandboxes and containers to prevent cross-session contamination. CaMeL uses Dual-LLM: untrusted content is given to a non-privileged model that cannot execute tools, and only structured, policy-checked summaries return to the privileged planner.
- Re-execution, information flow, and planning: MELON re-runs after masking the user query; if tool calls remain similar, it treats the untrusted output as manipulating control flow. F-Secure and RTBAS use information flow control to prevent privileged actions triggered by external data. ACE, IPIGuard, DRIFT adopt plan-then-execute or dynamic validation during execution; Progent and AgentArmor perform per-call policy or step-by-step checks at runtime.
- Paper's critique: The authors claim these methods often rely on predefined call stacks, restrict dynamic tool use, or impose rigid constraints to prevent memory accumulation, thereby limiting adaptive decomposition; the overhead of full-trajectory validation increases with interaction depth.
Experimental baselines and benchmarks
- Baselines: Section 6 selects Prompt Sandwiching, Spotlighting, Instructional Prevention, Tool Filter, ProtectAI, PIGuard, IsolateGPT, CaMeL, Progent, MELON, DRIFT according to the same taxonomy.
- Benchmarks: AgentDojo and ASB, with metrics of benign utility, attacked utility, and ASR.
The authors position this work as addressing indiscriminate accumulation: only task-required information enters working memory, using isolated workers and schema validation to remove attack persistence, while preserving dynamic tool use, rather than mitigating on bloated memory or sacrificing flexibility with rigid constraints.
How does the paper address this problem?
The main agent only receives the JSON-validated return value; the raw tool output remains in the isolated worker.
AGENTSYS separates long-horizon decisions from untrusted tool outputs: the main agent keeps only high-level state, while short-lived workers process raw observations in isolated contexts.
Problem setting
- Following the loop from Section 2: the backend LLM produces a policy on the context, with actions being stop or tool calls, and trajectories appended to the context.
- Indirect prompt injection means that an observation in some round contains attacker instructions, and the contaminated trajectory deviates from the clean trajectory in actions and/or observations by more than 0.
- The design constraint is that raw tool outputs do not enter the main memory; only structured values conforming to a pre-declared interface can return upward.
The main agent commits to an interface first
- Before seeing the tool output, the main agent issues ak = call(tk, xk, Itk). The intent is a JSON-like type schema composed of nested dictionaries and lists, with leaves being primitive types such as string, number, boolean, used to fix the returnable fields and their types.
- The authors' rationale: if the interface were expanded after seeing the output, adversarial responses could widen the channel back to the main agent.
- The tool still executes normally. The raw output is not appended as-is. After the worker returns rk, the main agent only performs syntactic gating: it must be a JSON-parseable object, otherwise the subtask explicitly fails.
- If it passes, rk is written into the main memory as the observation for that round. The authors claim string fields may still contain attacker-controlled content, but the channel is narrower than the entire raw output.
Isolated worker
- The worker does not inherit the main agent's long-term memory, nor does it receive the user query. Its inputs are the current tool output, the intent for that call, and the compact tool call trajectory Stack.
- It generates a return value according to the intent. If extraction or parsing fails, it returns an error object from a predefined failure type. The paper does not list the names of these types.
- The worker can call tools again and derive nested workers. Recursive calls are constrained by the validator; rejected outputs can be sanitized and retried within the subtask.
- The authors claim that non-essential content therefore does not accumulate in the main memory, and adversarial instructions in observations cannot persist across subsequent reasoning cycles.
The validator only sees trusted inputs
- The validator only applies to tool calls initiated within subtasks, not to the main agent's top-level calls. The decision is V(q, Stack, (t′, x′, It′)) ∈ {allow, deny}.
- Inputs are limited to the initial user query, the compact call trajectory, and the proposed call. The Stack contains only tool identifiers, parameters, and declared intents, not raw tool outputs. The authors claim this prevents the validator from being influenced by attacker-controlled observations.
- It triggers only on command tools, e.g., write, send, purchase, file modification. Tools are labeled as command or query by the LLM based on descriptions and usage signatures, defaulting to command when ambiguous. Classification is computed once per toolset. The authors claim overhead grows mainly with the number of command operations, not interaction length.
- If allow, the sub-call continues, and the raw output remains within the subtask. If deny, it is blocked and enters sanitization and restart.
Bounded sanitize-restart
- After rejection, the sanitizer processes only the raw tool output: it removes imperative segments and retains task-relevant data, without receiving the user query or intent, then re-extracts under the same intent.
- Each sanitize–restart consumes the subtask budget Bk for that tool output. When exhausted, it returns a predefined error object to the parent agent. The paper does not give the value of Bk.
- The authors claim this loop only occurs when a subtask is about to execute a command that may have side effects; read-only subtasks do not go through this recovery path.
What experiments did the paper conduct?
On AgentDojo, AGENTSYS with GPT-4o-mini has an ASR of 0.78% and benign utility of 64.36%.
Experimental setup
- Benchmarks: AgentDojo includes Banking, Slack, Travel, Workspace, with 97 user tasks and 629 injection tasks; ASB includes 10 evaluation scenarios. The paper does not give the number of tasks in ASB.
- Models: GPT-4o-mini, GPT-4o, GPT-5.1, Claude-3.7-Sonnet, Gemini-2.5-Pro, Qwen-2.5-7B-Instruct. Table 2 and Figure 2 use GPT-4o-mini; six-model results are only on AgentDojo (Tables 5–7). In the text, the model name is written as Qwen2.5-7B-Instruct in the tables.
- Baselines: Model-layer: Prompt Sandwiching, Spotlighting, Instructional Prevention, Tool Filter; detection-layer: ProtectAI, PIGuard; system-layer: IsolateGPT, CaMeL, Progent, MELON, DRIFT. Instructional Prevention appears in the ASB comparison but is not listed in Table 2.
- Attacks: Defaults are AgentDojo's important_instruction and ASB's OPI. Adaptive attacks are in Section 6.4.
- Metrics: Benign Utility, Attacked Utility, ASR. Section 6.3 defines Defense Quality as benign utility times Security divided by 100, where Security = 100 − ASR, and measures overhead with total tokens. The paper does not mention a judge model, thresholds, or human agreement.
- Unspecified items: The paper does not report the number of repetitions, nor does it specify which model is used for the validator, sanitizer, and command/query labeling.
Main results
According to Table 2, AgentDojo, GPT-4o-mini, units in %.
Swipe horizontally to read the table
Method Benign Utility Attacked Utility ASR No Defense 63.54 48.27 30.66 Spotlighting 59.85 45.42 35.22 PIGuard 43.33 16.38 0.85 isolateGPT 6.25 6.39 0.00 CaMeL 29.97 33.39 0.00 Progent 63.42 47.04 7.17 DRIFT 58.48 47.91 1.29 AGENTSYS 64.36 52.87 0.78 - The authors state that the two system-layer methods with 0.00% ASR in the table trade rigid execution paths for security, with benign utility dropping by more than half relative to no defense. The unlisted Prompt Sandwiching, Tool Filter, ProtectAI, MELON have ASRs of 14.69%, 8.34%, 6.84%, and 0.89%, respectively.
- In the table, Spotlighting's ASR is higher than No Defense. The authors claim that in this setting, explicit memory management makes benign utility slightly higher than the no-defense baseline.
- ASB, GPT-4o-mini (Figure 2, Section 6.1): The authors claim AGENTSYS has an ASR of 4.25%; Spotlighting has slightly higher benign utility, with a very small ASR reduction relative to no defense. The remaining unlabeled bar values in the figure cannot be reliably mapped to methods from plain text, so they are not transcribed.
Across base models
According to the Overall columns of Table 5 and Table 7, AgentDojo, units in %.
Swipe horizontally to read the table
Model No Defense Benign AGENTSYS Benign No Defense ASR AGENTSYS ASR GPT-4o-mini 63.54 64.36 30.66 0.78 GPT-4o 70.86 76.68 51.68 2.54 GPT-5.1 84.75 74.87 3.79 0.28 Claude-3.7-Sonnet 86.31 84.12 7.84 1.15 Gemini-2.5-Pro 74.49 72.68 36.90 4.08 Qwen2.5-7B-Instruct 38.15 26.40 14.11 3.45 - In all six rows, AGENTSYS's ASR is lower than the corresponding No Defense. The lowest Overall is GPT-5.1, the highest is Gemini-2.5-Pro.
- Benign utility is higher than No Defense only in the first two rows. The authors claim robustness across six base models; in Table 5, the last four rows are lower than No Defense, and the table is authoritative here.
- Table 6's Overall attacked utility: higher than no defense are GPT-4o-mini (52.87% vs. 48.27%), GPT-4o (58.22% vs. 55.43%), Gemini-2.5-Pro (63.95% vs. 60.56%); lower are GPT-5.1 (66.03% vs. 70.79%), Claude-3.7-Sonnet (75.85% vs. 76.21%), Qwen2.5-7B-Instruct (19.39% vs. 26.86%).
Component ablation
- On AgentDojo with GPT-4o-mini, components are removed one by one (Table 3).
- Removing context isolation: benign utility 62.49%, ASR 8.62%. Keeping only hierarchical memory management: benign utility 56.10%, attacked utility 52.61%, ASR 2.19%. The authors claim isolation alone already shrinks the attack surface.
- Removing the validator and always sanitizing: benign utility 50.85%, attacked utility 53.16%, ASR 0.18%. Removing the sanitizer: benign utility 57.66%, ASR 1.54%. The authors claim indiscriminate sanitization removes task-relevant information; sanitize–retry is used to recover from contaminated outputs.
Adaptive attacks and trajectory length
- Adaptive: The adversary knows the defense. Manual attacks target the schema return channel, and PAIR is used for iterative rewriting (Table 4, AgentDojo, GPT-4o-mini). Overall ASR is Base 0.78%, Adapt 1.43%, PAIR 2.06%; overall attacked utility is 52.87%, 54.53%, 53.44%. Banking's PAIR ASR is 6.94%, Travel is 0.00%. The authors claim a reduction of over 93% relative to no defense's 30.66%, with the channel limited but not eliminated.
- Trajectory utility: Short tasks are up to 3 tool calls, long tasks are more than 3, with values weighted by task proportion (Section 6.5, Figure 4a). For short tasks, AGENTSYS is 39.78%, lower than the baseline's 44.46%; for long tasks, 24.58%, higher than the baseline's 19.08%. The authors claim from short to long, AGENTSYS drops 38.21%, DRIFT drops 60.96%, Progent drops 52.98%.
- Trajectory security: Weighted ASR is 0–0.42% across length buckets, and 0% for at least 4 tool calls (Section 6.5). Baseline weighted ASR is 9.22% at length 2, Progent is 1.87% at length 3. The introduction states ASR is 0% for "more than 4 tool calls," which differs from the "at least 4" phrasing in Section 6.5 and the conclusion.
Other ablations and analyses
- Defense Quality and total tokens (Section 6.3, AgentDojo, GPT-4o-mini): AGENTSYS 63.86 (3.25M), No Defense 44.06 (0.82M), Progent 58.87 (2.60M), DRIFT 57.73 (2.37M), CaMeL 29.97 (6.09M).
- The authors report Security: AGENTSYS 99.22%, ProtectAI 93.16%, Spotlighting 64.78%. The paper reports total tokens, not broken down by trajectory length or command count.
- Table 4: Slack's PAIR attacked utility 57.14%, ASR 0.95%; Workspace's Adapt ASR 0.18%; Travel's ASR is 0.00% for all three settings.
- Table 6: GPT-4o's Workspace attacked utility: No Defense 24.17%, AGENTSYS 55.54%.
- Table 7: GPT-4o's no-defense Slack ASR is 92.38%; AGENTSYS's Slack ASR is 9.52% for Gemini-2.5-Pro and 10.48% for Qwen2.5-7B-Instruct.
- Table 1 (no defense): for trajectory length 3, rounds 1/2/3 ASR are 40.26%, 35.00%, 0.00%; for trajectory length 2, rounds 1/2 are 15.87%, 0.00%.
What are some points that can be further explored?
The authors note that the validator can misjudge, and string fields may still bring in adversarial content.
Limitations and future directions noted by the authors
- Validator reliability: Section 7 states that although the validator only sees the user query and the compact call trajectory, it may still approve malicious calls that subtly misalign with user intent, or reject legitimate calls due to being overly conservative. The authors cite an ablation: removing the validator and sanitizer yields an ASR of 2.19%, while the full system has a residual ASR of 0.78%, which they attribute to occasional validation failures. Future directions include specialized training, ensemble methods, or mixing with rule-based checks.
- Return channel: Section 7 states that the main residual channel is the schema-validated return value; string fields can still carry adversarial content. The authors claim the adaptive attacks in Section 6.4 had limited success but did not eliminate this channel.
- Intent specification: Section 7 states that for exploratory tasks where the required structure is unknown in advance, precise schemas may be hard to write; too strict limits information flow, too loose expands the attack surface. Future direction is automatic schema synthesis to balance expressiveness and security.
The limitations discussion is concentrated in Section 7; the conclusion does not list separate items.
Experimental coverage
- Utility and ASR experiments use AgentDojo (four scenarios, 97 user tasks, 629 injection tasks) and ASB (10 evaluation scenarios). Table 2 and the ASB main results use GPT-4o-mini.
- On AgentDojo, benign utility, attacked utility, and ASR are reported for six base models (Tables 5–7). Comparison methods are the model-layer, detection-layer, and system-layer defenses listed in Section 6.
- Default attacks are AgentDojo's important_instruction and ASB's OPI. Additional experiments include component ablations (Table 3), manual adaptive and PAIR attacks (Table 4), utility and ASR stratified by trajectory length (Section 6.5), and total token overhead (Section 6.3).
- The paper does not report the retry budget Bk value, does not specify the models used for the validator, sanitizer, and tool classification, and does not report the PAIR attacker LLM name, number of repetitions, or significance tests.
- The paper does not report the reviewer model name, decision thresholds, or agreement between review and human. Success is measured by utility and ASR on the two benchmarks.
Summarize the main content of the paper
AGENTSYS achieves an ASR of 0.78% on AgentDojo with GPT-4o-mini; the authors claim memory isolation is the primary mechanism.
AGENTSYS is a system-level defense against indirect prompt injection, replacing "all tool outputs are written into the context" with hierarchical memory management.
- Problem: Injected instructions enter working memory with tool observations and are repeatedly processed in subsequent turns; irrelevant content also lowers utility on long trajectories. The adversary can influence tool observations but cannot modify the actuator or environment transitions.
- Method: The main agent declares its intent before seeing the output and only accepts JSON-parseable return values. Workers extract in isolated contexts, do not inherit the main memory, and do not receive user queries. Imperative recursive calls in subtasks are allowed or denied by a validator that does not see the original output; after denial, cleaning and retrying occur within a limited budget. The main agent's top-level calls do not go through this validator.
- Main results: On AgentDojo with GPT-4o-mini, ASR is 0.78% and benign utility is 64.36%, versus 30.66% and 63.54% without defense (Table 2). On ASB with the same model, ASR is 4.25%. With only context isolation, ASR is 2.19% (Table 3). Under PAIR, overall ASR is 2.06% (Table 4). Section 6.5 states that when trajectory length is at least 4 tool calls, ASR is 0%.
- Exceptions: In Table 5, GPT-5.1, Claude-3.7-Sonnet, Gemini-2.5-Pro, and Qwen-2.5-7B-Instruct have lower benign utility than without defense. In Table 7, AGENTSYS's Overall ASR ranges from 0.28% for GPT-5.1 to 4.08% for Gemini-2.5-Pro. IsolateGPT and CaMeL have ASR of 0.00% and benign utility of 6.25% and 29.97%.
- Authors' conclusion: The authors argue that the indiscriminate accumulation of memory should be addressed, rather than applying robustness, detection, or rigid constraints on the bloated context. The conclusion states that state-of-the-art safety is achieved on AgentDojo and ASB, and that overhead grows with command operations rather than context length. Section 7 attributes residual risk to validator misjudgments and adversarial content in string fields.
Related papers
- Post-Training Large Language Models with LLMONDefensesarXiv