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

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.9

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.9
File Size Uploaded
grantex_crewai-0.1.9.tar.gz 12.6 kB Details

Built distribution (wheel)

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

Total release size: 24.5 kB

Release files / grantex_crewai-0.1.9.tar.gz

Download URL grantex_crewai-0.1.9.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
71aed99a5042170acb196eaee4540678e7e9a0a3fbb8e5ae934508482e92ae51
BLAKE2b-256 checksum
How to use checksums
685bdccc0c351c468b80f4f036822cc0b53df310ee9d4db0e28adfa88c5d06ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL grantex_crewai-0.1.9-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29f9f83c1624e292528ae000a4b2f135463c91531d6f2591622db1c0b829a69e
BLAKE2b-256 checksum
How to use checksums
618f6c90859b12b63687b9570815a51c25333544a7174f3fc9838a42604cca07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

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