Skip to content

CrewAI Adapter

The CrewAI adapter gives each agent in your crew a scoped PQSafe payment capability. For the complete integration guide including multi-agent envelope scoping, Python SDK examples, and approval gate wiring, see the CrewAI Integration Guide.

Quick reference (Python)

from pqsafe import generate_key_pair, create_spend_envelope, create_signed_envelope, execute_agent_payment
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
from datetime import datetime, timedelta
import json
# Setup at crew initialization
keys = generate_key_pair()
signed_envelope = create_signed_envelope(
create_spend_envelope(
agent_id='crewai-procurement-agent',
max_amount=500.0,
currency='USD',
allowed_rails=['airwallex'],
allowed_recipients=['vendor-a.com', 'vendor-b.com'],
valid_until=datetime.utcnow() + timedelta(hours=24),
require_approval=True,
approval_threshold=200.0,
),
keys['secret_key']
)
class PaymentInput(BaseModel):
recipient: str = Field(description="Recipient domain")
amount: float = Field(description="Amount in USD")
memo: str = Field(description="Payment memo")
class PQSafePaymentTool(BaseTool):
name: str = "pqsafe_pay"
description: str = "Execute PQSafe-authorized payment. Recipients: vendor-a.com, vendor-b.com. Max: $500 USD."
def _run(self, recipient: str, amount: float, memo: str) -> str:
result = execute_agent_payment(signed_envelope, recipient=recipient, amount=amount, memo=memo)
return json.dumps({"status": result.status, "tx_id": result.tx_id, "rail": result.rail})

Full CrewAI Integration Guide