Google ADK
An ADK agent that gets its token from LumoAuth, asks LumoAuth in a callback before each tool, and waits there for a person's approval.
What it shows
- The agent gets its token from LumoAuth, with its client ID and secret, when the program starts.
- One
before_tool_callbackruns before every tool and asks LumoAuth, with the Ask API, for the action of that tool. - A refusal becomes the result of the tool: the tool does not run, and the model reads the reason.
- For the tool that changes a booking, the callback asks LumoAuth for a just-in-time permission and waits for the decision of a person.
- After an approval, the tool runs, with a token that allows exactly this change in the state of the session.
Before you start
- An agent with a client ID and secret. The setup script below registers "Room booking agent", which may read bookings and nothing else.
- A person who may approve the requests of the agent, other than its owner. The setup script gives the agent to Maya Chen, so that you can approve as administrator.
- Python 3.11 or later, and a Gemini API key for the model.
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
AGENT_CLIENT_ID | The client ID of the agent "Room booking agent". The setup script prints it. |
AGENT_CLIENT_SECRET | Its client secret. The setup script prints it. |
GOOGLE_API_KEY | The Gemini API key of your Google account, for the model. |
GOOGLE_MODEL | Optional. The model. Default: gemini-2.5-flash. |
The setup script registers "Room booking agent" with the capability bookings:read, and gives it to the user Maya Chen, so that you can approve its requests. Its API key needs the scopes admin:agents:read, admin:agents:write and admin:users:write.
node frameworks/google-adk/setup.mjs
setup.mjs
// Registers the agent of this recipe, "Room booking agent", which may read
// bookings, and gives it to another person, so that you can approve its
// requests. Run it again at any time.
//
// node frameworks/google-adk/setup.mjs
//
// The API key needs the scopes admin:agents:read, admin:agents:write and
// admin:users:write.
import { randomBytes } from 'node:crypto';
import { call, ensure, printEnv } from '../../_lib/admin.mjs';
const agent = await ensure('/admin/agents', (a) => a.name === 'Room booking agent', {
name: 'Room booking agent',
description: 'Reads room bookings. It asks a person before it changes one, and it may not cancel one.',
identityType: 'client_secret',
capabilities: ['bookings:read'],
});
// LumoAuth shows a secret once, in the answer that creates it. On a second
// run the script therefore asks for a new secret, and the old one stops.
const secret =
agent.clientSecret ??
(await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;
// The owner of an agent cannot decide its requests, and the agent belongs to
// the person who created it: you. Give it to another person, so that you can
// approve in the portal.
const owner = await ensure('/admin/users', (u) => u.email === 'maya.chen@example.com', {
email: 'maya.chen@example.com',
name: 'Maya Chen',
// The recipe never signs in as this user, so nobody needs the password.
password: `${randomBytes(18).toString('base64url')}#Aa1`,
emailVerified: true,
});
await call('PATCH', `/admin/agents/${agent.agentId}`, { ownerId: owner.id });
console.log(`Agent "${agent.name}" holds bookings:read. Its owner is ${owner.email}.`);
printEnv({ AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });
Code
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. The order of the tool calls and the last line depend on the model.
- Python
"""A Google ADK agent that asks LumoAuth in a callback before each tool runs.
The agent may read room bookings. It may not cancel one, and LumoAuth tells
the model why. To change a booking it needs a person: the callback asks
LumoAuth for a just-in-time permission and waits for the decision.
cd frameworks/google-adk/python
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python agent.py
"""
import asyncio
import os
from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.adk.tools import ToolContext
from google.genai import types
from lumoauth import JITContext, LumoAuthAgent
# The agent gets its token from LumoAuth, with the client credentials grant.
# Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
lumo = LumoAuthAgent()
lumo.authenticate()
jit = JITContext(lumo)
BOOKINGS = {"BKG-6021": {"guest": "Maya Chen", "room": "Harbor 4", "date": "2026-12-03"}}
# The action that each tool asks LumoAuth for, and the tools that a person may allow.
ACTIONS = {"get_booking": "bookings:read", "cancel_booking": "bookings:cancel", "change_booking": "bookings:change"}
A_PERSON_DECIDES = {"change_booking"}
def get_booking(booking_id: str) -> dict:
"""Read one booking: the guest, the room and the date."""
return BOOKINGS.get(booking_id, {})
def cancel_booking(booking_id: str) -> dict:
"""Cancel a booking."""
return {"cancelled": booking_id}
def change_booking(booking_id: str, date: str, tool_context: ToolContext) -> dict:
"""Move a booking to another date."""
# The callback approved this call. Its token allows exactly this change:
# send it to your booking API.
token = tool_context.state.get("approval_token")
return {"changed": booking_id, "date": date}
def ask_lumoauth(tool, args: dict, tool_context: ToolContext):
"""Runs before every tool. A dict as the answer replaces the call of the tool."""
action = ACTIONS[tool.name]
answer = lumo.ask(action, args)
print(f"{tool.name}: {action} {'allowed' if answer['allowed'] else 'refused'}")
if answer["allowed"]:
return None
if tool.name not in A_PERSON_DECIDES:
# The model reads the reason and can tell the person.
return {"error": f"Refused by LumoAuth: {answer['reason']}"}
# The agent may not do this by itself. LumoAuth sends the request to the
# approvers of the agent, and the callback waits for the decision (5 minutes at most).
justification = f"Move {args['booking_id']} to {args['date']}."
print(f"waiting for a person: {justification}")
decision = jit.request_permission(
{"type": "bookings", "actions": ["change"], "identifier": args["booking_id"]}, justification=justification
)
print(f"decision: {decision['status']}")
if decision["status"] != "approved":
return {"error": f"A person did not approve: {decision['status']}."}
tool_context.state["approval_token"] = jit.get_token(decision["request_id"])
return None
agent = Agent(
name="room_bookings",
model=os.environ.get("GOOGLE_MODEL", "gemini-2.5-flash"),
instruction="You help the front desk with room bookings. If LumoAuth refuses a tool, say why.",
tools=[get_booking, cancel_booking, change_booking],
before_tool_callback=ask_lumoauth,
)
async def main() -> None:
runner = InMemoryRunner(agent=agent, app_name="room-bookings")
session = await runner.session_service.create_session(app_name="room-bookings", user_id="front-desk")
request = types.Content(role="user", parts=[types.Part(text="Show BKG-6021, move it to 2026-12-05, then cancel it.")])
# A task frames the permissions that a person grants during the run.
jit.create_task(name="Change booking BKG-6021", task_type="front-desk")
try:
async for event in runner.run_async(user_id="front-desk", session_id=session.id, new_message=request):
if event.is_final_response() and event.content and event.content.parts:
print(f"model: {event.content.parts[0].text}")
finally:
# The end of the task revokes every token that a person granted in it.
jit.complete_task()
if __name__ == "__main__":
asyncio.run(main())
google-adk>=2.15
lumoauth>=1.7.0
cd frameworks/google-adk/python
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python agent.py
Compiles. Not run against an organization. The run, the callback and the LumoAuth calls ran against an organization with a scripted stand-in for the model, and the change was approved in the portal. The run with Gemini did not happen: it needs a model API key.
Check the result
get_booking: bookings:read allowed
change_booking: bookings:change refused
waiting for a person: Move BKG-6021 to 2026-12-05.
decision: approved
cancel_booking: bookings:cancel refused
model: I moved BKG-6021 to 2026-12-05. I could not cancel it: LumoAuth refused, because the agent lacks the capability bookings:cancel.
- While the callback waits, open AI Agents, Approvals in the portal. The request "Move BKG-6021 to 2026-12-05." is pending. Approve it, and the run continues.
- Deny it instead: the callback returns "A person did not approve: denied." as the result of the tool.
- The audit log shows
agent.capability_check_deniedforbookings:cancel, andjit.permission_requestedandjit.permission_approvedfor the change.
Limits
- The callback waits for the decision for 5 minutes at most, and the run waits with it. A request that nobody decides ends as
expired. - The map of tools to actions is part of your code. A new tool needs its action in
ACTIONS, or the callback stops with an error. - To link the audit rows to the trace of the run, see Link agent actions to traces.