> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Context in Actions

> Access agent identity and metadata in Auth0 Actions using the `event.agent` object.

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "Beta",
    "ea": "Early Access"
  };
  const stageText = stageTextMap[stage] || "a product release stage";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>This feature is available for {linkify(`${plans} plans`, "https://auth0.com/pricing")}. </>}
            {contact && "To participate, contact " + contact + ". "}
            {terms && <>By using this feature, you agree to the applicable Free Trial terms in Okta's {linkify("Master Subscription Agreement", "https://www.okta.com/legal")}.</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>The {feature} feature is in {linkify(stageText, prsLink)}.</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="Agents as Principal" stage="ea" contact="Auth0 Support" terms="true" />

When a request involves an agent-linked client, the Actions runtime exposes an `event.agent` object. The object is absent when no agent is involved, so existing Actions code is unaffected.

## Triggers

`event.agent` is present in the following triggers:

| Trigger                | When `event.agent` is present                                                           |
| ---------------------- | --------------------------------------------------------------------------------------- |
| `credentials-exchange` | Client credentials grant where the client has `agent_id` set.                           |
| `post-login`           | Authorization code, token exchange, or device flow where the client has `agent_id` set. |

## `event.agent` object

The `event.agent` object has the following schema:

```json theme={null}
{
  "agent_id": "agt_72jbvv7LfRKYp59gtRLtkn",
  "agent_metadata": {
    "env": "prod"
  }
}
```

`event.client` is unchanged; it continues to reflect the linked OAuth client that authenticated the request.

## Example: custom claims on agent tokens

Use `event.agent` in a `credentials-exchange` Action to add agent context to access tokens:

```javascript theme={null}
exports.onExecuteCredentialsExchange = async (event, api) => {
  if (event.agent) {
    api.accessToken.setCustomClaim('agent_env', event.agent.agent_metadata?.env);
    api.accessToken.setCustomClaim('agent_id', event.agent.agent_id);
  }
};
```

To learn more about writing Actions, read [Write Your First Action](/docs/customize/actions/write-your-first-action).
