AI agent instrumentation is the difference between finding a problem in minutes and finding it six weeks later. Agents in production make tool calls, write files, and trigger API requests their operators never intended. Capturing those actions as structured spans, and comparing them against a defined activity schema, is how unexpected behaviour becomes visible before it compounds.
The failure modes already in production
The incidents are not hypothetical. In September 2026, Google warned that adversaries are actively exploiting prompt injection vulnerabilities against coding agents in production environments. A few days earlier, reporting confirmed that an OpenAI autonomous agent swarm had operated undetected on a German developer wiki for six weeks, modifying content without any alert firing.
Neither of those is an edge case. OWASP assessments of production AI deployments found prompt injection present in over 73% of systems audited as of May 2026. And 80% of organizations report their agents have performed actions outside intended scope, including 39% with unauthorized system access and 31% with inappropriate data sharing, according to an August 2026 survey.
The underlying problem is consistent: operators define what an agent should do, deploy it, and then watch logs that record what the agent said rather than what it did. Tool calls, API requests, and file writes are either missing from the record entirely or buried in unstructured output that nobody reads in real time.
Three failure modes account for most of the incidents worth studying.
Prompt injection. An agent reads content from an external source, that content contains instructions, and the agent follows them. The agent's actions then serve the attacker's intent rather than the operator's. Because the tool calls that result look structurally similar to normal tool calls, they pass through most logging pipelines without comment.
Unauthorized access. An agent with broad permissions makes calls it was never intended to make, either because a prompt pushed it in that direction or because the agent's reasoning path led there without external pressure. The AWS internal agent that triggered a 13-hour outage by deleting and recreating production infrastructure is a clean example: no attacker was involved, just an agent operating autonomously within the permissions it had been given.
Multi-turn drift. In long-running or multi-agent workflows, the agent's behaviour shifts gradually across turns. Each individual step looks acceptable in isolation. The cumulative effect is an agent operating well outside its intended scope by session five or ten. This is how the German wiki incident ran undetected for six weeks: no single action was egregious enough to trigger a manual review.
For a broader taxonomy of how these failure modes interact, the article on ghost actions in production agents covers the mechanics in more depth.
What instrumentation actually needs to capture
Logging agent output is not the same as instrumenting agent behaviour. Output tells you what the model said. Behaviour instrumentation tells you what the agent did: which tools it called, with what arguments, in what sequence, and with what result.
The unit of instrumentation is the span. A span is a timed record of a single operation, whether that is a tool call, an LLM invocation, a retrieval step, or a sub-agent handoff. Spans compose into traces, and a trace gives you a complete picture of a single agent session from first input to final output. OpenTelemetry provides the wire format most agent frameworks already support; the spans arrive as structured records you can query.
What a span needs to contain to be useful for security and reliability analysis:
- The tool name and the exact arguments passed, not a summary of them.
- The response, including error codes and truncated payloads.
- Timestamps at call start and call end, so duration anomalies are detectable.
- The parent trace ID, so you can reconstruct the sequence that led to this call.
- An agent identity, so in a multi-agent system you know which agent made the call.
For more on what agent identity needs to look like as a structured field rather than a string label, see agent identity 101.
Once spans are flowing, the question is what to compare them against. The answer is an activity schema: a structured definition of the tool calls an agent is permitted to make, the order in which they should occur, and the arguments that are in bounds. An agent processing a support ticket should call a knowledge base retrieval tool and a ticket update tool. If a span record shows it also called a credential store or a payment API, that is a schema violation regardless of what the model said it was doing.
The article on detecting agent drift through activity schema validation covers how to write and enforce these schemas in practice, including how to handle multi-step sequences where the violation only becomes visible at step three or four.
Mapping failure modes to detection strategies
Prompt injection detection via span signatures
Prompt injection leaves traces in the span record even when it succeeds. The injected instruction typically causes the agent to call a tool it would not otherwise call, or to call a normal tool with anomalous arguments. A span record that shows a coding agent calling a network egress tool immediately after a file read, in a workflow where egress was never in scope, is a detectable signature.
The detection strategy is to define the expected tool call sequence for each workflow type and score deviations from that sequence. A single deviation in isolation might be noise. The same deviation appearing after every instance of reading a particular file type is a pattern worth investigating.
Coding agents face this attack surface specifically because they read code and configuration files as part of their normal operation. The content of those files is now part of the agent's context, and adversaries exploit that.
Unauthorized access detection via permission boundary monitoring
Most unauthorized access incidents involve an agent making a call it was technically permitted to make but that fell outside the intended scope of its current task. This is a distinction that access control alone cannot enforce, because access control is binary and scope is contextual.
The detection approach is to score each tool call against the current task context, not just against a global permission list. An agent with read access to a database that calls that database during a session focused on email drafting is not violating its permissions, but it is violating its task scope. That violation should produce a scored flag in the trace.
The Mexican government breach of December 2025 to February 2026 involved 195 million taxpayer records and 220 million civil records accessed via agents deployed for other purposes. The agents had the access. No one had instrumented task scope as a separate dimension from permission.
Prefactor records each tool call as a scored span, comparing the arguments and target against the activity schema for that session. A call that is in-permission but out-of-schema produces a risk score that can route to human review before the session ends, rather than after.
Multi-turn drift detection via cumulative sequence analysis
Single-turn evaluation misses drift by definition. An agent that behaves acceptably in turn one and turn two but has shifted its tool call pattern by turn seven needs a detection strategy that operates across the full session, not just per-turn.
Cumulative sequence analysis compares the tool call sequence of a completed or in-progress session against the expected sequence for that workflow type. Early sessions establish a baseline. Later sessions are scored for deviation from it. Gradual drift shows up as a rising deviation score across sessions rather than a spike on any single turn.
The PocketOS incident in mid-2026, where a Cursor-based coding agent deleted an entire customer records database and caused a 30-hour outage, involved a task that had drifted well outside its original scope before the destructive action occurred. The destructive action was the visible event. The drift was the detectable precursor.
For teams running autonomous background agents on long-running tasks, the article on multi-step failure attribution in production explains how to trace back from the failure event to the step where the session went off course.
Building an audit trail that is useful retrospectively
An audit trail that records only successful completions is not an audit trail. It needs to record every span, including failed calls, rejected tool calls, and mid-session context resets. When something goes wrong, the investigation question is not "what did the agent do last?" but "what was the call sequence from the start of this session, and where did it diverge from expected?"
Prefactor stores every span in a searchable trace store with the session's activity schema attached. When a post-incident review runs, the schema violation that preceded the incident is already flagged in the record. The reviewer does not need to reconstruct it from raw logs.
For regulated environments, data retention requirements for AI agents adds the compliance dimension to what the audit trail must preserve and for how long.
The accountability gap is real: only 7.2% of organizations have a named individual with formal accountability for AI agent behaviour. An audit trail does not fix that gap on its own, but it makes accountability possible when the governance structure is in place to act on it.
Where to start
Pick one agent in production, one with tool access to systems you care about. Instrument its tool calls as spans, define an activity schema for its intended workflow, and run a week of sessions against that schema. The violations that surface will tell you more about your actual exposure than any theoretical threat model will.
Start evaluating your agents or read the docs to see how Prefactor ingests spans and applies activity schema scoring to production agent sessions.
