Twin Agent: Context Residual Compression for Privilege Separated Agents

Zhanhao Hu, Dennis Jacob, Xiao Huang, Zhaorun Chen, Bo Li +1 more
7/21/2026
cs.CRcs.CL

No confident code implementation found for this paper.

Abstract

Large language model (LLM) agents are vulnerable to security risks, such as prompt injection attacks from untrusted context that manipulate downstream reasoning and tool use. Existing secure-by-design approaches mitigate this risk by separating untrusted observations from privileged execution and careful control of information flow, but often degrade utility and require extensive task-specific engineering.

Show full abstract

We thus propose Twin Agent, a general privilege separation design pattern inspired by residual coding in the agent context. Twin Agent consists of two nearly symmetric agents: an Explore Agent that inspects untrusted information and a Safe Agent that executes privileged actions. The Explore Agent is conditioned on the Safe Agent's current context and communicates only compact hints to the Safe Agent about the next action to take. This design reduces the information needed to preserve task utility and thus achieves a better security--utility tradeoff, which we empirically verify by measuring how utility and attack success change as the length of hints varies. We evaluate Twin Agent on long-horizon software engineering tasks with SWE-bench Lite and on heterogeneous multi-tool interaction tasks with AgentDojo and DecodingTrust-Agent. Across both benchmarks, Twin Agent preserves high task utility while preventing prompt injection attacks, outperforming both undefended agents and privilege separation baselines.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{hu2026twin,
  title  = {Twin Agent: Context Residual Compression for Privilege Separated Agents},
  author = {Zhanhao Hu and Dennis Jacob and Xiao Huang and Zhaorun Chen and Bo Li and David Wagner},
  year   = {2026},
  eprint = {2607.19595},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2607.19595v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2607.19595.svg)](https://codeofpaper.com/paper/2607.19595)

Discussion