Guide · Agent security

AI agent audit trail: what to log for every tool call

Andrey Lesnikov · 2026-11-13 · sources checked 2026-11-13

Identity, policy version, verdict, approval and cost — recorded for every agent tool call. A design for an audit trail on Kubernetes, not a product.

On this page

When an agent does something it should not have done, the first questions are always the same. Which agent was it, acting for whom? What exactly did it call, with which arguments? Was the call allowed by policy, and by which version of the policy? Did a human approve it? What did it cost? Most teams find out during the incident that their logs answer one or two of these, spread across three systems with no shared ID.

This guide defines the record I want for every agent tool call, and where each field comes from: the tool gate, the gateway, OpenTelemetry and Kubernetes. It is a design for an audit trail, not a product. Where my own repositories implement part of it, I say which part and with which limits.

Tool call recorded as a hash-chained evidence envelope for later review
Tool call recorded as a hash-chained evidence envelope for later review
Every tool call leaves an evidence-grade audit record. Tool call Audit record identity · policy · verdict approvals · cost · digest trace_id · evidence chain OTel
Every tool call leaves an evidence-grade audit record.

Why the logs you already have are not enough

  • Kubernetes audit logs record requests to the Kubernetes API server. They show that a ServiceAccount created a Job or read a Secret. They do not show that an agent called send_email through an MCP server, because that never touches the API server.
  • Application logs usually record the tool call but not the decision: which policy allowed it, whether approval was required, what the policy digest was.
  • LLM traces record model calls and often tool spans, but arguments and results are frequently dropped for privacy, and nobody links the span to the policy decision.
  • Gateway logs record tokens and cost per request, but not which tool call the request led to.

An audit trail joins these with shared identifiers and adds the decision evidence that none of them carries on its own.

The record: one entry per tool call

The minimum set of fields, grouped by the question each group answers:

Group Field Why
Who agent_id, agent_name Which agent acted
Who workload_identity (ServiceAccount or SPIFFE ID) Which runtime identity executed the call
Who on_behalf_of (user or tenant) Whose authority the agent used
What tool_name, tool_server Which tool, served by which MCP server
What tool_catalog_digest Which approved catalog the tool came from
What arguments_digest (+ redacted arguments) Exactly what was requested, without storing secrets
Decision verdict (ALLOW / BLOCK / REQUIRE_APPROVAL) What the gate decided
Decision reason Why, in a machine-readable form
Decision policy_version, policy_sha256 Which rules were in force
Decision approval_id, approver, approved_arguments_digest Who approved, and what exactly
Outcome outcome (executed, blocked, error, timeout) What really happened
Outcome result_digest, result_size What came back, without storing it in full
Cost input_tokens, output_tokens, estimated_cost What the model step behind the call cost
Correlation trace_id, span_id Join with traces
Correlation conversation_id, tool_call_id, mcp_session_id, jsonrpc_request_id Join with model and MCP records
Provenance commit_sha, runtime_version Which build made the decision
Time timestamp (UTC) Ordering
Integrity record_digest Detect edits to a stored record

Some fields will be empty for some calls. That is fine. A missing approval on a call that did not need one is information; a missing policy digest on any call is a gap.

Use the OpenTelemetry names where they exist

The OpenTelemetry GenAI semantic conventions define an execute_tool span. Its name should be execute_tool {gen_ai.tool.name}, its kind INTERNAL, with gen_ai.operation.name set to execute_tool. Relevant attributes:

  • gen_ai.tool.name (required), gen_ai.tool.type, gen_ai.tool.description
  • gen_ai.tool.call.id, conditionally required: the identifier the model or provider supplied for the call
  • gen_ai.agent.name and gen_ai.conversation.id, when available
  • error.type when the call failed
  • gen_ai.tool.call.arguments and gen_ai.tool.call.result, both Opt-In

For MCP, the conventions define client and server spans with mcp.method.name (for example tools/call), mcp.session.id, mcp.protocol.version and jsonrpc.request.id.

Two things to keep in mind. First, all of these are at Development stability, so names can still change; pin the semconv version you follow. Second, the Opt-In status of arguments and results is deliberate: the registry warns that such attributes may contain sensitive data. Do not turn them on globally to "have everything". Store a digest and a redacted copy in the audit record instead.

Using the same names in the audit record and in traces means one query language works for both, and the trace_id join is trivial.

The decision is the part most systems miss

An audit trail without the policy decision only tells you what happened. With the decision it also tells you whether it was supposed to happen. That requires a gate that runs before execution and emits evidence.

