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 performs an offline scope check at creation time by decoding the JWT's scp claim. No network call is needed — if the required scope is missing, a PermissionError is raised before the tool is ever used.

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,
) -> 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

Raises:

  • PermissionError — if the grant token doesn't contain required_scope
  • ValueError — if the grant token can't be decoded
  • 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.5.tar.gz (8.1 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.5-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grantex_crewai-0.1.5.tar.gz
  • Upload date:
  • Size: 8.1 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.5.tar.gz
Algorithm Hash digest
SHA256 1261401d8600e2d5fb5226bd64970ec5142631ae1dcfa100b01e7e9f890a0704
MD5 113aa3fa5309a003b55fcf5c8a7f7e16
BLAKE2b-256 e63b858b3d9fb8bc4e59809cd6268377a11cc28e29ad363ac4d6d701a52b6b7a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grantex_crewai-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 53e188e902f26ef807ea81140a0b772485c2a6f9a8c5f1412c4ee8b2409b0c3b
MD5 a61278ae90c19a7d4d2542d91db9ceb8
BLAKE2b-256 9f92ef5d98c35cd34917336048552ea31334cbef913fb00ebe4d947e62638a17

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