# Your KV Cache Can Spot Attacks on Your AI Agents

Ari Azarafrooz, Intrinsec AI | AI Engineer | 07:12

Source: https://www.youtube.com/watch?v=1NWnSwCB4NM
Channel: AI Engineer (https://www.youtube.com/@aiDotEngineer). Summarised by AIE Talks.
Page: https://aietalks.com/talks/your-kv-cache-can-spot-attacks-on-your-ai-agents
Published: 2026-11-09
Tags: inference, security

## TL;DR
- KV cache pages record the model's computation and can reveal attacks that input and output guardrails miss.
- A baseline of normal KV pages can expose unusual pages in voice and text agent traffic, including hidden spoken instructions.
- Production systems must handle model changes and the cost of moving large KV cache data for real-time analysis.

## Summary
Ari Azarafrooz argues that the KV cache can provide a security signal alongside existing input and output guardrails. Every input becomes a model computation before the agent generates text or calls a tool, and the KV cache records that computation. Teams can learn what normal KV pages look like, flag rare pages, then classify or explain the anomalies. In a voice-agent example, this approach detects a hidden instruction in audio even though there is no text to filter, and it identifies which page contains the unusual event. Azarafrooz also describes results from text-agent traffic, where many of the highest-ranked alerts corresponded to meaningful anomalous activity. The difficult engineering problems come later: different models produce different KV representations, and large cache chunks are expensive to move for real-time analysis. He places the integration inside inference engines or in cache-management systems such as LMCache, llm-d, and NVIDIA Dynamo.

## Key ideas
### KV cache data can extend security checks beyond inputs and outputs
[00:00](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=0s)
Ari Azarafrooz describes the KV cache as the keys and values computed for each token and kept so the model does not need to compute them again. Agent failures can include prompt injections, jailbreaks, broken or sensitive tool calls, data exposure, hidden backdoors, and drift. Existing defenses often inspect prompts, inputs, and outputs with a judge model or separate classifiers. His proposal is to use the computation already recorded in the KV cache as another security signal.

### Anomaly detection can learn normal KV pages and find unusual ones
[02:03](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=123s)
The proposed workflow starts by learning a baseline for an AI workload and its inference traffic. The system measures what a normal KV page looks like, finds pages that are rare against that baseline, and then classifies or explains the anomalies. Azarafrooz gives three reasons to use this data: it already exists in the inference stack, it can cover activity that passed other guardrails, and it can remain in place when privacy rules prevent reading the original inputs and outputs.

### The signal can plug into inference engines or cache-management layers
[02:27](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=147s)
KV caches make inference stateful across the system. LMCache can store cached pages from GPU memory to remote storage, while llm-d and NVIDIA Dynamo can route requests to workers that already hold a relevant page. Anomaly detection can run inside the inference engine for real-time alerts that influence later tool calls and policies. It can also read stored pages through a cache layer and search for pages that do not fit the rest of the workload.

### KV pages can expose hidden instructions in audio
[03:56](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=236s)
For a voice-agent example, Azarafrooz uses ordinary voice clips as a baseline and examines 16-token pages. The test compares a clean voice with another voice containing a hidden instruction. Simple anomaly detection identifies the unusual case and points to the part of the request where the event occurred. This matters because there is no text field to inspect before the audio reaches the model.

### A model trained on KV pages can attach useful explanations to anomalies
[04:41](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=281s)
Azarafrooz says his team trained a model using KV pages as features and asked it to explain or tag the detected activity. Although the model was not trained on audio, it produced information about personal information, home address, location data, travel information, and destination in the voice-agent example. The proposed security signal can therefore point beyond a binary alert toward categories that help describe the event.

### Text-agent traffic also separates normal activity from failures
[05:02](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=302s)
In a text-agent experiment, the team compared benign agent traces with several types of agent failure, including injected tool descriptions and misinformation. The presentation showed normal and attack traffic separating in the learned representation. Looking at the ten highest-ranked alerts, Azarafrooz says roughly seven or eight were meaningful anomalous activities. The team also examined whether some anomalous events stood out more strongly than others.

### Changing models make shared security representations necessary
[06:13](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=373s)
Production systems change through fine-tunes and new releases, while different agents and routers may use different specialist models. Each model writes KV pages in its own coordinate system. Maintaining a separate baseline, classifier, and explainer for every model would be computationally prohibitive, according to Azarafrooz. The alternative is to map pages from different models into one shared representation space.

### Real-time KV analysis is limited by the size of the data
[06:35](https://www.youtube.com/watch?v=1NWnSwCB4NM&t=395s)
Azarafrooz describes a second production problem: real-time analysis requires moving large cache objects. A 1,256-token chunk from the model example he gives is about 40 megabytes of KV data. Compression and streaming approaches such as CacheGen may help, but moving that data for security analysis and taking action in real time remains slow. This limits how easily the signal can be added to a live inference path.

## Notable quotes
- "The KV cache is your engine's record of that computation." (01:02)
- "Whatever it slips past those guardrails, it still becomes computation." (01:45)
- "The KV cache is your engine's record of that computation." (01:02)
- "The second, real time means moving big objects." (06:35)

## Tools & references mentioned
- Intrinsec AI
- LMCache
- llm-d
- NVIDIA Dynamo
- vLLM
- SGLang
- Hugging Face
- ATBench
- CacheGen

## Who should watch
- You run agents on your own inference stack and want a security signal that does not depend on inspecting every input and output.
- Your system handles voice or other inputs where harmful instructions may not appear as filterable text.
- You are deciding how to support multiple changing models while keeping KV-based analysis close to real time.

## Related talks

- [Context Platform Engineering to Reduce Token Anxiety](https://aietalks.com/talks/context-platform-engineering-to-reduce-token-anxiety) (Val Bercovici & Callan Fox, WEKA, 23:52)
- [I Monitored Crime Audio. Voice Agents Scare Me More.](https://aietalks.com/talks/i-monitored-crime-audio-voice-agents-scare-me-more) (Sumanyu Sharma, Hamming AI, 16:04)
- [How We Hacked YC Spring 2025 Batch's AI Agents](https://aietalks.com/talks/how-we-hacked-yc-spring-2025-batchs-ai-agents) (Rene Brandel, Casco, 17:33)
- [Turning My Obsidian Vault Into a Local AI Engineer](https://aietalks.com/talks/turning-my-obsidian-vault-into-a-local-ai-engineer) (Filip Makraduli, Superlinked, 47:26)
- [Real AI Agent Attacks and What Would Have Stopped Them](https://aietalks.com/talks/real-ai-agent-attacks-and-what-would-have-stopped-them) (Andrey Rybka, Bloomberg, 15:44)
