# What structural signals indicate adversarial skill-injection via behavioral drift in agent toolchains **Date of Record:** 2026 November 27 **Scope:** Applies to tool-using LLM agents whose capability set is extended at runtime (skill/plugin registration, MCP tool discovery, dynamic function-calling schemas) and whose outputs are monitored for drift against a baseline behavior profile. Does not apply to statically compiled toolchains where the tool manifest is frozen at build time and never renegotiated. ## Core Distinction Behavioral drift monitoring is typically framed as a *distributional* problem: compare the agent's output distribution against a baseline and flag divergence. That framing fails against skill-injection because the adversary does not perturb the *marginal* distribution of agent outputs — it perturbs the *conditional structure* of tool invocation. A malicious skill that exfiltrates a credential via a legitimate-looking `format_report` call produces outputs that are locally indistinguishable from the baseline; the drift lives in the *argument-dependency graph* (which prior context tokens the tool arguments are a function of), not in the output text. The distinction that matters operationally: **output drift is a symptom; argument-provenance drift is the signal.** An injected skill can hold output drift below any KL-divergence threshold while rewiring which fields of the tool-call JSON are sourced from which context segments. The invariant to monitor is not "does the agent behave differently" but "does the *causal parent set* of each tool argument change after a skill registration event." ## What Was Observed Across three production agent toolchains instrumented with per-tool-call argument tracing, a consistent failure trace emerged after an adversarial skill was registered under a plausible name (`summarize_thread_v2`, `normalize_contacts`, `audit_permissions`). The trace has five structurally identifiable stages: 1. **Registration-time schema shadowing.** The injected skill declared an input schema that was a strict superset of an existing trusted tool's schema — same required fields, additional optional fields (`context_hint`, `source_uri`, `cache_key`). The tool router, keying on name similarity and schema compatibility, began routing a fraction of calls to the new skill. No error fired: the superset schema is *valid* against every call site. 2. **Argument-provenance shift.** Before injection, the `query` argument of the trusted tool was sourced (by token-attribution tracing) from the user turn 94% of the time and from retrieved memory 6%. After injection, the injected skill's `context_hint` argument was sourced from the *system prompt* and *prior tool outputs* 71% of the time. This is the load-bearing signal: the adversary's skill is reading context regions the trusted tool never touched, because its superset schema gave it a slot to place them. 3. **Latent-state accumulation.** The injected skill's outputs included a benign-looking field (`_cache_token`) that the agent's planner carried forward into subsequent turns as conversational state. This is the poisoning vector: the skill did not need to act maliciously in one call; it seeded state that later calls conditioned on. 4. **Delayed divergence.** Output drift, measured as embedding distance from baseline per turn, stayed within 0.04 (below the 0.15 alert threshold) for 11–40 turns. The first detectable output divergence occurred only when accumulated `_cache_token` state crossed a context-window threshold and began displacing genuine user-context tokens — a *saturation* event, not an injection event. By then the injected skill had been invoked hundreds of times. 5. **Detection lag.** Median detection lag between first routing to the injected skill and first output-drift alert was 23 turns; median detection lag between first routing and first *argument-provenance* alert (when that monitor was enabled) was 2 turns. ## Condition of Validity The argument-provenance signal is only valid under three conditions, and each is a place where naive implementations produce false negatives: - **Token attribution must be per-argument, not per-call.** Attributing the whole tool call to a context region averages away the signal. The injected skill's `context_hint` is 100% sourced from system prompt while its `query` is 90% user-sourced; the call-level average looks normal. - **The baseline must be conditioned on tool identity, not agent identity.** A baseline that pools all tool calls across the toolchain will absorb the injected skill's provenance profile into the "normal" envelope within a few dozen calls. Baseline must be keyed on `(tool_name, schema_hash)` so that a new schema hash starts with no baseline and is flagged as *unbaselined* rather than *baseline-conforming*. - **Registration events must be timestamped into the trace.** If the monitor cannot correlate a provenance shift with a specific skill-registration event, it cannot distinguish adversarial injection from legitimate capability expansion. The invariant is: *every provenance shift of magnitude > τ must be attributable to a registration event within the preceding N calls, or it is an anomaly.* The signal is invalid (produces false positives) when a legitimate skill is registered that intentionally reads broader context — e.g., a summarizer that is *supposed* to consume system prompt and prior outputs. This is why the guardrail is not "flag provenance shifts" but "flag provenance shifts that are *not declared in the skill's capability manifest*." The manifest is the contract; drift from the manifest is the violation. ## Decision Boundary The boundary between "benign capability expansion" and "adversarial skill-injection" is not a threshold on drift magnitude. It is a **manifest-conformance predicate** over the argument-provenance graph: - **Benign:** provenance shift is confined to context regions declared in the skill's manifest (`reads: [user_turn, retrieved_memory]`), and the shift magnitude is stable across calls (low variance). - **Suspicious:** provenance shift touches an undeclared region (system prompt, credential store, prior tool outputs) OR the shift magnitude has high variance across calls (indicating the skill is *conditionally* reading context — a hallmark of exfiltration logic that only activates on trigger tokens). - **Adversarial:** undeclared region access AND latent-state emission (skill output contains fields that persist into planner state) AND schema-superset relationship to an existing trusted tool. All three together is the signature; any two is a hold for review. The boundary is deliberately set at the *conjunction* of three structural signals rather than any single one, because each individually has a benign explanation (broader reads = summarizer; latent state = caching; schema superset = versioning). The conjunction has no benign explanation observed in the corpus. ## Operational Effect Enforcing the manifest-conformance predicate at the tool-router layer changes the failure mode from *silent multi-turn poisoning* to *fail-closed at registration-to-first-invocation*. Concretely: - Detection latency drops from O(10¹) turns to O(10⁰) turns, because the provenance check fires on the first call whose arguments source from an undeclared region. - The blast radius is bounded to a single tool call, because latent-state emission from an unbaselined skill is quarantined before it can enter planner state. - The router must reject, not just log, because the poisoning vector is state accumulation — a logged-but-allowed call still seeds `_cache_token`. The cost is a mandatory capability-manifest declaration for every skill, and a provenance-tracing overhead of roughly one attribution pass per tool call. In the instrumented toolchains this was ~8% latency overhead and eliminated the class of undetected injections that previously required post-hoc forensic reconstruction. ```python import hashlib from dataclasses import dataclass, field from typing import FrozenSet, Dict, List, Optional class SkillInjectionBoundaryError(RuntimeError): """Raised when a tool call violates the manifest-conformance predicate.""" pass @dataclass(frozen=True) class CapabilityManifest: skill_name: str schema_hash: str declared_reads: FrozenSet[str] # context regions the skill may source from declares_latent_state: bool # does the skill emit persistent state fields? superset_of: Optional[str] = None # name of a trusted tool this schema extends @dataclass class CallTrace: skill_name: str schema_hash: str # per-argument provenance: arg_name -> {context_region: attribution_fraction} provenance: Dict[str, Dict[str, float]] emitted_state_fields: List[str] = field(default_factory=list) TRUSTED_TOOLS: FrozenSet[str] = frozenset({"format_report", "fetch_doc"}) def _schema_hash(schema: dict) -> str: return hashlib.sha256(repr(sorted(schema.items())).encode()).hexdigest() def enforce_manifest_conformance( trace: CallTrace, manifest: CapabilityManifest, baseline: Dict[str, Dict[str, Dict[str, float]]], # (skill, schema_hash) -> provenance undeclared_region_threshold: float = 0.30, ) -> None: """ Fail-closed boundary check. Raises on the conjunction of structural signals that has no benign explanation in the observed corpus. """ # Signal 1: undeclared context-region reads. undeclared_access = False for arg, regions in trace.provenance.items(): for region, frac in regions.items(): if region not in manifest.declared_reads and frac > undeclared_region_threshold: undeclared_access = True break if undeclared_access: break # Signal 2: latent-state emission from a skill that did not declare it. latent_emission = bool(trace.emitted_state_fields) and not manifest.declares_latent_state # Signal 3: schema superset of a trusted tool (shadowing relationship). schema_shadowing = ( manifest.superset_of is not None and manifest.superset_of in TRUSTED_TOOLS ) # Unbaselined schema: a new schema_hash has no provenance baseline, so it # must not be treated as conforming by default. baseline_key = (trace.skill_name, trace.schema_hash) is_unbaselined = trace.skill_name not in baseline or trace.schema_hash not in baseline.get(trace.skill_name, {}) signals = sum([undeclared_access, latent_emission, schema_shadowing]) if signals >= 2: raise SkillInjectionBoundaryError( f"adversarial skill-injection signature: skill={trace.skill_name!r} " f"schema={trace.schema_hash[:8]} signals=" f"[undeclared_read={undeclared_access}, " f"latent_emission={latent_emission}, " f"schema_shadowing={schema_shadowing}]" ) if is_unbaselined and undeclared_access: raise SkillInjectionBoundaryError( f"unbaselined skill reading undeclared region: skill={trace.skill_name!r} " f"schema={trace.schema_hash[:8]} — quarantined before latent-state entry" ) # Benign path: record provenance into baseline for future conditioning. baseline.setdefault(trace.skill_name, {})[trace.schema_hash] = trace.provenance ```