The Agent Security Contract emits an evidence envelope for every verdict, defined by a JSON schema in the repo. For the broader security controls around AI agents, see OWASP Agentic Top 10 mapped to Kubernetes, MCP security checklist for Kubernetes, and the agent security hub. The envelope fields:

  • schema_version, policy_version, policy_sha256
  • scenario_id, verdict, reason
  • trace_id, commit_sha, timestamp (UTC ISO-8601)
  • envelope_sha256, a SHA-256 over the canonical JSON of all other fields

asc verify rejects envelopes with missing fields, inconsistent verdicts, edits that no longer match the digest, and, with --policy, a policy_sha256 that differs from the policy file. The README is careful about the limit, and so should you be: envelope_sha256 is an unkeyed integrity digest, not a signature. It catches accidental or naive edits; someone who can rewrite the file can also recompute it. Treat envelopes as trustworthy only when they come from a CI run or a pipeline you control.

The AI Runtime Platform records a similar decision on the request path. Its enforcement-evidence document lists control_plane_decision_id, policy_bundle_id, policy_digest, request_digest, runtime_version and an enforcement_outcome (executed, blocked, approval_required, upstream_error, stream states). For MCP execution, its sequence ends with an audit call carrying session, capability and request IDs. Signed decision tokens (JWS) are optional and verified against a JWKS URL and audience. The repo also states that its Redis decision store is TTL-bound operational state, not an audit log. That distinction matters: the decision store answers "what was decided recently", the audit trail must survive much longer.

Cost questions come up in almost every agent review: which task cost what, and was the spend expected. If the audit record carries the trace_id and the gateway records usage on the same trace, you can answer "cost per task" instead of "cost per day".

In the AI Runtime Platform, usage events carry tenant_id, request_id, decision_id, model and backend, input and output tokens, estimated cost, GPU seconds, duration and outcome, and the same fields are attached to the active OTel span. The repo calls these events attribution-grade and best-effort: they can be lost on pod crash, buffer overflow or shutdown timeout, and the docs point to an external durable sink for billing-grade delivery. That is the right framing for an audit trail too: cost in the audit record is for attribution, not invoicing.

The Cost and Token Observability case describes the operating side: tying token and cost telemetry to services, gateway requests and deployment events, so cost becomes a signal teams act on. For the complete observability mesh, the OpenTelemetry Observability Mesh case shows how traces, metrics and logs correlate into one investigation story.

Arguments, results and sensitive data

The tension: auditors want exact arguments, privacy wants none. A workable rule:

  1. Always store a digest of the canonical arguments and of the result. A digest proves what was requested without revealing it.
  2. Store a redacted copy of arguments with known secret fields removed (tokens, passwords, keys) and free text truncated.
  3. Store full arguments only for high-impact tools, in a separate store with stricter access and shorter retention, if your policy requires it.
  4. Bind approvals to the argument digest. An approval for delete /workspace/tmp/report.json must not cover delete /workspace.

The OWASP Logging Cheat Sheet's general rules apply: do not log secrets or session tokens, protect logs from tampering, and keep the log pipeline from becoming an injection path. Agents make the last one more likely, because tool arguments and results are often model-generated text.

Where Kubernetes audit fits

Kubernetes audit is still useful: it covers what agents do through the Kubernetes API. Write an audit policy that records agent ServiceAccounts at Metadata level by default, RequestResponse for writes to the resources you care about, and never request bodies for Secrets:

apiVersion: audit.k8s.io/v1
kind: Policy
omitStages:
  - RequestReceived
rules:
  - level: Metadata
    resources:
      - group: ""
        resources: ["secrets"]
  - level: RequestResponse
    userGroups: ["system:serviceaccounts:agents"]
    verbs: ["create", "update", "patch", "delete"]
  - level: Metadata
    userGroups: ["system:serviceaccounts:agents"]

Rules are matched in order, so the Secrets rule comes first. Join Kubernetes audit events to the tool-call record by ServiceAccount and time window, or better, by putting the trace_id into a request annotation where your tooling allows it.

Storage and integrity

  • Append-only storage that the agent's identity cannot write to or delete from. The component that writes audit records should be different from the one that executes tools.
  • Per-record digest plus a chain or batch digest, so removal of records is detectable, not only edits.
  • Signatures if records are evidence for third parties. An unkeyed hash is not enough there.
  • Retention defined per field group: decision evidence long, redacted arguments medium, full arguments short.
  • Clock discipline: UTC timestamps from synchronized nodes; record both decision time and execution time if they differ.

An example record

Values are placeholders; the shape is what matters.

