Stop Giving Your AI Agents API Keys - Kim Maida, Keycard & Mason Egger, Temporal
Loading slides…
Read the talk
Stop Giving Your AI Agents API Keys: Identity and Durable Execution for Expense Desk
Kim Maida uses scoped tokens to show who filed a $30 expense and why the agent could approve it. Mason Egger then kills a worker after a ledger debit and shows how Temporal finishes settlement without repeating the debit or storing the access token in workflow history.
From a talk by Kim Maida and Mason Egger
At a glance
Ideas worth remembering
Put token issuance in the tool dispatch path, where the runtime knows the proposed operation and its target. Exchange again when the MCP server needs a credential addressed to the ledger.
Register both roles of an application that receives sign-in tokens and requests downstream access. Explicitly associate the resource with its providing application so Keycard will accept the exchange.
Verify autonomous operation separately from human delegation. With no subject token, the client credentials grant should identify the registered agent when you ask Expense Desk which account is active.
Record the verified filer and reviewer on their respective expense events. A name supplied in a memo cannot establish delegated authority or enforce a self-review rule.
To trace a delegated call, inspect the requester, subject and target resource at each exchange. Match the session number across hops when many agents share one MCP server.
Test recovery between observable steps. Stop the worker after the debit completion is recorded, verify that result while the worker is down, then restart and check settlement.
Inspect the history for the exact workflow ID you exercised. Fetch credentials at activity execution time, and use payload encryption for sensitive results that must survive replay.
An expense service needs to know who exercised its permissions
Kim Maida of Keycard and Mason Egger, a solutions architect at Temporal, introduce two responsibilities of an agent runtime. Maida works on the identity and access an agent needs while it runs. Egger works on durable execution for applications, including agents. Maida takes the first part of the workshop, which starts with a functioning expense application and changes how it gets permission to do its work. Participants can use the supplied sandbox and join Keycard during the exercise. Registration for a personal account afterward is separate.
Consider what an expense service learns when an agent presents an API key. It can grant the operations attached to the key, but possession alone identifies neither the particular agent making the request nor the person who asked it to act. The agent can exercise every permission the key carries, even if the current request needs only one. Requiring a person to click Approve leaves the attribution problem intact if the agent still submits the approval with that key. People can also make mistakes, and some agents need to work autonomously. Expense Desk will need a way to represent both delegated human authority and the agent’s own authority.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A user’s sign-in establishes whose access can be delegated
Maida introduces Token Exchange, an open standard dating to 2020 that extends OAuth 2. To follow a human identity through an execution, start at sign-in. An authorization server verifies the user’s identity and issues tokens. Google, Okta and Auth0 are examples of identity providers that offer authorization servers. Logging in establishes who is present. The subsequent consent step establishes which portion of that person’s access the agent may exercise.
The user consents to delegate a subset of their permissions, expressed as scopes. This is the first opportunity to narrow access, before the agent has even received a prompt. The authorization server issues a token identifying the user and their level of access. Later, when the application presents that token in an exchange, it serves as the subject token. The subject is the person on whose behalf the application wants to act. The application will supply a separate means of identifying itself, so a downstream authorization decision can account for both parties.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Follow a prompt from the LangChain loop to the expense ledger
Expense Desk is the runtime, the process that runs the agent loop and executes calls. Inside the custom application, a LangChain agent calls an LLM. An expense Model Context Protocol (MCP) server exposes a defined set of tools and connects them to a ledger API. The ledger API in turn connects to the database that stores expenses. Within this arrangement the MCP client has a specific job: take the tool calls the model proposes and dispatch them to the MCP server.
A user submits a prompt to Expense Desk. The runtime calls the model, which proposes a tool call. The MCP client dispatches it, the MCP server executes the tool, and the tool calls the ledger API. The result travels back through the server and client to the runtime. Expense Desk calls the model again with the result. The model can propose another call, sending the application around the loop again, or return an answer to the user. This order matters for authorization. By the time a proposal reaches the client, the application knows which operation it needs permission to perform.
Implementing the exchange requires an OAuth client capable of executing code. Maida describes three places it could live. A gateway could perform the exchange between an MCP client and a third-party MCP server. A custom agent application could perform it inside its own runtime. A CLI wrapper could add the exchange around an off-the-shelf coding agent. Expense Desk takes the second approach for access to the expense MCP server. That server also supports exchange, giving it a way to ask for access at the next boundary, the ledger API.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Mint one credential for the MCP call and another for the ledger
In the delegated path, the prompt and subject token arrive at Expense Desk together. Once the model proposes a tool call, the application authenticates to Keycard’s security token service, a specialized authorization server. It can establish its own identity with client credentials or a workload identity. It also presents the user’s subject token and asks for access to the expense MCP server for the particular tool call the model proposed.
Keycard can now evaluate the requesting agent, the user it represents and the extent of the user’s delegation alongside the target resource and requested access. A user’s permission to use Expense Desk therefore does not by itself settle whether to issue this next credential. The delegation chain and the operation requested at this resource must fit policy. If they do, Keycard issues an access token addressed to the expense MCP server. Maida says it typically expires within minutes and instructs participants to keep it out of storage.
The Expense Desk MCP client presents the issued token as a bearer credential with the tool call. The MCP server validates it and uses it to authorize the operation. Executing the tool now requires the server to call a different resource. For this second hop, the MCP server becomes the requester. It asks Keycard to exchange the token it received from Expense Desk for a token that grants the access this operation needs at the ledger API.
Keycard evaluates the second request against policy, then issues the ledger credential if permitted. The MCP server calls the API, the API validates the token, and the server discards it when the call finishes. The API result flows back to the model through the normal agent loop. If the model proposes another tool call, the runtime requests access for that call. This places credential issuance at the point of use on each hop, even when a single user prompt produces several operations.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Run the API-key version and inspect a $75 filing
Start the workshop sandbox and allow a minute or two for setup. Participants work in one pre-provisioned Keycard organization, so they can see one another’s work. Each runs a separate Expense Desk agent against the same MCP server. The initial application requires no login. Each agent uses an API key, and the desk cannot reliably tell whether participants use a common key or different ones. Later configuration requires Keycard administrator access, which the workshop team grants as participants appear in the organization’s user list.
The desk supports a familiar sequence. Someone files an expense, a reviewer approves or rejects it, and an approved expense can proceed to payout. The workshop makes no actual payments. Every interaction with the desk goes through the agent. Maida asks hers to submit $75 for workshop snacks. The expense appears as pending. Its activity entry says that an API key granted access to create it. There is no user identity attached to the filing, and the agent has yet to acquire an identity of its own.
Maida refreshes the desk, picks another participant’s expense and clicks Approve. The button sends an approval prompt to her agent, which successfully approves the expense. Looking at the entry afterward, she can see that a key authorized creation. She knows who just clicked the button because she did it herself, but a reader of the record cannot identify the filer or the approver. This gives the group a baseline they can reproduce before changing any credentials.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Register Expense Desk as both a token requester and a recipient
The first implementation goal is to let the agent act on its own behalf. Follow the invitation in the workshop instructions and log in with GitHub to join Keycard. Check for Workshop AIE NYC in the upper left of the console to confirm the organization. Participants may encounter consent prompts as they join. This login gets Maida into the console where she configures the agent. A user signing into Expense Desk itself will be a separate event.
In Applications, create an application registration for the agent. An application is a registration for something that can request tokens. Maida names hers as an agent app and incorporates her GitHub handle so she can find it among the other participants’ registrations. Give it a unique identifier, select implicit consent and obtain the redirect URL by running the supplied instruction in the sandbox terminal. Copy that instance-specific URL into the registration. It tells the sign-in flow where to return the user after login. Then choose Create application.
Expense Desk will also receive a user’s sign-in token. In Keycard, a resource is a registered target to which a token can be addressed. The same running component can hold both roles. Open Resources, add an agent resource, and give it a recognizable name and identifier using the same personal naming convention. Set its credential provider to the zone provider. This makes Keycard responsible for handling token exchange and issuing tokens for this resource.
In the resource configuration, select the agent application just created as the application that provides the resource, then save. This association has an operational consequence. It tells Keycard that this particular application can exchange sign-in tokens addressed to this particular resource. Similar names in the two registration lists do not establish that relationship. If the provider association is omitted, Keycard rejects the exchange requests.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Connect four dependencies and configure the sandbox’s client credentials
Return to the agent’s application registration and open Dependencies. Add the agent resource just created for the application’s exchange flow, then add the expense MCP server as the downstream resource the agent needs to call. The workshop has already configured that MCP resource for the entire group. Participants select the shared entry here, even though each participant has a distinct agent application.
Select two more dependencies before choosing Connect. The LLM API gives the agent access to the model provider, whose API key the workshop has already placed in Keycard’s vault. This keeps that provider secret off the agent’s disk. The user info endpoint supplies identity information about the logged-in user. These entries serve different parts of the loop: the model proposes work, the MCP server exposes the expense tools, and the user info endpoint can identify the person using the desk.
The application registration still needs a way to authenticate its requests. Choose Add Credential, then Client ID & Secret. In the sandbox editor, open the environment file in the agent folder and paste the client ID and client secret. These credentials identify the agent application to Keycard. The LLM provider’s key serves a different purpose and remains in the vault. Also set the agent resource identifier to the value used in the resource registration, including the participant-specific portion, and wait for the editor to report that the changes are saved.
Maida uses a client secret in the file because this is a local sandbox. For a production deployment she suggests workload identity. She also describes Keycard’s CLI as a way to populate secrets dynamically without requiring them on disk. At this stage the console knows the application, the resource it provides and its dependencies. The running Expense Desk code still has to request the credentials at the right time.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Wire the MCP toolset to token issuance and run as the agent
Inspect the agent authentication code in the agent folder, then open the corresponding file under the authenticated checkpoint for exercise two. Each lesson provides the code for its completed state, so the comparison isolates what changes in the runtime. In the starting version there is no authenticated MCP access. In the checkpoint, the MCP toolset receives Keycard zone token authentication from the Keycard SDK. Attaching authentication here makes the toolset request a scoped token each time it dispatches an individual call to the expense MCP server.
Next, inspect the mint function in the Keycard file. This is where the request to issue a token is made. The function handles a case the delegated walkthrough deliberately set aside: Expense Desk may be running without a signed-in user. In that case it has no user subject token to present. It uses a client credentials grant, authenticating with the application’s configured client ID and secret. The resulting authority belongs to the agent itself. This is the path the group can test immediately, before adding human sign-in to the desk.
In the Terminal tab, activate checkpoint two and restart the services so Expense Desk loads the updated code. Back in the application, choose Continue as the agent. Maida asks which account is active and how much it can approve on someone else’s expense. The desk identifies the Expense Desk agent whose client ID and secret she configured and reports an approval limit of about $50.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A $75 claim filed on Kim’s behalf has only one verified actor
Maida asks the agent to file a $75 expense for workshop swag on her behalf. The submission succeeds. When she opens the expense, the memo says it was filed on behalf of Kim, while the activity record identifies her Expense Desk agent as the filer.
The agent got the name for the memo from the request itself. Maida has yet to sign in, so the application has no evidence connecting the person who typed the request to Kim. It can establish which agent filed the claim because that agent presented its own credential. This also illustrates the difference between filing and approving. The agent can submit a $75 claim even though that amount exceeds its authority to approve a purchase on its own.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Follow the agent’s credential from the MCP server to the ledger
To see how the agent reached the expense service, Maida opens Applications in Keycard and inspects the activity against her application. Several resources appear in the log. She filters for calls to the expense MCP resource and narrows the time range to the last hour. An issued-credential entry records a client credentials grant. The application itself was the actor that obtained access to the expense MCP server.
The MCP server has two jobs, which explains its multiple registrations in Keycard. From the agent’s perspective, the server is a resource that receives a token when the agent makes a tool call. To carry out that call, the server needs access to a second resource, the ledger API. At that point the server becomes the requesting application. Its actor registration lets it exchange the incoming token for a credential to call the ledger.
Maida switches to the preregistered expense MCP actor and filters its activity by calls to the ledger API. Everyone in the workshop uses this MCP server, so its activity includes other participants’ requests. She opens an exchange to show how to read the delegation chain. The server made the request, the agent application was the identity on whose behalf it acted, and the ledger API was the resource it accessed. Those are three separate fields of interest even for a filing with no human identity attached.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Sign in a human while preserving the agent’s own authority
For the next filing, Maida wants the record to preserve two facts together. A particular agent performed the operation, and a particular human delegated permission for it. Simply attributing every action to Kim would obscure the agent’s involvement. It would also make it hard to distinguish work the agent did using Kim’s permissions from a decision it was authorized to make independently.
The sandbox embeds Expense Desk in an iframe that cannot handle external authentication. Maida opens the desk in a separate tab and clicks Sign In at the upper right. Her existing login session completes sign-in automatically. Her email now appears in the desk. She asks the agent which account she is using, a question that previously returned the agent’s identity. This time it recognizes her human account and reads a $100 approval limit associated with her identity metadata.
Maida has yet to file anything under that account. She changes the expense filter to show all expenses and finds earlier submissions still attributed to the API key, alongside examples of Expense Desk acting for other people. Signing in gives the desk a verified identity to use on subsequent requests. The old entries retain the attribution the service was able to establish when it accepted them.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A $30 office-supplies claim gets a human filer and an agent approver
Maida asks Expense Desk to submit $30 for office supplies for the team. The agent checks who she is and files the claim. This purchase also qualifies for autonomous approval, so the agent takes a second action under its own authority. A single request in the interface has produced two decisions in the expense system, each with a different identity attached.
Maida opens the expense activity. The creation entry shows her email, and the approval entry identifies the Expense Desk agent and gives its reason: “Eligible office supplies under fifty dollars with a clear business purpose.” Maida describes the agent’s authority as covering expenses under $49.99. The $30 purchase falls within both descriptions.
The two entries also clarify what signing in changed. The agent could use Maida’s identity to file her expense and still make the approval decision as itself. Anyone reviewing the purchase later can recover the filer, the approver and the stated basis for approval from the activity, even though Maida made only one request.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A $75 claim stays pending, even with a $100 reviewer limit
Maida next submits a $75 expense under her signed-in identity. It exceeds the agent’s autonomous approval limit, and the desk leaves it pending for human review. She sends the agent another instruction asking it to approve the expense by number. That request exercises a different check. The amount falls within her personal $100 limit, but she filed the expense herself. The response says she needs another reviewer to approve or reject it.
The desk can enforce this rule because it can compare the identity behind the review request with the recorded filer. Routing the request through the agent still leaves Maida as the human on whose behalf it would act. Maida points out that the earlier shared-key setup would have let her approve her own expenses or somebody else’s. She describes that earlier capability here. The action she demonstrates on this claim is the refusal.
To exercise a permitted review, she finds a different pending expense and asks the agent to reject it. Its activity shows that the Expense Desk agent created it during the earlier exercise, when the agent was acting as itself. The new rejection carries Maida’s identity. The same expense can therefore span both stages of the workshop. Its original agent attribution survives, and a later decision by an authenticated reviewer gets a separate entry.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Trace Kim’s delegated permissions across both token exchanges
The expense activity answers who filed and who reviewed. To inspect the credentials that allowed the services to act, Maida returns to Applications in Keycard, finds her Kmaida application, clears prior filters, selects her email as the actor and chooses the last hour. Opening an issued credential shows her agent application as the requester, Maida as the human on whose behalf it acted, and the expense MCP resource as the destination.
On this first hop, the agent starts with the sign-in token it acquired when Maida authenticated. It offers this to Keycard as the subject token in a token exchange request. The requested credential is for the next resource in the chain, the MCP server. The agent uses the resulting MCP token to call the server with the scopes appropriate to the tool operation. This is where the signed-in path differs from the earlier client credentials grant. There is now a human subject whose delegated permissions the exchange can carry.
For the second hop, Maida opens the expense MCP actor and selects a credential issued for access to the ledger API. The requester is now the MCP server. It presented the token it received from the agent and requested a new token for the ledger. The resource and requesting application have both changed between hops, while Maida remains the human on whose behalf the request proceeds.
To investigate one sequence on a shared server, use the session number. Maida explains that it stays consistent across the agent-to-MCP exchange and the MCP-to-ledger exchange. Filtering by resource can find many credentials for the right destination. Matching the session across the two registrations lets an investigator follow a particular sequence. She identifies the matching field here without copying session numbers or walking through a manual match.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Put the agent loop in a workflow and external calls in activities
Mason Egger of Temporal takes over with Ziggy, the plush tardigrade he carries with him, and a question about deploying the expense agent. A service can identify every participant correctly and still lose its place halfway through a task. An agent loop calls tools and external services in succession. Once a process fails, the application needs some way to determine which calls completed, what they returned and which operation should run next.
Egger introduces Temporal as a durable execution framework. His mental model for its Python interface is a parent function and its child calls. The parent is a workflow, which describes the sequence or loop. Each run is a separate workflow execution. An external operation such as a tool call is an activity. Activities give the workflow places to apply retry behavior when a dependency fails and results from which it can reconstruct progress after an interruption. An activity implementation looks like ordinary Python. Egger points to an asynchronous function, async def assess, as an example.
The concrete workflow he will interrupt is settlement. It specifies a retry policy, executes a debit against the ledger, waits on a timer, then executes a second activity to mark the expense settled. The timer stands in for time a human might take to review something. It also creates a useful interval for the experiment. Once the debit has completed and before settlement finishes, there is already a ledger operation whose result a replacement worker needs to respect.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Give the activity a credential when the worker executes it
Egger draws attention to the first decorator above an activity, which declares the resource for which it needs a grant. Keycard implemented the corresponding behavior using a Temporal interceptor. Egger describes an interceptor as a hook at a particular point in execution. When the worker executes the activity, that hook obtains identity and permission from Keycard so the activity can authenticate to its resource.
This gives the deployment a choice about the identity used for work. Individual workers can have distinct identities, or a fleet can use an identity assigned to the fleet. The choice determines what the operator can identify and scope when those workers request access. For the workshop, the worker identity, Temporal application and environment configuration are already set up. Egger proceeds directly to starting a worker.
Temporal separates the service that maintains execution state from the processes that perform the work. Egger suggests thinking of a fleet of workers as pods or processes within a pod. He starts one worker, and the worker tab reports PID 572. That process is now available to execute work. The separate Temporal service will still have the execution record if PID 572 disappears.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Kill PID 572 after the debit and inspect what survives
From the client tab, Egger invokes a settlement and gets a workflow ID. He switches back to the worker tab to see the application’s execution log, including credential minting for the call, then refreshes the Temporal web UI to find the running workflow. These views serve different purposes. The client identifies the execution he requested, the worker shows what its process is doing, and the service holds the history he will inspect after that process dies.
With the debit complete, Egger kills the worker cold. Back in the Temporal UI, he can still inspect the retry policy, the completed activity task and the debit’s stored output. He reads the debited value as 4,200 without specifying a unit. While the worker is down, a workflow task times out. That timeout and the completed debit are both visible. The service has evidence of the successful ledger operation even though there is currently no worker to advance settlement.
Egger restarts the worker. Temporal reconstructs the workflow’s state by replaying its progress using the recorded responses. When the workflow reaches the completed debit, it already has the result. The worker can proceed to mark the expense settled without sending a second debit. The timing is important to this demonstration. The service had recorded completion before Egger stopped the process. That recorded result is what replay can reuse.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Recover a long agent run without buying its answers again
Egger asks the audience to consider losing a worker twelve steps into an agent loop. Starting over can mean paying again for model responses the application already obtained. Recording progress in an application database is one possible design, but the developer then owns the logic to reconstruct the loop and determine what to retry. In Temporal, a completed model activity’s recorded response can serve the same purpose as the debit result in the settlement example.
The distinction is between waiting for an unavailable dependency and losing completed work. Egger gives an LLM provider outage and the loss of compute in an AWS region as examples. Execution can continue when the needed resources return. Whether a user notices depends on timing. In his hypothetical, a client already expects to wait a minute for approval. If the worker returns within five seconds of failing during that interval, the interruption might pass unnoticed. Those times illustrate the user experience. The observed failure in the workshop was the deliberate worker shutdown.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Inspect the recovered run for JWTs, then decide what to encrypt
The durable history raises a security question. If the next worker can recover the output of each activity, what else did the service retain? Egger goes to run a Python inspection script and has to retrieve the correct workflow ID from the client tab first. With that ID, the script reports that it found no JWT material in the event history for the settlement he just ran.
Egger opens the activity results to show how much business data is nevertheless present. The debit result is readable, and the second activity, Mark Settled, has a recorded result as well. The Keycard interceptor obtains and injects a credential when the activity executes. That timing keeps the credential out of the recorded payloads while leaving the operation’s result available for replay. The script checks this property for the specific execution he recovered.
Egger describes a second mechanism for a different requirement. Some data needs to survive in history, but its owner may want it encrypted before it reaches the Temporal service. A payload encoder can apply an operator-selected encryption policy. He describes a sidecar pattern for doing this with operator-controlled keys, whether Temporal is self-hosted or used in the cloud. The settlement results on screen are plaintext. Payload encryption is an option he explains separately from the credential injection he demonstrated.
Egger closes by mentioning integrations including OpenAI, Pydantic AI and LangChain. The expense desk shows where the two systems meet in practice. Keycard can record who requested access to the ledger and under whose authority. Temporal can record that the debit completed and use its result to finish settlement. The credential used for the call can stay with the executing worker while both records retain the information their readers need.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Full transcript
Loading transcript…