CrewAI
A crew in which each member is its own registered agent with its own capabilities, and a refund that waits for a person.
What it shows
- Each member of the crew signs in to LumoAuth as its own agent, with its own client ID and secret.
- The tools of a member ask LumoAuth with the identity of that member. The researcher may read the order, and LumoAuth refuses its cancellation with a reason, which the model reads.
- The refund clerk may not refund by itself. Its tool asks LumoAuth for a just-in-time permission and waits, and the crew waits with it.
- A person approves the request in LumoAuth. The tool receives a token that allows exactly this refund, and the crew goes on.
Before you start
- Two agents with a client ID and secret each. The setup script below registers "Order researcher" and "Refund clerk".
- A person who may approve the requests of the agents, other than their owner. The setup script gives both agents to Maya Chen, so that you can approve as administrator.
- Python 3.10 to 3.13: CrewAI does not install on Python 3.14. An OpenAI 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. |
RESEARCHER_CLIENT_ID | The client ID of the agent "Order researcher". The setup script prints it. |
RESEARCHER_CLIENT_SECRET | Its client secret. |
CLERK_CLIENT_ID | The client ID of the agent "Refund clerk". The setup script prints it. |
CLERK_CLIENT_SECRET | Its client secret. |
OPENAI_API_KEY | The API key of your OpenAI account, for the model. |
OPENAI_MODEL | Optional. The model. Default: gpt-5-mini. |
The setup script registers the two members of the crew as two agents, each with the capability orders:read, and gives both to the user Maya Chen, so that you can approve their requests. Its API key needs the scopes admin:agents:read, admin:agents:write and admin:users:write.
node frameworks/crewai/setup.mjs
setup.mjs
// Registers the two members of the crew as two agents, each with its own
// capabilities: "Order researcher" may read orders, and "Refund clerk" may
// read orders too. Neither may refund by itself. Run it again at any time.
//
// node frameworks/crewai/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';
// The owner of an agent cannot decide its requests, and an agent belongs to
// the person who created it: you. The agents go 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,
});
async function member(name, description, capabilities) {
const agent = await ensure('/admin/agents', (a) => a.name === name, {
name,
description,
identityType: 'client_secret',
capabilities,
});
await call('PUT', `/admin/agents/${agent.agentId}/scopes`, { scopes: capabilities });
await call('PATCH', `/admin/agents/${agent.agentId}`, { ownerId: owner.id });
// LumoAuth shows a secret once. A second run therefore makes a new secret.
const secret =
agent.clientSecret ??
(await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;
console.log(`Agent "${name}" holds: ${capabilities.join(', ')}`);
return { id: agent.agentId, secret };
}
const researcher = await member('Order researcher', 'Looks up orders for the support crew.', ['orders:read']);
const clerk = await member('Refund clerk', 'Prepares refunds. A person approves each one.', ['orders:read']);
printEnv({
RESEARCHER_CLIENT_ID: researcher.id,
RESEARCHER_CLIENT_SECRET: researcher.secret,
CLERK_CLIENT_ID: clerk.id,
CLERK_CLIENT_SECRET: clerk.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 CrewAI crew in which each member is its own agent in LumoAuth.
The researcher looks up an order with its own identity. It may not cancel
the order, and LumoAuth tells the model why. The refund clerk prepares a
refund with its own identity. The refund tool waits until a person approves
it in LumoAuth.
cd frameworks/crewai/python
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python crew.py
"""
import json
import os
from crewai import Agent, Crew, Process, Task
from crewai.tools import tool
from lumoauth import JITContext, LumoAuthAgent
# Each member signs in as itself, with its own client ID and secret.
# LUMOAUTH_URL and LUMOAUTH_ORG_ID are read from the environment.
researcher_identity = LumoAuthAgent(
client_id=os.environ["RESEARCHER_CLIENT_ID"], client_secret=os.environ["RESEARCHER_CLIENT_SECRET"]
)
clerk_identity = LumoAuthAgent(client_id=os.environ["CLERK_CLIENT_ID"], client_secret=os.environ["CLERK_CLIENT_SECRET"])
researcher_identity.authenticate()
clerk_identity.authenticate()
clerk_jit = JITContext(clerk_identity)
ORDERS = {"ORD-3318": {"customer": "Northwind Labs", "total_usd": 240, "status": "delivered damaged"}}
def refusal(identity: LumoAuthAgent, tool_name: str, action: str, **context) -> str | None:
"""Asks LumoAuth whether this member may do the action. Returns the reason of a refusal."""
answer = identity.ask(action, context)
print(f"{tool_name}: {action} {'allowed' if answer['allowed'] else 'refused'}")
return None if answer["allowed"] else answer["reason"]
@tool("Look up order")
def look_up_order(order_id: str) -> str:
"""Read one order: the customer, the total and the status."""
if reason := refusal(researcher_identity, "look_up_order", "orders:read", order=order_id):
return f"Refused by LumoAuth: {reason}"
return json.dumps(ORDERS.get(order_id, {}))
@tool("Cancel order")
def cancel_order(order_id: str) -> str:
"""Cancel an order."""
if reason := refusal(researcher_identity, "cancel_order", "orders:cancel", order=order_id):
# The model reads the reason and can tell the person.
return f"Refused by LumoAuth: {reason}"
return f"Cancelled {order_id}"
@tool("Issue refund")
def issue_refund(order_id: str, amount_usd: int) -> str:
"""Refund an amount of an order to the customer."""
if refusal(clerk_identity, "issue_refund", "refunds:issue", order=order_id, amount_usd=amount_usd):
# The clerk may not refund by itself. The tool waits here until a
# person decides in LumoAuth (5 minutes at most), and the crew waits with it.
justification = f"Refund {amount_usd} USD of {order_id} to {ORDERS[order_id]['customer']}."
print(f"waiting for a person: {justification}")
decision = clerk_jit.request_permission(
{"type": "refunds", "actions": ["issue"], "identifier": order_id}, justification=justification
)
print(f"decision: {decision['status']}")
if decision["status"] != "approved":
return f"Not refunded: the request was {decision['status']}."
# The token allows exactly this refund. Send it to your payment API.
token = clerk_jit.get_token(decision["request_id"])
return f"Refunded {amount_usd} USD of {order_id}"
llm = os.environ.get("OPENAI_MODEL", "gpt-5-mini")
researcher = Agent(
role="Order researcher",
goal="Find the facts of an order.",
backstory="You look up orders for the support team.",
tools=[look_up_order, cancel_order],
llm=llm,
)
clerk = Agent(
role="Refund clerk",
goal="Refund customers whose order arrived damaged.",
backstory="You prepare refunds. A person approves each one.",
tools=[issue_refund],
llm=llm,
)
crew = Crew(
agents=[researcher, clerk],
tasks=[
Task(
description="Look up order ORD-3318. The customer asks to cancel it: try that too.",
expected_output="The facts of the order, and whether it was cancelled.",
agent=researcher,
),
Task(
description="Refund the full total of order ORD-3318, because it arrived damaged.",
expected_output="Whether the refund went through.",
agent=clerk,
),
],
process=Process.sequential,
)
if __name__ == "__main__":
# A task frames the permissions that a person grants during the run.
clerk_jit.create_task(name="Refund damaged order ORD-3318", task_type="support")
try:
print(f"crew: {crew.kickoff()}")
finally:
# The end of the task revokes every token that a person granted in it.
clerk_jit.complete_task()
crewai>=1.15
lumoauth>=1.7.0
cd frameworks/crewai/python
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python crew.py
Compiles. Not run against an organization. The crew was built and its three tools were called directly against an organization (Python 3.13), and the refund was approved in the portal. The crew did not run with a model: it needs a model API key.
Check the result
look_up_order: orders:read allowed
cancel_order: orders:cancel refused
issue_refund: refunds:issue refused
waiting for a person: Refund 240 USD of ORD-3318 to Northwind Labs.
decision: approved
crew: The refund of 240 USD for order ORD-3318 went through.
- While the clerk waits, open AI Agents, Approvals in the portal. The request "Refund 240 USD of ORD-3318 to Northwind Labs." of "Refund clerk" is pending. Approve it, and the crew goes on.
- In the audit log, the rows of each member name that member:
agent.capability_check_deniedof "Order researcher" fororders:cancel, and the requests of "Refund clerk". - Remove
orders:readfrom "Order researcher" in the portal, and run the crew again. The tool of the researcher now returns the refusal of LumoAuth, and the capabilities of the clerk stay as they are.
Limits
- The tool waits for the decision for 5 minutes at most, and the whole crew waits with it. A request that nobody decides ends as
expired. - Each member holds its own token. A tool uses the token of the member that the tool belongs to, so give each tool to the right member.
- To link the audit rows to the trace of the run, see Link agent actions to traces.