{
  "timestamp": "2026-10-22T08:00:00Z",
  "trace_id": "<trace-id>",
  "span_id": "<span-id>",
  "agent_name": "research-agent",
  "workload_identity": "system:serviceaccount:agents:research-agent",
  "on_behalf_of": "tenant:docs-team",
  "tool_name": "http_get",
  "tool_server": "mcp-docs",
  "tool_catalog_digest": "sha256:<catalog>",
  "tool_call_id": "<provider-call-id>",
  "mcp_session_id": "<session-id>",
  "arguments_digest": "sha256:<args>",
  "arguments_redacted": {"url": "https://docs.internal.example/page"},
  "verdict": "ALLOW",
  "reason": "host allowlisted",
  "policy_version": "<policy-version>",
  "policy_sha256": "sha256:<policy>",
  "approval_id": null,
  "outcome": "executed",
  "result_digest": "sha256:<result>",
  "input_tokens": null,
  "output_tokens": null,
  "commit_sha": "<commit>",
  "record_digest": "sha256:<record>"
}

How to prove to an auditor that every agent action is authenticated, authorized and logged

An auditor sampling your agent logs will ask three questions. Each question maps to specific fields in the audit record and to architectural choices that generate those fields at enforcement time, not after the fact.

1. Authenticated: which agent acted, for whom, bound at the gate

The auditor needs proof that the identity recorded for a tool call came from the enforcement gate, not from a self-reported claim in the model prompt or tool arguments. Post-hoc attribution (parsing agent name from a completion or reading it from context) does not prove authentication.

What to show:

  • workload_identity: the Kubernetes ServiceAccount or SPIFFE ID under which the process ran. This comes from the platform, not the application. On Kubernetes it is system:serviceaccount:<namespace>:<serviceaccount>, verified by the API server.
  • agent_id and agent_name: identifiers for the agent itself, recorded by the tool gateway or authorization gate that intercepts the call.
  • on_behalf_of: the user or tenant whose authority the agent used. This should be bound to the request by the session authenticator (OAuth token, OIDC claim, or signed credential presented at session start), not read from a tool argument.
  • Binding point: the enforcement component (authorization gate, tool proxy, or MCP gateway) that checks identity before allowing the tool call must be the same component that writes the audit record. If the agent itself logs its identity, an attacker who compromises the agent can log a false identity. If a separate gate logs it, compromise of the agent does not falsify the record.

Verification: an auditor picks a record, finds the workload_identity, and checks that a ServiceAccount with that name existed in the cluster at timestamp. They then verify that the enforcement policy in force at that time required the caller to present that identity. The Agent Security Contract and similar gates bind identity at policy evaluation time; the decision envelope records it.

2. Authorized before execution: fail-closed verdict on the request path

The auditor needs proof that a policy was evaluated before the tool ran, not that the call was logged afterward. Logging alone does not prove authorization. A log entry for a tool call with no verdict, policy_version, or policy_sha256 is evidence that a call happened, not that it was allowed.

What to show:

  • verdict: ALLOW, BLOCK, or REQUIRE_APPROVAL. This must come from a decision made on the request path. A tool call that was blocked should still produce an audit record with verdict: BLOCK and outcome: blocked. If blocked calls are missing from the log, you cannot prove to an auditor that unauthorized calls did not succeed.
  • policy_version and policy_sha256: which rules were in force, pinned by digest. The digest binds the decision to the exact policy text. An auditor can check out the repository at the commit recorded in commit_sha, hash the policy file, and confirm it matches policy_sha256. If it does not match, either the record was tampered with or the decision cited the wrong policy.
  • approval_id, approver, approved_arguments_digest: for calls that required human approval, these fields prove who approved and that the approval was bound to the exact arguments via digest. An approval for arguments with digest abc123 must not cover a call with arguments digest def456. The approval must be recorded outside the agent, in a store the agent cannot write to.
  • Why post-hoc logging does not suffice: if the agent logs the call after execution, a compromised agent can execute any call and then either log it with a false verdict or skip logging it entirely. The decision must block the call if policy says no, which requires the decision to happen before execution. For the design rationale, see Fail-Closed Authorization for AI Agents.

Verification: an auditor picks a sampled record, checks that verdict, policy_version, and policy_sha256 are present, retrieves the policy file at the recorded version, hashes it, and confirms the digest matches. They check that the policy rules in that file would produce the recorded verdict for a call with the recorded tool_name, workload_identity, and arguments_digest. If approval was required, they verify that the approval_id exists in the approval log and that its approved_arguments_digest matches the arguments_digest in the audit record. The Agent Security Contract verification tool performs this check.

3. Tamper-evident logging: the evidence bundle you hand an auditor

The auditor needs a concrete set of files or records for a sampled tool call, and a procedure to verify them offline without access to your production systems.

What to provide:

  • The audit record itself, in JSON or structured format, with all fields from the table in the "The record: one entry per tool call" section.
  • The policy file at the version cited by policy_sha256, retrieved from the repository at commit_sha.
  • For approval-gated calls, the approval record with approval_id, approver, timestamp, and approved_arguments_digest.
  • For Agent Security Contract evidence envelopes, the envelope JSON and the policy file. ASC envelopes carry an unkeyed envelope_sha256 integrity digest (hash-checked, not cryptographically signed); asc verify --policy checks that the digest matches and that the decision is consistent with the policy rules.
  • For optional JWS-signed decision tokens (as used by AI Runtime Platform or other signing gates), the signed token, the JWKS URL or public key, and the expected audience.
  • Correlation artifacts: OpenTelemetry trace exports that include the trace_id and span_id from the record, showing the call in context. MCP session logs with mcp_session_id and jsonrpc_request_id, if available.
  • Chain integrity proof: if records are hash-chained or stored in batches with a batch digest, provide the chain or batch metadata that includes the sampled record. The auditor recomputes the chain and verifies the record was not removed.

Offline verification steps:

  1. Hash the policy file. Confirm it matches policy_sha256 in the record.
  2. If the record is an ASC evidence envelope with envelope_sha256, run asc verify --policy <policy-file> <envelope-file> to check the unkeyed integrity digest and confirm the decision matches the policy. If the record is a JWS-signed decision token, verify the signature against the JWKS and check the audience claim.
  3. Recompute arguments_digest from the redacted arguments if full arguments were provided separately. Confirm it matches the digest in the record.
  4. If approval was required, confirm approved_arguments_digest in the approval log matches arguments_digest in the audit record. Verify the approver identity and that approval occurred before the timestamp of the tool call.
  5. Check the trace_id in the OTel export. Confirm the execute_tool span exists, its timestamps bound the call, and the span outcome matches the record's outcome.
  6. For hash-chained records, recompute the chain from the first record to the sampled record and verify the chain digest. A mismatch means a record was altered or removed.

These steps do not require access to the cluster or to production services. They can be performed on copies of files and exported logs. That offline verifiability is what makes the trail auditable.

Agent Security Contract for auditors and compliance

The Agent Security Contract (ASC) is a deny-by-default, pre-execution authorization gate for AI agent and MCP tool calls. ASC policies pin a SHA-256 digest of the approved tool catalog, declare per-agent tool allowlists with argument constraints, mark high-impact tools that require out-of-band approval, and bound call rates. Each decision (ALLOW, BLOCK, REQUIRE_APPROVAL) is emitted as an integrity-checked JSON evidence envelope. Every error path resolves to BLOCK.

For compliance purposes, ASC provides verifiable evidence that tool calls were evaluated against a known policy before execution. The policy digest binds each decision to the exact ruleset in force at that moment, and the evidence envelope structure makes post-hoc verification possible: given an envelope and the corresponding policy file, asc verify can confirm that the decision matches the rules and that the envelope has not been tampered with.

The research preprint documents the full evaluation methodology, including results on the author-constructed corpus and the held-out AgentDojo replay. The agent security hub collects the related MCP security checklist, OWASP Agentic Top 10 mappings, and audit trail design in one place.

Every call becomes an immutable, chainable record. Call Append-only Chain
Every call becomes an immutable, chainable record.

Checklist

For the risk side of the same design, see OWASP Top 10 for Agentic Applications mapped to Kubernetes controls. For the telemetry side, see OpenTelemetry for LLM observability.

References

Related

Cases

Related cases.

Case 27 · Flagship

Agent Security Contract

  • CLI
  • Action
  • Policy

Agent and MCP stacks expand the attack surface beyond prompt text: tool misuse, poisoned tool descriptions, argument injection, and unapproved high-impact actions run without a pre-execution gate

0 false-ALLOW · 0 false-BLOCK on this corpus

Case 21

Cost and Token Observability

  • Meter
  • Owner
  • Budget

AI and cloud costs can grow quietly when usage is disconnected from teams, services, and deployment changes

Token spend visible before finance week

Case 19 · Flagship

AI Runtime Platform

  • Python
  • vLLM
  • KServe

AI workloads often start as API calls but become production systems that need identity, policy, scaling, telemetry, and clear ownership

Every model call: policy + trace + budget

Available for meaningful infrastructure conversations

Build systems that stay calm under pressure.

Available for conversations

Talk infrastructure

Book a working session

Meet ↗

Evidence first

For deep dives

Explore the systems

All cases ↗