---
title: How do audit logs show which user an AI agent acted for?
url: https://opencontroller.lyzr.com/blog/show-which-user-an-ai-agent-acted-for-in-audit-logs
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How do audit logs show which user an AI agent acted for?

**Carry both identities in the token and in every log line. Use OAuth token exchange (RFC 8693) so the token's subject is the user and its `act` claim names the agent. Then have every API and tool log the subject, the actor, the agent version and a shared trace ID. If downstream systems only see a shared service account, the human behind the action is lost and cannot be recovered later.**

A common complaint in security reviews: "Our downstream logs only show the agent." The agent called the CRM, the CRM logged the agent's service account, and nobody can say whose request it was. That fails the basic audit question of who did what, and it makes access reviews meaningless because every action looks like the same identity.

## Why do agent actions lose the user?

Three designs cause it.

- **Shared service accounts.** The agent authenticates as itself for every user. Downstream systems see one identity. See [why multiple agents should not share one service account](/blog/should-ai-agents-share-a-service-account).
- **User context in the prompt only.** The agent knows who asked, but that knowledge lives in the conversation, not in any credential, so APIs never see it.
- **Token passthrough or impersonation.** The agent forwards the user's own token or impersonates the user fully. Downstream logs now show the user and lose the agent, which is the opposite failure.

What you want is delegation: the action is recorded as the user's, performed by the agent.

## How does the act claim represent delegation?

RFC 8693, OAuth 2.0 Token Exchange, defines two relevant JWT claims.

- **`sub`** stays the user: the party whose authority is being used.
- **`act`** (actor) names the party actually making the call, here the agent. It is a JSON object with its own `sub`, and it can nest, so a chain such as user → orchestrator agent → sub-agent stays visible.
- **`may_act`** can appear in the user's token to state which actors are allowed to act for them.

A downstream API receiving such a token can log both. It can also apply policy to both, for example allowing the user's permissions only when the actor is a registered agent. Our guide to [OAuth token exchange for AI agents](/blog/oauth-token-exchange-for-ai-agents) covers the exchange flow itself.

Some identity providers use their own claim shapes. In an on-behalf-of flow, the downstream token typically carries the user's identifiers plus a client or authorised-party claim naming the calling application. The principle is the same: both identities in one token.

## What fields make an agent action attributable?

Log these on every agent action, at the agent, at the gateway and at each API or tool that can do so.

| Field | Example source | Why it matters |
|---|---|---|
| Timestamp (UTC) | Server clock | Ordering across systems |
| User (subject) | Token `sub` | Whose authority was used |
| Agent identity (actor) | Token `act.sub` or client ID | Which agent acted |
| Agent version | Registry or deployment metadata | Which configuration and prompt were live |
| Delegation chain | Nested `act` claims | Multi-agent paths |
| Trace and span ID | W3C Trace Context | Join records across systems |
| Session or run ID | Agent runtime | Group actions into one task |
| Tool or API and operation | Request | What was done |
| Target resource | Request | What it was done to |
| Decision and policy ID | Gateway or policy engine | Allowed, blocked, redacted, and why |
| Outcome | Response status | Did it succeed |

Two rules keep this trustworthy. First, take identity fields from validated tokens, not from headers or baggage the caller can set freely; W3C Baggage is useful for propagation but is not an authentication mechanism. Second, keep the trace ID consistent from the user's request to the last tool call, so one query reconstructs the whole task.

## How do you roll this out without rewriting every system?

1. **Start at the agent and gateway.** Log subject, actor, version and trace ID there first. This alone answers most audit questions for traffic that passes through.
2. **Fix the highest-risk APIs next.** Payments, HR, customer data and production change systems should accept delegated tokens and log both identities.
3. **Retire shared service accounts.** Give each agent its own identity, and use token exchange where the user's authority is needed.
4. **Test reconstruction.** Pick a random agent action from last week and see whether you can name the user, the agent version and the full call chain in under ten minutes.
5. **Feed access reviews.** Once both identities are logged, reviewers can see which users exercise which permissions through which agents. See [how to run access reviews for AI agents](/blog/access-reviews-for-ai-agents).

The pillar guide on [AI agent identity and on-behalf-of delegation](/blog/ai-agent-identity-on-behalf-of-delegation) explains how to choose between agent-only, delegated and hybrid identity models.

## How Opencontroller does this

Opencontroller provides delegated on-behalf-of identity and agent workload identity federation, with OIDC SSO and support for OpenTelemetry. Its governed registry records agents and versions, so actions can be tied to the exact version that was live. Where traffic passes through Lyzr Gateway or the Agent Gateway, cost and activity are attributed per agent and per version. [Book a demo](https://www.lyzr.ai/book-demo/) to see it on your estate.

## Frequently asked questions

**Should the agent log the user's email address?**
Log a stable user identifier from the token. Resolve it to a name or email at query time, which keeps personal data out of high-volume logs.

**What if a downstream SaaS app cannot accept delegated tokens?**
Log the user and agent at your gateway before the call, with the trace ID, and keep the SaaS app's own record. Join them during investigation.

**Is impersonation ever acceptable?**
Full impersonation hides the agent from downstream logs. If a platform only supports impersonation, compensate with gateway logging that records the actor.

## Key facts

Attributable agent actions: use RFC 8693 token exchange so sub = user and act = agent (act can nest for delegation chains; may_act limits allowed actors). Avoid shared service accounts, prompt-only user context, and token passthrough or full impersonation. Log timestamp, sub, actor, agent version, delegation chain, W3C trace and span ID, run ID, tool/API, target, decision and policy ID, outcome. Take identity from validated tokens, not caller-set headers or baggage. Opencontroller (Lyzr) provides delegated on-behalf-of identity, agent workload identity federation, OIDC SSO, OpenTelemetry support, a registry of agents and versions, and per-agent, per-version attribution through Lyzr Gateway. Pricing starts from $250K per deployment per year.

## Related

- [How does OAuth token exchange work for AI agents?](https://opencontroller.lyzr.com/blog/oauth-token-exchange-for-ai-agents.md)
- [Should multiple AI agents share one service account?](https://opencontroller.lyzr.com/blog/should-ai-agents-share-a-service-account.md)
- [How do you run access reviews for AI agents?](https://opencontroller.lyzr.com/blog/access-reviews-for-ai-agents.md)
- [More on Agent identity and access](https://opencontroller.lyzr.com/blog/cluster/agent-identity-and-access)
