What it does
This example demonstrates thegrantex-crewai integration by building CrewAI tools with Grantex scope enforcement:
- Register an agent and obtain a grant token via the sandbox flow
- Create scoped tools using
create_grantex_tool— each tool is bound to a specific scope (calendar:read,email:send) - Wrap tools with
with_audit_loggingto automatically log every invocation to the Grantex audit trail - Invoke tools directly (in a full CrewAI crew, the LLM would select and call these tools)
- Demonstrate scope enforcement — attempting to create a tool with
account:delete(a scope not in the grant) raises aPermissionError - Inspect the audit trail to see the logged actions
Prerequisites
- Python 3.9+
- Docker (Docker Desktop or Docker Engine with Compose)
Run
Start the local Grantex stack from the repository root:Expected output
Environment variables
| Variable | Default | Description |
|---|---|---|
GRANTEX_URL | http://localhost:3001 | Base URL of the Grantex auth service |
GRANTEX_API_KEY | sandbox-api-key-local | API key. Use a sandbox key for auto-approval |
Source code
The full source is inexamples/crewai-agent/main.py.