Wiring Instruction Snapshots Into Span Attributes so Observability Tools Can Judge Execution Against Original Intent
Attaching frozen prompts to spans lets auditors judge what agents did.

Intent-aware auditing for AI agents requires a frozen record of what the agent was told to do, linked to the trace of what it did. Instruction snapshots attached through span attributes make that link, so observability tools can compare what the agent did with what it was told to do. For large or sensitive snapshots, the span should hold a reference to the exact stored invocation-time instructions.
Why agents fail silently and why APM misses it
An agent can return confident, well-formed, semantically wrong output with a clean status code and normal latency. Traditional APM watches CPU, memory, request latency, and HTTP errors. Those signals describe infrastructure health. A Salesforce agent that maps the wrong custom field can receive HTTP 200 at negligible latency, leaving the transaction recorded as successful even though it completed the wrong operation.
A support agent can retrieve last year’s refund policy at step 1, summarize it through a tool call at step 3, and quote it as fact at step 10. Each operation can look healthy even when the answer is wrong. This is a structural limit of binary pass/fail monitoring. If the failure is semantic, what must the monitoring signal contain to detect it.
What makes agent failures debuggable: the trace as a causal record
A trace supplies the execution record needed to answer that question. It represents a complete agent run, from the user request to the final answer, with nested spans for model calls, tool calls, retrievals, and memory reads. Each span records its own inputs, outputs, tokens, latency, and error state. The nesting preserves the chain of calls and responses. The agent invocation is the root, with model and tool operations nested beneath it to show which calls they made.
That structure makes a wrong answer locatable. Instead of treating the final response as an isolated failure, an engineer can identify the retrieval span that returned the wrong document and follow its effect downstream. A 30-minute agent run can produce 200+ spans, so this record needs programmatic queries and evaluation. Yet the tree alone describes only execution. The instructions governing that execution are not automatically part of the agent span.
The missing dimension: intent is not in the trace by default
System prompts, task descriptions, guardrail rules, and tool-use policies are often kept outside the trace. They may sit in application code, a config file, a database row, or a prompt registry. Investigating a failure then requires reconstructing external state. That reconstruction becomes unreliable when prompts are versioned, A/B tested, or edited between the incident and the investigation. Execution evidence remains available, but the standard against which to judge it is missing.
A downstream API changed a field name from incident_count to num_incidents, so routing decisions were made with context missing. Without the instruction snapshot, the trace lacked the declared tool schema needed to show its divergence from the API’s actual response shape. The instruction-at-execution-time is the version required to judge that run. A current prompt retrieved during investigation describes what the agent would receive today, which may differ from what governed the failed decision.
The instruction snapshot pattern: what to capture and where to attach it
The implementation follows directly from that diagnosis. Capture a frozen snapshot at agent initialization, including the complete system prompt, task description, active tool policy and argument constraints, guardrail rules, and retrieval or memory configuration. Attach the snapshot, or its immutable reference, to the invoke_agent span. This is the governing span for the agent’s subtree. Child chat and execute_tool spans can then be correlated with that instruction set without repeating the payload on every operation.
For multi-agent systems, each agent boundary needs its own snapshot. The orchestrator’s instructions belong on its invoke_agent span, while a sub-agent’s instructions belong on the sub-agent’s own invoke_agent span. Trace IDs must propagate across that boundary to preserve the relationship. Resumption also needs a link to persisted state. A checkpoint_id can connect the trace to a stateful checkpoint, while the pruneAgentLoopSnapshot pattern preserves context.input whole so a resumed run can rebuild its span without per-step duplication of the full snapshot.
A custom gen_ai.agent.instructions attribute, or an equivalent field, identifies the invocation-time system prompt, while gen_ai.agent.tool_policy records permitted tools and their constraints. prompt.version and prompt.variant identify the prompt template and variant. Correlation fields such as tenant.id and user.cohort support grouping by the affected population. These identifiers supplement the snapshot’s complete contents.
The size and privacy problem with storing prompts on spans, and how to solve it
Attributes have size limits and are indexed by default, so large instructions can hit backend limits and expose sensitive content to downstream consumers. Span events offer only a partial improvement. A collector can filter or drop them, but an auditing system still needs a retrievable copy of the original instructions. If that content is dropped without keeping a reference, the evidence is lost.
OpenTelemetry defines three modes for prompt content, including no recording by default, direct storage in attributes, and external storage with a reference on the span. At initialization, write the frozen snapshot to object storage, a prompt registry, or a versioned config system, then attach its reference URL and prompt version to the agent span. At query time, retrieve that specific snapshot. This differs from reconstructing instructions from current external state because the reference identifies the captured version.
Privacy controls belong in the collector pipeline, where sensitive attribute values can be stripped or hashed before reaching the storage backend. Sampling needs its own decision because semantic failures often have successful status codes. The working pattern is full capture on errors and low-rate sampling on successes, with a snapshot reference present on every retained agent span. The reference keeps trace payloads small without sacrificing evidence. The exact instructions can still be retrieved for past runs kept for audit.
OTel GenAI conventions as the shared vocabulary for attaching intent
OpenTelemetry GenAI semantic conventions provide the vocabulary for this span tree. The gen_ai.* namespace covers operations including invoke_agent, chat, execute_tool, embeddings, and create_agent, making traces comparable across frameworks. Instruction references and prompt identifiers are added to that record as custom attributes. They are not all standardized GenAI fields. Their portability comes from an OTLP-compatible representation that backends can read without requiring the application to adopt a different execution model.
As of v1.41, all gen_ai.* attributes have Development stability, while shared core attributes such as error.type and server.address have Stable badges. Teams should version-pin instrumentation and watch the specification changelog because GenAI attribute names can change without a major version bump. MCP instrumentation adds another coordination point. When outer GenAI instrumentation already tracks a tool execution, MCP instrumentation should enrich the single existing execute_tool span, although this behavior is a recommendation whose implementation may require configuration.
Evaluation results have a defined place in this vocabulary. The conventions define gen_ai.evaluation.result as a log event with gen_ai.evaluation.* event attributes, which should be parented to the GenAI operation span being evaluated. This keeps the judgment linked to execution rather than treating it as an unrelated dashboard result. Across agents, W3C Trace Context must preserve the shared trace ID. Otherwise, a sub-agent failure looks as though it has no link to the workflow it belongs to.
How do you audit agents against what they were supposed to do
With the snapshot available, an observability tool can compare declared intent with recorded behavior. It reads the governing instructions from the invoke_agent span’s snapshot reference and examines tool calls and model outputs in the child spans. Both sides of the comparison are now present. This supports evaluation without a hand-written assertion for every failure mode, although the judgment still needs to be made against the relevant instruction. The capability depends on retrieving invocation-time intent.
A tool span may return an error payload that a later model span treats as valid data, but the snapshot gives the output format the tool was expected to return. Instruction drift has a different comparison. An execute_tool span can be checked against the permitted tools and argument constraints in the active policy. The same successful run status can thus hide different violations that need different fixes.
Tool-call count above P99 of the historical distribution for that task type can flag excessive repetition, while cost-per-run above P99 can expose runaway loops or context blowouts. The task description helps explain those anomalies. A high count alone does not distinguish an agent exceeding its scope from a task whose scope changed. The snapshot provides that missing basis for diagnosis.
The snapshot names incident_count, but the tool response has num_incidents. The recorded mismatch explains the routing error as context-schema drift. A platform therefore needs to retrieve the exact snapshot, link it to child execution spans, and link evaluation results to the operation being judged.
Instrumenting the pattern across the frameworks teams already use
The pattern is framework-agnostic, but attachment requires deliberate instrumentation. OpenAI Agents SDK wraps each Runner.run() call in a trace, with spans for agent activity, generation, function calls, handoffs, guardrails, tasks, and turns. A response span provides a Responses-API-specific alternative to a generation span. Custom export has two routes. add_trace_processor() adds processing beside the default backend, while set_trace_processors() replaces the default processors.
For snapshot attachment, the SDK call can be wrapped in an OTel span with custom instruction-reference attributes. The SDK’s experimental_telemetry creates child spans under the active OTel context, keeping the wrapper and execution in the same trace. More generally, instrumentation in Python, TypeScript, and Java can use a register() call with project name, version, and semantic convention, including OpenInference or OTel-GenAI. Subsequent model calls produce OTLP spans. The exporter can then change without changing application code.
When sub-agents run in separate processes, propagation must be set up explicitly. Naive instrumentation may show the spawning tool call but reveal none of the sub-agent’s internal activity. The remedy is to propagate W3C Trace Context across the process boundary and capture the sub-agent’s invoke_agent span as a child of the spawning call. Its own snapshot belongs on that span. The parent’s instructions cannot substitute for the operating context of a separately instructed agent.
Closing the loop from silent failure to verified fix
Detection becomes operationally useful when recurring mismatches become issues. Failures that violate the same instruction clause should be grouped automatically. A prompt edit, tool-policy change, or schema update then produces a new prompt.version that can be evaluated against the retained real-traffic examples. The original snapshots preserve the baseline for that comparison.
Those examples can also become regression evaluations without hand-written assertions. The trace and snapshot already supply the input, declared intent, and observed output, allowing a human label or model judge to produce a pass/fail judgment against the instruction. Evaluating the new version on those examples tests the proposed fix before another production incident is needed. This makes instruction capture part of the feedback infrastructure. Without that loop, failures are detected through user complaints or churn, days or weeks after silent semantic failures have reached customers.


