LatentTriad: Pre-Action Risk Representations for Malicious Agent Skill DetectionLatentTriad: Pre-Action Risk Representations for Malicious Agent Skill Detection
The authors propose LatentTriad, which uses hidden states from a single prefill to detect malicious agent skills before generation and execution, achieving pooled F1 of 99.0–99.2% on five Large-ID sources across seven backbones.
The attacker controls the skill package and seeks operations beyond the trusted task (e.g., credential exfiltration, unauthorized file modification), and may distribute or obfuscate content across files, but cannot alter the trusted prompt, model weights, runtime hooks, or detector labels. The defender controls prompt assembly and action permissions, has white-box access to hidden states, and screens loaded inputs before generation or tool calls.
- Untrusted skills loaded by LLM agents may induce operations beyond the user's task, while the risk depends on task context and may be distributed across multiple files; static rules struggle to capture behavioral intent, and dynamic sandbox analysis is costly.
- LatentTriad performs one prefill on the task and skill before generation and execution, extracts three types of hidden states—Declaration, Operation and Boundary—scores them through three branches respectively: context readout, group-adjusted risk direction and benign geometric residual, and then fuses them with a fixed max–min strategy for the decision.
- On 5,830 skill packages and seven backbones, pooled F1 99.0–99.2% and source-macro F1 93.0–94.6%; under leave-one-source-out it drops to 73.2%; CompoSkill compositional attacks are detected at 93.0–97.2%; under white-box rewriting, Llama equal-source ASR is at most 11.0%, but benign FPR rises.
- The authors note: the detector requires white-box access and a fixed input contract, can only inspect loaded context, and behaviors triggered by downloads or the environment require runtime checks; the compact configuration's latency does not represent the full pipeline; under the synthetic stress test of symbol permutation, performance is close to random.
- Evaluated models
- Llama-3.1-8B-InstructQwen2.5-7B-InstructMistral-7B-Instruct-v0.3InternLM2.5-7BQwen2.5-14BPhi-3-medium-14BQwen3-30B-A3BLlama-3.3-70B-INT8
- Benchmarks
- Large-ID(MalSkillBench、SkillFortify、SkillsBench-1650、Agent-skill malware、ATR Skill Benchmark)CompoSkillSCR-BenchBalanced 2×2任务-操作兼容性受控数据集
- Metrics
- F1FPRFNRAUROCAPsource-macro F1ASRTPR retentionPairAcc
The researchers propose LatentTriad, which uses hidden states formed by large language models during the prefill stage to detect malicious agent skills before skill execution. The method combines contextual Boundary features, group-adjusted Operation directions, and deviations in relation to benign states; the detection process generates no output tokens, calls no tools, and executes no skill code. On 5,830 skill packages from five sources and seven backbone models, pooled F1 is 99.0%–99.2% and source macro-average F1 is 93.0%–94.6%. A separately tested compact implementation completes prefill and detection in a median time of 259–284 ms.
Paper analysis
What problem does this paper attempt to solve?
Detect malicious agent skills inconsistent with the task before generation or execution, using hidden states from a single prefill.
Core question: can skill-induced operations beyond the trusted task be detected after the model has interpreted the skill but before it generates or executes an action?
- Setting and importance: LLM agents increasingly load reusable skills (packages of instructions, scripts, and configuration); the authors state that SkillsMP has indexed more than 3.18 million public SKILL.md files, and loading untrusted skills can steer agents toward operations that violate the user's trusted task.
- Shortcomings of existing methods (per the paper): skill risk is context-dependent and may be distributed across multiple components; instructions, scripts, and configuration that are benign in isolation may jointly induce unauthorized operations; static rules based on keywords or code patterns struggle to capture behavioral intent; dynamic analysis requires generation, sandbox execution, and runtime monitoring, making large-scale screening costly.
- Core observation: the authors find that hidden states formed during prefill already contain readable information about task-operation consistency, and that in controlled evaluations this transfers to unseen expression forms; matched interventions on Operation states affect subsequent Boundary states and the fixed risk readout.
- Proposed: LatentTriad, a pre-action detector that reads risk from a single prefill via three branches—Boundary, Operation, and Geometry—without generating tokens, calling tools, or executing skill code.
- Threat model:
- Attacker goal: seek operations beyond the trusted task by controlling the skill package, including credential exfiltration or unauthorized file modification.
- Attacker capability: can distribute or obfuscate content across files; cannot alter the trusted prompt, model weights, runtime hooks, or detector labels.
- Defender: controls prompt assembly and action permissions, has white-box access to hidden states, and screens loaded inputs before generation or tool use.
- Victim system: the LLM agent loading the skill; the decision is enforced at runtime, and the authors cite Cartagena & Teixeira (2026) in noting that textual refusal does not guarantee tool-call safety.
What related research exists?
Related work is divided into three groups: agent security, skill security detection, and internal representations; baselines are AgentLens, RouteGuard and five input-level methods.
Agent safety and internal representations
- CaMeL (Debenedetti et al., 2025) — separates control flow from data flow and enforces tool-use policies; Attention Tracker (Hung et al., 2024) — detects prompt injection via attention patterns.
- AgentLens (Luo et al., 2026) — monitors and intervenes on hidden representations during execution; Refusal (Arditi et al., 2024) and Circuit Breakers (Zou et al., 2024) — link internal representations to safety-related behavior.
Skill safety detectors (summarized in Table 1)
- SkillSieve (Hou & Yang, 2026) — a layered triage framework combining rules, code structure checks, and LLM-based content analysis.
- RouteGuard (Xiao et al., 2026) — performs repeated fixed continuations on SKILL.md and aggregates response-conditioned signals, without covering auxiliary files.
- SkillDetonate (Ji et al., 2026) — checks behavior in a sandbox against a configured security policy; other content-checking tools such as Cisco Skill Scanner, SkillFortify, and SkillScan Security are also listed in the comparison table.
Composition and adaptive attacks (for robustness evaluation)
- CompoSkill (Liu et al., 2026b) — compositional skill-chain attacks composed of individual skills that each pass the scanner; SCR-Bench (Xie et al., 2026) — paired mechanism test cases measuring compositional risk in the skill ecosystem.
- ColluSkill (Zeng et al., 2026) — adversarial cross-skill composition to evade scanners; this paper adapts its scanner-feedback rewriting procedure for adaptive testing.
Baselines and benchmarks: representation-level baselines are AgentLens (official probe protocol) and RouteGuard (reproduced per the paper's specification); input-level baselines are Regex, SkillSieve L1, Cisco AI Skill Scanner, LLM-as-judge (Mistral-7B), and a supervised Qwen text readout. The main benchmark is Large-ID constructed by the authors (containing five sources including MalSkillBench, 5,830 packages), plus CompoSkill and SCR-Bench.
The authors position this paper as combining task-aware evaluation with multi-file inspection: the trusted task establishes authorization, instructions, scripts, and configuration jointly indicate the requested operation, and the detector inspects the assembled complete package in that context.
How does the paper address this problem?
A single prefill extracts three states D/O/B; the three branches respectively read context, operation risk directions, and geometric residuals, fused by a fixed policy.
Overall approach: convert the pre-action risk information found in Section 3 into a package-level risk score. The three branches of LatentTriad share the same single prefill of the frozen model, and scores are fused by a fixed policy before generation or execution.
State definition and extraction
- For input x, mean-pool the Declaration region (root file front matter, title, and first prose paragraph) to obtain D, mean-pool the Operation region (the rest of the root file plus readable auxiliary files) to obtain O, and sample at the last prompt token position to obtain B: hDℓ = meant∈ D(x) hℓ,t, likewise hOℓ, and hBℓ = hℓ,T (Equation 1). The mask depends only on document structure and is independent of labels.
- The input serializes the trusted prompt, task, tool schema, and multi-file skill package in a deterministic path lexicographic order; a single prefill extracts states at eight fixed normalized depths and retains the local spans of D/O. Large-ID retains at most 8 Declaration atoms and 256 Operation atoms, with an input limit of 24,576 tokens.
Three complementary branches
- Boundary: the depth is selected on non-test data, the raw B state is read directly, contextual evidence is retained, and no cross-region residual is constructed.
- Operation: the training families are divided into five manual strata (distinct from source ecosystems); within each stratum, local risk contrast directions are defined by the class means of the normalized O states, and the fitted inter-stratum directions are projected out to remove domain/family style confounding; the projected values are pooled across eight depths into standardized features (60 dimensions per member, 180 dimensions for three members).
- Geometry: a shared 32-dimensional coordinate and affine ridge mapping are fitted on benign packages to predict the expected states for D→O and O→B, and the observed-minus-predicted residuals rDOℓ = zO,DOℓ − TDOℓ(zD,DOℓ) and likewise rOBℓ (Equation 2) measure structural deviation from the benign reference relationship; additionally, each O span is matched to its nearest predicted counterpart to retain short payloads. The authors emphasize that the residuals do not constitute an independent anomaly determination; a supervised head learns the risk-related directional deviations.
Training and decision
- Three member encoders per branch are fitted on training partitions grouped by different families; a standardized L2-logistic head maps member features to branch probabilities (Equation 3); the encoders use only training packages, the final head uses training plus development packages, and test packages do not participate in fitting or selection.
- The fusion policy is fixed as s(x) = max{pboundary(x), min(poperation(x), pgeometry(x))} (Equation 4), and a threshold of 0.5 determines BLOCK/PASS (Equation 5): Boundary can block independently, an additional block triggered by Operation requires Geometry support, and Geometry cannot block independently.
- An optional risk localization head reuses the D/O states and does not affect the decision (Appendix E.2).
Success determination and evaluation protocol
- F1, FPR, AUROC, and AP are reported with malicious as the positive class; pooled metrics weight packages equally, and source-macro metrics weight the five sources equally; confidence intervals use 2,000 source-stratified component-bootstrap resamples.
- The controlled studies (cross-form, intervention, composition) resample domains or families respectively and use diagnostic readouts fitted separately from package detection.
What experiments did the paper conduct?
Large-ID seven-backbone source-macro F1 93.0–94.6%; leave-one-source-out drops to 73.2%; detection is maintained under white-box rewriting and composition attacks.
Experimental Setup
- Backbones tested: Llama-3.1-8B-Instruct, Qwen2.5-7B-Instruct, Mistral-7B-Instruct-v0.3, InternLM2.5-7B, Qwen2.5-14B, Phi-3-medium-14B, Qwen3-30B-A3B, seven in total; the CompoSkill path experiments additionally include Llama-3.3-70B-INT8.
- Data: Large-ID contains 5,830 skills (2,915 source-matched malicious-benign pairs), from MalSkillBench (89.9%), SkillFortify, SkillsBench-1650, Agent-skill malware, ATR Skill Benchmark; 1,954 content-linked components are split into five folds, each fold with three training, one development and one test, and each skill is tested only once.
- Baselines: AgentLens (official probe protocol), RouteGuard (reproduced per paper specification, four probe prefills), input-level baselines Regex, SkillSieve L1, Cisco AI Skill Scanner, LLM-as-judge (Mistral-7B), supervised Qwen text readout.
- Metrics and decision: malicious-class F1, FPR, AUROC, AP; threshold 0.5; intervals use 2,000 source-stratified component-bootstrap; controlled studies resample domains or families.
Main Results
Large-ID detection (%, per Table 2; Src.-F1 is source-macro F1):
Swipe horizontally to read the table
Method Backbone FPR F1 Src.-F1 AUROC AgentLens Llama-3.1-8B 3.7 96.8 79.5 78.7 RouteGuard Llama-3.1-8B 19.7 84.9 77.3 85.2 LatentTriad Llama-3.1-8B 1.1 99.0 94.4 99.1 LatentTriad Qwen2.5-7B 1.4 99.0 94.3 99.1 LatentTriad Mistral-7B-v0.3 1.3 99.1 93.4 98.7 LatentTriad InternLM2.5-7B 1.1 99.2 94.6 99.2 LatentTriad Qwen2.5-14B 1.1 99.1 94.3 98.9 LatentTriad Phi-3-medium-14B 1.1 99.0 93.3 99.2 LatentTriad Qwen3-30B-A3B 1.2 99.1 93.0 98.9 - The authors report LatentTriad's mean source-macro F1 of 93.9%, higher than RouteGuard's 79.2% and AgentLens's 62.3%, with all 14 paired bootstrap intervals excluding zero; pooled FPR 1.1–1.4%, source-macro FPR 8.0–11.2%.
- Input-level baselines are weaker: LLM judge source-macro F1 30.5%, supervised Qwen text readout 58.4%, SkillSieve L1 60.5% (Table 2).
- Leave-one-source-out (LOSO): after excluding an entire source, mean source-macro F1 drops to 73.2% and AUROC to 80.3%, still higher than RouteGuard and AgentLens on the same backbone (Appendix Tables 20–21); the authors say the detection advantage transfers, but in-ecosystem performance does not hold.
Branch Ablation and Fusion Strategy
- Per Table 3 (seven-backbone source-macro means, threshold 0.5): Full's F1 93.91%, recall 96.73%; Boundary-only F1 91.63%, recall 92.58%; Geometry-only F1 95.85%, AUROC 99.68%, observed FPR 0 but recall 92.42%; max(B, O) F1 94.08%, recall 97.05%.
- The authors say the fixed max–min gating is not the optimal strategy on the reported metrics, and deployment should select a strategy on independent development data; replacing Geometry with independent state features only lowers Full's AUROC by 0.076 percentage points (95% CI [0.027, 0.136]).
Composition Attacks and Adaptive Rewriting
- CompoSkill: 690 matched attack-clean paths, LatentTriad detects 93.0–97.2% with FPR 3.8–4.3% (five backbones, Table 9); after seven rounds of feedback-guided rewriting, original-path detection remains 92.9–97.1%, and effective rewrites of the 9 blocked Llama and 8 blocked Qwen paths produce only 1 and 0 new escapes respectively (Table 13).
- White-box rewriting: cross-file split rewriting on Llama yields equal-source ASR 11.0% [6.5, 16.3], and all 21 backbone-attack units pass the paper's defined anti-escape criterion; but the same rewriting raises the benign FPR of that qualifying subset from 32.3–40.8% to 49.3–80.4% (Table 23).
- Generalization boundaries: on CompoSkill, workspace-only TF-IDF already performs strongly (Appendix Figure 6c); under the synthetic stress test of symbol permutation, AUROC drops to 49.25–53.47% (Appendix G.6). The authors say the results depend on contextualized representations and cannot establish general structural reasoning.
Other Ablations and Analyses
- Balanced 2×2 diagnostic (57 packages per cell): LatentTriad ranks the malicious operation above its benign counterpart in 94.7% (Llama) and 100% (Qwen) of pairs, while RouteGuard ties in all (Appendix E.1).
- Request-level broker simulation (256 pairs): under a 30% containment budget, mean ASR 17.2%, effective benign pass-through 46.7% (Table 24).
- Compact configuration (8/24 atom, CDF scoring) adds 56–65 ms, with prefill plus detection median 259–284 ms (Table 31); the end-to-end time of the full Large-ID pipeline was not directly measured.
- Cross-form controlled study: when holding out a certain expression form, Boundary AUROC 90.09–100.00% (Table 32); the O replacement intervention moves the frozen diagnostic logit toward the donor label by 2.376–2.909 (Table 33).
What are some points that can be further explored?
The authors list three types of limitations: readability scope, out-of-distribution generalization and deployment boundaries; the experiments cover seven backbones and five sources.
Limitations and future directions noted by the authors
- Scope of readability (Appendix H.1): under inferential prompts, the full-width linear Boundary readout reaches 53.12%, whereas 512-token generation reaches 94.53% (Qwen); the authors state this concerns the accessibility of the linear head tested and do not assert that the first prefill lacks information or that generation creates new knowledge.
- Boundaries of intervention conclusions (Appendix H.1): the intervention experiments answer different questions, cannot establish that B is a necessary mediator of the fused decision, and do not measure whether the agent executes the patched operation.
- Out-of-distribution generalization (Appendix H.2): source holdout changes the ecosystem and degrades performance; expression-form transfer supports robustness only for the forms tested, not cross-ecosystem screening; the synthetic symbol-permutation test is near chance even on known templates.
- Deployment boundaries (Appendix H.3): the detector requires white-box access and the input contract of Appendix A.1, and can only inspect loaded context; downloads, environment-triggered branches, and externally assembled payloads require permission enforcement and runtime monitoring in conjunction.
- Measurement boundaries (Appendix H.3): the compact-configuration timing does not represent the full Large-ID pipeline; the broker's request decisions do not measure task completion; the rise in false positives on the qualified subset under white-box rewriting and the limited coverage of effective adaptive rewriting also constrain deployment conclusions.
- Policy choice (Appendix H.3): Geometry-only and max(B, O) outperform the fixed rule on the component panel; selecting a specific deployment operating point requires separate selection on independent development data, and a policy cannot be chosen from test results.
Scope of experimental coverage
- Seven backbones were tested (the CompoSkill path experiments additionally include Llama-3.3-70B-INT8), all open-source instruction models; the paper reports no closed-source model experiments.
- The main evaluation is Large-ID's five sources and 5,830 packages, of which MalSkillBench accounts for 89.9%; benign packages total 114 across the three small sources (Table 15).
- The adaptive attack evaluation covers seven rounds of feedback rewriting (two backbones, Llama/Qwen) and three rewriting mechanisms in the white-box panel (256 pairs, seven backbones).
- Runtime measurements were conducted only on the compact 8/24-atom configuration of Llama-3.1-8B and Qwen2.5-7B, with 360 paired measurements per backbone; the paper does not report end-to-end latency for the full configuration.
- The paper does not report agreement between detection decisions and human evaluation; all decisions are given by a rule with a fixed threshold of 0.5.
Summarize the main content of the paper
A single prefill with three branches reads hidden states for pre-execution skill screening, with source-macro F1 93.0–94.6% on Large-ID.
A defense-oriented paper: addressing the problem that untrusted agent skills may induce operations outside the task context, the authors propose LatentTriad, which screens before generation and execution.
- Problem: skill risk depends on task context and may be distributed across multiple files; the authors argue that static rules struggle to capture behavioral intent and dynamic sandbox analysis is costly, so detection is needed after the model interprets the skill but before action.
- Method: perform a single prefill over the task and skill package and extract three types of hidden states—Declaration, Operation, and Boundary; the Boundary branch reads the full context, the Operation branch projects onto group-adjusted risk directions, and the Geometry branch measures residuals relative to benign reference relationships; a fixed max–min policy fuses them at a threshold of 0.5, without generating tokens or executing code.
- Main results: on Large-ID's five sources, 5,830 packages, and seven backbones, pooled F1 99.0–99.2% and source-macro F1 93.0–94.6% (Table 2); the authors report that its mean is higher than RouteGuard and AgentLens and that the paired intervals exclude zero.
- Generalization and robustness: under leave-one-source-out, source-macro F1 drops to 73.2% (Appendix C.3); CompoSkill compositional attacks are detected at 93.0–97.2% with FPR 3.8–4.3% (Table 9); under white-box cross-file split rewriting, equal-source ASR on Llama is 11.0%, but benign FPR rises from 32.3–40.8% to 49.3–80.4% (Table 23).
- Efficiency: for the compact configuration measured separately, prefill plus detection has a median of 259–284 ms (Table 31); the authors compare this with the approximately 153 s per skill reported by SkillDetonate, but the full Large-ID pipeline latency was not measured.
- Authors' conclusion: pre-action screening can complement execution-time permission enforcement and runtime monitoring; the authors also note that detection depends on white-box access and a fixed input contract, cannot address behavior triggered by downloads or the environment, and performs near chance under synthetic symbol-permutation tests.