Skip to main content

grantex-crewai

CrewAI integration for the Grantex delegated authorization protocol — scope-enforced, audited agent tools.

Wrap any CrewAI tool with Grantex grant token verification so your agents can only use tools they've been authorized for, with a full audit trail.

PyPI Python License

Homepage | Docs | Sign Up Free | GitHub

Install

pip install grantex-crewai==0.1.8

You also need CrewAI installed (it's a peer dependency):

pip install crewai

Quick start

from grantex_crewai import create_grantex_tool
from pydantic import BaseModel

# Define the tool's input schema
class FetchParams(BaseModel):
    url: str

# Create a scope-enforced tool
tool = create_grantex_tool(
    name="fetch_data",
    description="Fetches data from the given URL.",
    grant_token="eyJhbGciOiJSUzI1NiIs...",  # Grantex JWT
    required_scope="data:read",
    func=lambda url: requests.get(url).text,
    args_schema=FetchParams,
)

# Use it in a CrewAI agent — if the token doesn't have
# the "data:read" scope, create_grantex_tool raises immediately

The tool verifies the grant token against JWKS at creation time and before each run, then checks the verified scp claim. If the required scope is missing, a PermissionError is raised before the wrapped function runs.

Audit logging

Wrap any Grantex tool with audit logging to record every invocation to the Grantex audit trail:

from grantex import Grantex
from grantex_crewai import create_grantex_tool, with_audit_logging

client = Grantex(api_key="YOUR_API_KEY")

tool = create_grantex_tool(
    name="send_email",
    description="Sends an email.",
    grant_token=token,
    required_scope="email:send",
    func=send_email_fn,
)

# Wrap with audit logging — every call is recorded
tool = with_audit_logging(
    tool, client,
    agent_id="ag_01HXYZ...",
    grant_id="grnt_01HXYZ...",
)

# Now use the tool in your crew
# Successful calls log status="success", failures log status="failure"

API reference

create_grantex_tool

create_grantex_tool(
    *,
    name: str,
    description: str,
    grant_token: str,
    required_scope: str,
    func: Callable[..., str],
    args_schema: type[BaseModel] | None = None,
    jwks_uri: str = "https://api.grantex.dev/.well-known/jwks.json",
    issuer: str | None = None,
    issuer_did: str | None = None,
    audience: str | None = None,
    clock_tolerance: int = 0,
) -> BaseTool

Creates a CrewAI BaseTool with Grantex scope enforcement.

Parameter Description
name Tool name (used in audit log entries)
description Human-readable description shown to the LLM
grant_token Grantex grant token (RS256 JWT)
required_scope Scope that must be present in the token's scp claim
func The function to execute when the tool is called
args_schema Optional Pydantic BaseModel describing tool inputs
jwks_uri JWKS URL used to verify the grant token
issuer, issuer_did, audience Optional JWT claim validation settings
clock_tolerance Clock tolerance in seconds for token verification

Raises:

  • PermissionError — if the grant token doesn't contain required_scope
  • ValueError — if the grant token can't be verified
  • ImportError — if crewai is not installed

with_audit_logging

with_audit_logging(
    tool: BaseTool,
    client: Grantex,
    *,
    agent_id: str,
    grant_id: str,
) -> BaseTool

Fetches the grant and agent once to validate their relationship and resolve the immutable agent DID and principal ID, then patches the tool's _run method to log complete audit entries via the Grantex client.

Parameter Description
tool A CrewAI BaseTool (from create_grantex_tool)
client A grantex.Grantex client instance
agent_id Grantex agent ID to attribute the action to
grant_id Grant ID authorizing this tool invocation

get_tool_scopes

get_tool_scopes(grant_token: str) -> list[str]

Returns the scopes embedded in a grant token. Purely offline — no network call, no signature check.

Requirements

  • Python 3.9+
  • grantex >= 0.3.12
  • crewai >= 0.28.0 (peer dependency)

Grantex Ecosystem

This package is part of the Grantex ecosystem. See also:

License

Apache 2.0

Ownership

Grantex is owned by Orchestrum Technologies LLP. Inventor and owner: Sanjeev Kumar. Ownership contact: sanjeev@orchestrum.in or mishra.sanjeev@gmail.com.

Authority hardening requires Python SDK 0.7.1 (current_authority), not just a valid JWT signature. Bind the audience and trusted human/agent identities, and check the issuer before every execution. This does not create human consent or automatically consume action decisions/spend caps. Existing offline defaults remain offline. Verify registry availability before installation. See the SDK execution authority guide.

Metadata

Release files for grantex-crewai 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grantex-crewai 0.1.8
File Size Uploaded
grantex_crewai-0.1.8.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grantex-crewai 0.1.8
File Interpreter ABI Platform
grantex_crewai-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 25.1 kB

Release files / grantex_crewai-0.1.8.tar.gz

Download URL grantex_crewai-0.1.8.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
278daad3025d18ca416ab0367107c83ec79211fa46d520397060b0eaa9c0f21c
BLAKE2b-256 checksum
How to use checksums
2f26f50d354b0a711a6be7981db88b2306cb0bef333ecd767e5a15c46cc4aa5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / grantex_crewai-0.1.8-py3-none-any.whl

Download URL grantex_crewai-0.1.8-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
faa36e908cab7b0240df607459a2735a1161f2ebbd367e76aa53e75d6b54c40f
BLAKE2b-256 checksum
How to use checksums
f162c11033e913639906b630ff9c55c7b076ee772d1ea0f0abe1204fda5cf55f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

0.1.9

2 release files

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page