Add tool-call risk analyzer for agent steps #41
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.57) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #41"
general
weight: 0.35
rishabhsinha17
Summary
Adds a tool-call risk analyzer for agent steps, following up on the discussion with @pinyuchen about activation probes for agent misbehavior.
An agent step is the full prompt the agent sends to the model, including tool schemas and any tool results so far. This analyzer reads the last-token hidden state that
capture_hsalready captures and applies a logistic probe that returns P(next action follows a prompt injection). Since the score exists before the model samples any output token, a serving stack can use it to hold or reroute the step.Layout copies H-Node (#27). This repo gets only the inference side (numpy scorer, analyzer, infer config, demo). The probe, its training pipeline and all the numbers below live in latent-state-auditing/serving/vllm_hook, and the demo downloads the artifact from there on first run.
The released probe is for Qwen2.5-7B-Instruct, layer 28, a PCA-32 front end plus logistic regression folded into the plain (mean, scale, weights, bias) format. I fit it on 1,729 attacked AgentDojo v1 steps (all four suites, three attack templates) rendered with the Qwen2.5 tool-calling chat template and captured through vLLM-Hook, labelled by AgentDojo's own injection-task ground truth and security checks (358 unsafe). On held-out user tasks it scores 0.869 AUROC, and at 90% recall it flags 32.5% of attacked-but-safe steps.
Type of contribution
Files modified
mia/analyzers/tool_call_risk_analyzer.py(new)mia/utils/tool_call_risk/(new, numpy-only scorer)mia/__init__.py(registerstool_call_risk)model_configs/tool_call_risk/Qwen2.5-7B-Instruct.infer.json(new, layer 28 only)examples/demo_toolcallrisk.py(new, downloads the probe and three AgentDojo steps)docs/use_cases/tool_call_risk.md(new) and a row indocs/use_cases/README.mdtests/use_cases/test_tool_call_risk.py(new)Plugin architecture checklist
PluginRegistryin__init__.pyworker_extension_cls(for in-band artifact retrieval and concurrent request support)docs/use_cases/README.mdwith my GitHub handle. If the use case has a writeup, I placed it underdocs/use_cases/<name>.mdand linked it from the table.No new worker, it reuses
capture_hs.Testing
All GPU runs below used one RTX 4090 with vLLM 0.21.0, torch 2.11, bf16, on the pre-MIA capture path in eager mode. After merging the MIA restructure (#42) I ported the code to
MiaLLMandcapture_hs, and the CPU tests pass againstmia.artifacts. MIA backend. Re-verified on vLLM 0.29.0 (torch 2.13, transformers 5.19, RTX 4090) with MIA's default CUDA-graph capture. Offline mode scores the three demo steps 0.072 / 0.048 / 0.737 and server mode 0.075 / 0.051 / 0.719 (pass, pass, flag). Recapturing 440 training steps through MIA matches the features the probe was fit on, with median cosine 0.99966, largest score shift 0.06, 4 of 440 verdicts changed and AUROC 0.902 on both. That run also prompted three demo fixes (return_dict=Falsefor transformers 5, a 512 MiBMIA_APERTURE_GPU_BYTESdefault for 24 GB GPUs,max_model_len4096).End to end.
python examples/demo_toolcallrisk.pydownloads the artifact, serves three AgentDojo Slack steps with the disk path and the registered analyzer, and printsAll three steps come from the training distribution.
Capture parity. I rebuilt the 839 prompts behind the paper's stored HuggingFace activations (all prompt hashes match) and fed identical token ids to vLLM-Hook and to HuggingFace on the same GPU. In fp32 (Qwen2.5-1.5B) the captures agree to 0.13% relative L2. In bf16 (Qwen2.5-7B) vLLM-Hook differs from HuggingFace by 2.5%, the same as HuggingFace today vs the stored HuggingFace run, so the gap is bf16 rounding. The paper's probe gets 0.849 AUROC on vLLM-Hook features vs 0.853 on the stored ones.
Serving cost. 280 agent steps of about 4,500 prompt tokens, 64 output tokens. Plain vLLM 158.6 s eager and 158.5 s with CUDA graphs, vLLM-Hook with capture off 158.6 s, capturing layer 28 to memory 159.1 s, to disk 158.6 s. These steps are prefill-bound, so decode-heavy traffic will show a larger eager gap.
Stability. Scores move at most 0.067 between a batched capture and a one-prompt-per-call capture of the same 1,826 steps. The plain logistic probe on raw features moved up to 1.0 at early layers. The PCA front end fixes that.
Unit tests.
tests/plugin/test_tool_call_risk_scorer.pyhas 8 tests that run on CPU with a synthetic probe. They cover scoring against a reference logistic, overflow at extreme logits, hidden-size and layer mismatches, the analyzer on both the RPC (stacked) and disk (list) formats, and the threshold override.Limits. The probe predicts the action rather than detecting injection (0.53 AUROC for attacked-safe vs clean), so it belongs next to an injection filter. Layer 28 is the last block, and vLLM-Hook captures it before the final norm. HuggingFace
hidden_states[28]comes after the norm, and the probe does not apply to it.Related issue
N/A
Contribution acknowledgement
If this contribution is included in a future version of the vLLM-Hook technical report, would you like to be credited as a co-author?
If yes, please provide: