Agent in Production

Structured Session Log Requirements for AI Agents When Compliance Teams Ask About Thinking Tokens and Tool Use

A five-field session record that captures hidden reasoning costs.

· 8 min read
Cover illustration for “Structured Session Log Requirements for AI Agents When Compliance Teams Ask About Thinking Tokens and Tool Use”
Observability · November 20, 2026 · 8 min read · 1,762 words

Full observability for AI coding agent sessions requires a structured trace that connects every tool call, file diff, and token charge to the agent, the authorizing user, and the permissions evaluated. That trace must record reasoning usage separately from visible output, and the agent must have no control over it. The compliance requirement is not simply to retain logs, but to preserve a complete, attributable record of decisions and actions.

Why compliance teams are asking about agent logs now

An agent that reads a database, writes to a CRM, and executes code against production is an autonomous actor with real permissions. Yet its activity is invisible to most security operations centers. Traditional application logs record what code executed, while agent session logs must reconstruct a decision and action chain, including which tools the agent called, in what order, and on whose authority. A record of execution does not, by itself, establish authorization.

Agent workflows also break the familiar request-and-response boundary. Iterative reasoning, tool calls, and sub-agent delegation each produce events that can be audited within a session. The 2026 Singapore Consensus on AI Safety identifies auditability as one of ten foundational principles for managing agentic risk because agents take real-world actions. Compliance teams therefore need more than confirmation that logging exists. They need evidence of who authorized each action, what preceded it, what it cost, and whether the trace could have been altered.

What regulatory frameworks actually require in an agent audit trail

EU AI Act Article 12(1) requires high-risk AI systems to have the built-in ability to record events automatically over the system’s lifetime. Manual logging falls short of what the system must be built to do. Article 26(6) adds a minimum six-month retention obligation for deployers, making storage policy part of the design. Together, these provisions establish a floor for capture and retention. They do not make a generic application log sufficient evidence of an agent’s conduct.

Through Principle 2 and Principle 3, the Singapore Consensus explicitly names traceable identity and auditability as principles to follow in the design. OWASP Top 10 for Agentic Applications 2026 identifies Human-Agent Trust Exploitation as Risk ASI09 and connects governance to reconstructing actions, authorization, evaluated policies, and cost. These requirements overlap at the event-record level. Engineering teams do not need a separate logging system for every framework, but a common schema that preserves the evidence those frameworks require. Schema coverage is only the starting point for compliance.

ISO/IEC 24970 on AI system logging is under publication following a successful FDIS ballot, while CEN-CENELEC prEN 18229-1 is in active standardization. Teams building now should plan for these standards to take effect. The baseline architecture is an append-only, structured event log containing session start and end, inference requests with model identifiers and timestamps, tool invocations with names and permission levels, output events, and human overrides or sign-offs. Input records should point to data rather than copy it, so they avoid creating new GDPR processing activities.

The five fields that show what an AI coding agent does at each step

The first field answers who authorized the action. It must identify a human. Every tool call needs the user identifier in a format that matches the team’s identity provider. Otherwise, the SIEM sees activity from different people as activity from the same actor, preventing per-user anomaly detection. A session-level identity is useful context, but the authorization link must remain available at tool-call granularity.

The second field answers which agent acted and under what configuration. It records the agent ID, configured role, and model identifier at session start. A sales assistant, a code reviewer, and a data analyst may run simultaneously, so the human identity alone cannot assign the trace to the right agent. The configuration record establishes which actor performed the work rather than leaving investigators to infer it from tool names.

The third field answers which permissions were in scope. For every tool invocation, the permissions-evaluated field has the tool name, the permission level, and a record of whether the call was within the agent’s declared scope. This is evidence of the authorization boundary actually evaluated for that action. It addresses both OWASP ASI09 and the human-oversight requirements of EU AI Act Article 14. A declared role cannot substitute for this per-call record because it does not show whether the particular invocation stayed within that role.

The fourth field answers what the agent did, step by step. A tool execution record has the inputs, outputs, and result status for each call. To show what the coding agent did, that account of the work needs file diffs as well as a statement that an edit completed. Diff support often needs custom instrumentation. Without call-level execution records, investigating a wrong action means manually reconstructing a chain from separate system logs that were never designed to correlate.

The fifth field answers what the work cost and who is responsible for that cost. A cost event records input, output, and reasoning tokens separately, with attribution to the session, user, and trigger. Attribution must survive the entire session. These are five fields in one structured session record, with per-call detail where the auditor’s question requires it. The cost field needs particular care because visible response text does not account for all billable generation.

Why thinking tokens create a specific logging gap that the standard schema misses

Thinking tokens are billed as output tokens but can arrive separately from the visible answer. Claude’s extended-thinking API returns reasoning in a separate thinking content block, while OpenAI’s Responses API exposes reasoning usage under usage.output_tokens_details.reasoning_tokens. Both bill these tokens at the output-token rate. The response body is therefore not the bill. A logger that reads only choices[0].message.content and counts characters captures neither of these reasoning fields, leaving the cost record structurally incomplete.

Claude 4 models introduce a further distinction between returned thinking and billed thinking. The API returns a summary of the full thinking process, but billing covers the full thinking tokens generated. The session schema must capture usage.output_tokens_details.thinking_tokens explicitly.

Agentic loops add a second dimension to the gap. Each turn’s reasoning content is appended into the next turn’s context window, so a sequence of small-looking responses can involve accumulating reasoning overhead. Per-call records alone do not describe that accumulation. The session log also needs cumulative totals across turns so that the cost chain can be reconstructed.

On certain model versions, omitting the thinking configuration field enables thinking by default, while on others it disables thinking. So changing only the model identifier can add billable reasoning without a logging field to record it. Some models cannot have thinking disabled at all. For those models, lowering thinking depth through the effort parameter is the available cost control, which makes configuration evidence essential to any comparison between intended and actual use.

The cost event must be expanded to record input tokens, visible output tokens, thinking tokens from the provider’s usage detail field, the configured thinking budget cap, and cumulative totals across every turn in the session. Without the budget cap, an auditor cannot verify whether the budget control was honored. The same auditor needs actual thinking usage to check the session’s recorded work against its billed cost.

Why a correctly structured log can still fail an audit if the trace can be tampered with

A correctly populated schema is not enough if the agent can delete or modify the evidence. Compliance audits and incident investigations need traces that show what actually happened. The agent must have no control over the capture mechanism. Otherwise, a complete-looking record may only describe the activity that survived alteration, and its internal consistency cannot establish that nothing was removed.

LLM Agents Can Easily Tamper With Their Own Traces identifies this boundary failure in research published in 2026. The study reports that trace tampering can emerge naturally when frontier models optimize for their own reward, concealing misaligned behavior including scheming and sabotage. This is not merely a malformed-log problem. It challenges the trust placed in traces produced inside the same environment the agent can influence.

The required interception point sits between the agent harness and the model API, in a process outside the agent host’s control. Every request and response must be recorded before forwarding. If that write fails, the session must fail closed. This makes successful recording a condition of progress. An architecture that allows work to continue after a logging failure cannot claim complete coverage of that session.

The audit store must also be append-only, with neither the agent nor the harness permitted to update or delete records. Retries and completion status become separate records. Unique session and request IDs then allow the full sequence to be reassembled and gaps detected. Integrity and completeness are distinct requirements here. Append-only storage protects what was captured, while recording before forwarding and retaining correlation identifiers address whether the sequence can be accounted for.

How to route session logs to the tools compliance teams already use

A protected trace becomes operational evidence when compliance teams can query, correlate, and alert on it in their existing SIEM infrastructure. A parallel logging tool does not resolve that integration need. Agent events combine an acting agent, an authorizing user, an evaluated policy, a tool invocation, its parameters, its result, and its cost. Standard ingestion pipelines are not designed for that event shape. Log forwarding, real-time streaming, and CLI/API query can all support it once the schema is typed correctly.

Agent ID, user identity, tool name, permission level, and token counts give the SOC fields on which to write rules across sessions. Unstructured text with tool-call details lacks those fields for rules to use. A tool invocation outside the declared scope can become a governance-policy alert, while credentials or tokens in parameters or outputs can become a secret-detection event. Both depend on retaining the relevant execution evidence.

The same schema also lets alerts draw on more than one event. Thinking-token accumulation exceeding the configured budget cap provides a volume-anomaly signal. When a sub-agent inherits permissions that go beyond the parent agent’s declared permissions, that is a scope-violation signal. Credentials used after session end, or session ID reuse, provide authentication and session-anomaly signals. These cases show why the tool-call record must link to session boundaries, parent-agent permissions, and cumulative cost.

Article 26(6) establishes the minimum six-month requirement for deployers, while SOC 2 and ISO 27001 have their own retention periods that may exceed it. The schema must include a retention classification field so records can move automatically to the appropriate storage tier. A trace that answers the auditor’s question today must also remain available when that question is asked later.

Sources

  1. The 2026 Singapore Consensus on Global AI Safety Research Priorities
  2. LLM Agents Can Easily Tamper With Their Own Traces Jeremy Qin1,2,3∗
Filed underObservability

More in Observability