Skip to main content

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

Project description

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

Patches the tool's _run method to log 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)

Links

Grantex Ecosystem

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

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grantex_crewai-0.1.6.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grantex_crewai-0.1.6-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file grantex_crewai-0.1.6.tar.gz.

File metadata

  • Download URL: grantex_crewai-0.1.6.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for grantex_crewai-0.1.6.tar.gz
Algorithm Hash digest
SHA256 8f1e492f31debf24a8673fbb25a11b3ffe8e418a74066cbb4be73abf8401c5f3
MD5 a765f05d039cec9abaea9f480a0fc7bd
BLAKE2b-256 c1780d370d0e64498b00525f95de6fa5d00c7bf9b7320eba9d31dd07a69e2af2

See more details on using hashes here.

File details

Details for the file grantex_crewai-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: grantex_crewai-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for grantex_crewai-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 183f6eef6689d2b603b7843479ff2aae53d56890cb9fc4ec6465dc5118313377
MD5 4b5f0c6afb34f1bfa60687d34431d6ec
BLAKE2b-256 4f7fc7db3a7312ae4f402b3b49bd83e7996e068d6f76c74e2ba581c1b7ced744

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page