How AI Agents Delegate Tasks During an Incident. Give each AI agent its own identity and hand work over as a tracked request with a short-lived token from OAuth token exchange, never a shared credential.
To let AI agents delegate tasks to each other during an incident, give each agent its own identity and have the requesting agent hand the work over as a tracked request, not a shared credential. The receiving agent then gets a short-lived, narrowly scoped token through OAuth 2.0 token exchange (RFC 8693), so every handoff is bounded, attributable to the agents involved and easy to revoke once the incident is over.
This post is for SREs, platform engineers and incident leads who already have AI agents in their on-call or incident workflow and now want those agents to pass work to one another safely. You probably know OAuth well enough to configure a client, so we will spend the time on the parts generic multi-agent writing tends to skip: who each agent is, what a called-in agent is allowed to do, how you see afterwards who asked whom, and how you take the access back. We use Keycloak to illustrate, because its token exchange guide documents each piece, but the pattern works with any authorization server that implements RFC 8693.
Why does delegating tasks between AI agents during an incident need its own design?
During an incident, the agent that notices a problem is rarely the one best placed to fix it. A triage agent reading alerts may need a database agent to check replication lag, or a deployment agent to roll back a release, and it needs that help within minutes. The fastest way to make that work is to let every agent use the same service account, or to let the first agent pass its own token along. Both shortcuts work on the day, but afterwards nobody can tell which agent ran which query, and the token that was passed around can do everything the first agent could.
A handoff design has to settle four things before the incident starts: the identity each agent acts under, what an agent that was called in may actually do, where the record of who asked whom is kept, and how you take the delegated access back once the incident closes. The rest of this post covers them in that order.
Give each AI agent its own identity
Give every agent with its own purpose or owner its own Keycloak client, rather than one shared service account for the whole fleet. In Keycloak, an agent can be a confidential client with a service account enabled, which is what the token exchange guide asks of an actor client in its delegation prerequisites. Our post on non-human identity for AI agents explains why one shared account fails an audit: it erases which agent did something, who owns it and what would break if you revoked it. Identical replicas of the same agent can share a client, because they share an owner and an expected behaviour.
Separate clients pay off during the incident itself. If the database agent starts behaving oddly, you can disable its client without stopping the triage agent, and its tokens name it in the azp (authorized party) claim, as the guide’s example token shows, so the logs already tell you which agent a call came from. Our guide to authenticating AI agents with Keycloak walks through the client setup.
Scope what a called-in agent may do with token exchange
Token exchange lets one party trade a token it holds for a new token meant for a different audience. RFC 8693 defines the request: the caller presents a subject_token and asks for an audience or a scope, and the authorization server decides what, if anything, to issue. In the incident case, the triage agent passes its own access token along with the request, and the database agent exchanges it for a token that only reaches the system it needs to touch.
The triage agent files a request with the incident context and a token whose audience includes the database agent (1). The database agent exchanges that token at Keycloak for the metrics API only (2), Keycloak records the exchange and returns a short-lived token without a refresh token (3), and the database agent makes one narrow call with it (4).
Keycloak’s standard token exchange (the V2 implementation) puts several useful limits on this, according to its token exchange guide:
- Only the named receiver can exchange the token. The subject token, per the guide’s additional details, “must have the requester client set as an audience in the
audclaim. Otherwise, the request would be rejected.” So the triage agent’s token needs an audience mapper that adds the database agent, and a token stolen by any other client is useless for exchange. - The receiver must prove who it is. The requesting client must be a confidential client with the Standard token exchange switch turned on, as enabling token exchange describes, so the database agent authenticates with its own credentials when it exchanges.
- The new token can be narrower. The
audienceparameter filters the audiences and client roles in the result, which the guide’s scopes and audiences section describes as “effectively used for ‘downscoping’ the token”. Ask for the one API the task needs. - No refresh token by default. Standard token exchange issues no refresh token unless you set Allow refresh token in Standard Token Exchange on the client to a value other than its default, No (additional details), so the called-in agent’s access ends when its access token expires.
The guide also notes that the scope parameter can add the requester’s optional client scopes, so keep each agent’s optional scopes to the few it really needs. Our explainer on how Keycloak token exchange works covers the request format and the common errors.
Record who acts for whom with the act claim
A plain exchange tells the metrics API which client is calling, but RFC 8693 has a precise way to say “this agent, acting for that party”. Section 1.1 separates impersonation, where A “is B” within the rights of the token, from delegation, where actions “are being taken by A representing B”. Section 4.1 defines the act claim, which “provides a means within a JWT to express that delegation has occurred and identify the acting party”.
Keycloak 26.8 supports this as a preview feature, according to its 26.8.0 release notes. The guide’s delegation section says it is a preview that “is disabled by default”, and you enable it with the token-exchange-delegation feature, which needs the parameterized-scopes feature as well. A user, such as the incident lead, consents to a specific client acting for them, their token gets a may_act claim naming that client, and the token the agent receives from the exchange carries an act claim with the agent’s service account and client ID. Our post on Keycloak 26.8 token exchange delegation for AI agents walks through the full flow and its Fine-Grained Admin Permissions V2 setup.
If agents chain requests, so that agent B calls in agent C, keep in mind what the RFC allows the chain to mean. Per section 4.1, the outermost act claim is the current actor, while “Prior actors identified by any nested act claims are informational only and are not to be considered in access control decisions.” Your APIs should therefore authorize on the subject and the current actor only, and record the earlier hops for the audit trail.
Pass the incident context with the request, not the credential
A called-in agent that starts from nothing wastes the first minutes of its work repeating the investigation. Put the context in the request itself: the incident identifier, a summary of what is happening, what the requesting agent has already checked and ruled out, and the links to the dashboards or logs it used. Keep the token separate from that text, so the context can be stored, shown to people and searched without carrying anything that grants access.
A request might look like this, with the context as plain fields and no token among them:
{
"incident": "INC-0421",
"from": "triage-agent",
"to": "database-agent",
"ask": "Check replication lag on the orders database since 14:05 UTC",
"summary": "Checkout latency rose after the 14:00 deploy; API pods are healthy",
"ruled_out": ["API pod restarts", "load balancer errors"],
"links": ["https://grafana.example.com/d/orders-db"]
}
The triage agent sends its access token separately, in the request’s authorization header, and the database agent uses it only as the subject_token of its exchange.
A tracked request also gives the receiving agent a clear question to answer and a place to put the answer. When the result is written back to the same request, the next agent or person picking up the incident reads one history, rather than piecing it together from several chat threads.
The pattern above, already wired up
Skycloak gives you a managed Keycloak with OIDC and SAML, social and enterprise identity providers, MFA and fine-grained roles configured and running. Pick your framework during onboarding and you get a working sign-in in about three minutes.
Keep an audit trail of who asked whom
Your audit trail has two halves, and you need both. The request system records the intent: which agent asked for what, for which incident and when. Keycloak records the access: its user event types include TOKEN_EXCHANGE and TOKEN_EXCHANGE_ERROR, as Keycloak’s EventType source defines them and as we describe in how Keycloak token exchange works, so you can see which client exchanged a token and for what. Keycloak’s auditing guide says that by default it “does not store or display events in the Admin Console” until you turn on Save events for the realm, and our Keycloak auditing and event logging guide shows how to save them, set their retention and forward them to your SIEM.
Join the two on the time and the client ID when you review the incident. If your resource servers also log the sub and act claims of every delegated call, you can follow a handoff from the request, through the exchange, to the exact API call it led to.
Where does a human approve or override a handoff?
Put the human checkpoint where the access is granted, not only in the chat. With Keycloak’s delegation preview, the consent screen is that checkpoint: the incident lead approves a specific agent acting for them before any delegated token exists, as the 26.8 delegation post shows. For changes with a large blast radius, such as a rollback or a failover, it also helps to require a person to approve the filed request before the receiving agent starts.
Overriding is simpler when each agent has its own client. An incident lead who disagrees with what an agent is doing can disable that agent’s client, which stops it from getting new tokens, while the other agents keep working.
How do you revoke delegated access after the incident?
Plan the close-out before the incident, because exchanged tokens do not follow the token they came from. Keycloak’s token exchange guide says “the revocation of the access-token1 will not revoke access-token2”, meaning that revoking the original token leaves the exchanged access token valid until it expires. Short access token lifespans on the agent clients are therefore your main control, and since a standard exchange issues no refresh token by default, the called-in agent cannot quietly extend its access. RFC 8693’s security considerations make a related point: limiting the token with the scope claim, “in addition to other typical constraints such as a limited token lifetime”, “is suggested to mitigate potential for such abuse.”
At close-out, work through a short list:
- Close or reassign every request filed during the incident, so no agent keeps working on a task nobody owns.
- Remove any temporary consent, audience mapper or permission you added for the incident, including Fine-Grained Admin Permissions V2 grants for delegation.
- Check the
TOKEN_EXCHANGEevents for clients you did not expect, and for error spikes that point to an agent trying to reach something it should not. - Disable or rotate the credentials of any agent client that behaved unexpectedly.
For a longer-running view of which agent can reach what, our posts on Cross-App Access (ID-JAG) for AI agents and non-human identity cover how to govern agent access beyond a single incident.
FAQ
Can AI agents share one service account if they all work on the same incident?
They can technically, but you lose the ability to tell which agent did what and to revoke one without stopping the rest. Give each agent its own client, and let identical replicas of one agent share it.
Should one agent just pass its access token to the other?
No. A token passed on as-is still carries every audience and scope of the first agent. Exchange it instead, so the receiving agent gets a token limited to the one service it needs, and so the exchange appears in Keycloak’s events.
Does Keycloak support the act claim for agent delegation?
Yes, as a preview in Keycloak 26.8 that is disabled by default. It needs the token-exchange-delegation and parameterized-scopes features, a consenting user and a Fine-Grained Admin Permissions V2 permission, as the token exchange guide describes.
Does revoking the requesting agent’s token cut off the called-in agent?
Not for access tokens. Keycloak’s guide says revoking the original access token does not revoke tokens exchanged from it, so keep agent access tokens short-lived and disable the client when you need to stop an agent at once.
Next steps
Start by creating one Keycloak client per agent, add an audience mapper so the triage agent’s token names the agent it may call in, and try a scoped token exchange between the two on a test realm. When that works, follow our Keycloak 26.8 token exchange delegation guide to add consent and the act claim. If you would rather not run the Keycloak underneath your agents yourself, Skycloak hosts and operates it for you.


