Identity for Long-Running Agents: Delegation Tokens and a Re-Hydration Loop
Identity for long-running autonomous agents: why static keys fail, and how OBO delegation, an audit backplane and a re-hydration loop work on serverless.
This article is published in English.
Enterprise AI is moving from passive chat interfaces to autonomous agents that carry out transactions. With that move comes an identity problem, and it has little to do with how well a model reasons. The trouble is who the model is when it acts.
Organizations that hand language models static API keys, rotated keys or ordinary service accounts are taking on a serious and growing security risk. An agent is not like conventional software. It acts on outside services by itself, and its behavior is flexible and non-deterministic, adapting as it goes.
Three questions follow. Why does traditional identity and access management fall short in the agentic era? Why do designs that suit simple chatbots collapse under long-running autonomous agents and swarms? And what does a re-hydration loop look like, one that lets stateful agents run safely on ephemeral serverless compute?
Why an agent needs an identity of its own
Web and mobile clients work from structured, unambiguous input, so what they do is a clear and auditable expression of the user's intent. Agents read unstructured data and assemble their own execution graphs. The route an LLM and its harness take toward a goal is probabilistic, and that randomness is what makes auditing painful.
Today agents frequently impersonate users in ways that outside services cannot see, which leaves accountability gaps. If an agent hallucinates a network automation script while holding broad administrative credentials, the damage can be catastrophic, and a few real incidents have already shown it.
The fix is a shift from implicit impersonation to explicit delegation. Delegation relies on on-behalf-of (OBO) flows in which the agent shows what it has been authorized to do while staying identifiable as a separate entity from the user it represents. The agent needs its own cryptographically verifiable identity, both so that actions cannot later be denied and so that capability limits can be enforced.
An analogy helps. Implicit impersonation resembles lending a senior engineer's personal badge to a junior contractor who has to restart a server. The security system sees only the engineer. If the contractor panics and shuts down the primary billing database, the audit trail says the engineer did it, and nothing proves anyone else was present. Agents are treated exactly like this today: sweeping system API keys are placed in their environment. The model does the reasoning but acts with the user's admin privileges. If it hallucinates a destructive DROP TABLE, the command runs with no least-privilege restriction, and the consequences attach to the human.
Explicit delegation is the contractor going to the security desk and getting a temporary badge of their own. The badge names the holder as Contractor X and states that Engineer Y has approved entry to Rack 4 alone, for one hour. That sets a boundary in both space and time. A swipe at Rack 5 earns a red light. When an audit comes, the log does not merely say Engineer Y was present. It records that Contractor X, acting on behalf of Engineer Y, accessed Rack 4.
In a cloud-native stack, the JWT plays the part of that visitor badge. A sub claim identifying the human is not enough. The token should also carry an act claim naming the specific agent instance. That proof limits the agent to the scope that was delegated, and every action it takes is recorded as a machine working on someone's behalf.
The usual pattern for first-generation agents
Early agent security was fairly simple. OAuth 2.1 frameworks used with agents work well inside a single trust domain when agent operations are synchronous.
In the standard pattern, an employee talks to a chatbot that must query an internal tool. The agent is bound to the Model Context Protocol (MCP), authenticates through the enterprise identity provider (IdP), receives a short-lived JSON Web Token and makes its tool call.
That works because the operation is synchronous and brief. The agent starts, collects context, uses the token to read from the database and answers the user before the token lapses.
Where short-lived and long-running agents part ways
The model fails as autonomy scales. A stateless RAG chatbot and an asynchronous agent-to-agent (A2A) swarm are architecturally far apart.
Take a threat-hunting setup. At 2:00 AM a severity-1 alert reports a DNS rebinding attack. An analyst launches a swarm to analyze 48 hours of VPC flow logs, compare them with live threat feeds and isolate compromised endpoints. That is not a chat request. It is a multi-step execution graph that could run for minutes or hours.
The identity paradox on ephemeral compute
Running such agents on serverless infrastructure like Google Cloud Run exposes a paradox. Identity models built on short-lived, session-bound access tokens do not fit long-running asynchronous work. Strict zero trust would call for 15-minute OBO tokens, but a token like that will expire in the middle of the agent's reasoning graph. The MCP server then returns 401 Unauthorized, the container crashes, and hours of accumulated reasoning context are lost.
Developers often reach for a bad workaround: placing long-lived refresh tokens or static API keys inside the agent's sandbox. Giving a non-deterministic model a persistent, highly privileged token that renews itself forever wrecks least privilege. If the agent hallucinates or falls to prompt injection, it has been handed a credential nobody can stop.
A durable identity and a re-hydration loop
The better course is to stop resisting the ephemeral nature of cloud compute and to separate the agent's cognitive state from the machine that runs it.
The agent needs a durable, delegated identity that is a first-class object in the IAM system, distinct from the user who started it, so that it can authenticate on its own over long periods. That identity is paired with a temporal memory design called the Sense and Act (SnAC) pattern, which in effect externalizes the agent's hippocampus.
The zero-trust SnAC design
Four isolated components make up the architecture. Together they describe an ecosystem that runs autonomous agents safely without granting permanent admin keys. A human first delegates authority through an identity control plane, which issues a short-lived token to an agent inside an isolated compute sandbox. Every action the agent attempts is intercepted and evaluated by the policy-enforcing SnAC IAM mesh. Meanwhile its ongoing thought process and execution state stream into a temporal auditing backplane built on Kafka and ClickHouse. If the token runs out mid-task, or the agent attempts a high-risk action that needs out-of-band human approval by mobile push, the backplane pauses the agent's state. A background orchestrator then checks permissions and re-hydrates a fresh container so work resumes smoothly.
- Identity control plane (SCIM and IdP). The System for Cross-domain Identity Management schema is extended so that an agent counts as a non-human employee. The IdP keeps the durable delegation from the human but mints only short-lived OBO tokens for the sandbox.
- Compute isolation layer (Cloud Run or WebAssembly). The agent runs inside a tight, ephemeral serverless boundary and never holds persistent secrets.
- Temporal auditing backplane (Kafka into ClickHouse). While the agent works through its graph, each thought, reasoning trace and action streams as change data capture through Kafka into ClickHouse. This gives sub-second temporal state and avoids the read amplification wall.
- MCP gateway (policy enforcement point). The MCP server stands between the compute layer and external tools, validating the short-lived tokens dynamically and intercepting requests for capabilities.
How re-hydration runs
An expired token in mid-run is treated as an expected lifecycle event, not as a fatal error.
Phase 1: execution and suspension
- The agent runs in Cloud Run and uses a fixed-lifetime token, say 15 minutes, to talk to the MCP gateway.
- It streams its context continuously to ClickHouse through Kafka.
- The token expires and the gateway returns 401 Unauthorized.
- The agent catches the exception, sends a final STATE_SUSPENDED marker to Kafka containing its exact position in the execution graph, and shuts the container down cleanly.
Phase 2: verification and re-hydration
- A secure background orchestrator sees the STATE_SUSPENDED event in ClickHouse.
- It asks the IdP whether the human's original durable delegation is still in force.
- If it is, the identity plane mints a fresh 15-minute token.
- The orchestrator starts a new Cloud Run container, passes it the fresh token and tells the agent to load its previous cognitive state from ClickHouse. The agent resumes exactly where it stopped.
// Inside the Ephemeral Agent Worker
try {
const result = await mcpClient.executeTool(action.tool, action.params);
this.state = updateState(this.state, result);
await flushStateToKafka('STATE_ACTIVE', this.state);
} catch (error: any) {
if (error.statusCode === 401) {
console.log(`[AUTH_BOUNDARY] Token Expired. Halting execution.`);
// Safely persist execution pointer before container death
await flushStateToKafka('STATE_SUSPENDED', this.state);
// Graceful exit. Orchestrator will re-hydrate.
process.exit(0);
}
}
Escalating a swarm with CIBA
The design also handles one of the hardest practical cases, a human-in-the-loop bottleneck during high-stakes threat hunting.
Back to the swarm isolating the DNS rebinding attack. Halfway through, the triage agent identifies a compromised node and hands the job of quarantining it to a remediation sub-agent. Quarantine is a high-consequence capability, and the MCP gateway sees that the sub-agent's token lacks that scope.
Rather than fail, the system uses Client-Initiated Backchannel Authentication (CIBA). The agent sends a CIBA request to the IdP, writes its state to ClickHouse as STATE_SUSPENDED and terminates.
CIBA lets an agent ask the right human decision-maker for secure authorization out of band. The on-call engineer gets a push notification on a phone with the exact context and approves the escalation. The authorization server then triggers the re-hydration loop, and this time the new token includes a cryptographically verified scope to remove the firewall rule.
Treating identity as a dynamic, re-hydratable state instead of a static credential dissolves the supposed choice between security and autonomy. Self-contained data agents can run large, multi-day workloads across distributed systems while staying within the unforgiving rules of cloud-native infrastructure.
A return to distributed systems basics
A common shortcut is to paste a standing admin token into a Python script, put an LLM around it and name the result an agent. It is the quickest way to get a prototype going. Once such systems move from internal demos to production work on real infrastructure, though, the shortcut becomes a serious liability. Static, sweeping credentials should not keep going to non-deterministic models in the hope that nothing goes wrong.
Re-hydration is more than a clever way around 15-minute expirations. It reflects the way stateful systems really have to be assembled when the platform underneath keeps no state. Poking holes in IAM policy or stretching token lifetimes pushes against what serverless compute is, and this design accepts that nature instead.
Memory sits safely in ClickHouse, execution lives in short-lived Cloud Run containers, and explicit delegation arrives through on-behalf-of tokens. That is a clear separation of concerns. It accepts a practical truth: nobody can guarantee what an LLM will decide to do next. Standard IAM guardrails plus out-of-band approvals such as CIBA do guarantee what the system will allow it to execute. The boundaries become explicit and auditable, and they follow the principle of least privilege.