draconic21
Integration · CrewAI

Use draconic21 as a CrewAI tool

CrewAI has no merged official x402 integration (a Coinbase-wallet pull request adding one, crewAI#5785, was closed unmerged). This subclasses the documented crewai.tools.BaseTool and reuses the official Python x402 client.

Prerequisites

  • A wallet on the Base network (chain id 8453) funded with a little USDC — a few dollars covers hundreds of calls at these prices.
  • An x402 v2 client library (installed per snippet below) that can sign the "exact" EVM payment scheme (EIP-3009, gasless — no ETH for gas needed on your side).
  • Your wallet's private key available to your own process/agent — never share it, never commit it, never paste it into a chat with an AI you don't fully trust with funds.
Not legal, tax, or investment advice. Payments are USDC on Base and are irreversible once settled — test with a small balance first. draconic21 never holds your funds or your private key; every dollar goes straight from your wallet to the seller's on-chain address via the x402 facilitator.

Install

pip install crewai "x402[evm,requests]"

The code

"""CrewAI tool for a draconic21 x402 paid route.

CrewAI has no merged official x402 integration (crewAIInc/crewAI PR #5785,
a CoinbaseAgenticWalletTool with x402 support, was closed unmerged). This
subclasses crewai.tools.BaseTool and reuses the official `x402` PyPI
package's `requests` session wrapper for the actual payment.

Install:
    pip install crewai "x402[evm,requests]"

Run it standalone (no crew/agent; dry run with no key -- prints the 402
challenge and stops):
    python tool.py
"""

import json
import os
from typing import Optional, Type

import requests
from crewai.tools import BaseTool
from pydantic import BaseModel, Field

ORIGIN = os.environ.get("DRACONIC21_ORIGIN", "https://draconic21-x402-api.onrender.com")


def _build_session():
    """Return a payment-aware requests.Session, or None if no wallet is set."""
    private_key = os.environ.get("BUYER_PRIVATE_KEY")
    if not private_key:
        return None
    from eth_account import Account
    from x402 import x402ClientSync
    from x402.http.clients import x402_requests
    from x402.mechanisms.evm.signers import EthAccountSigner
    from x402.mechanisms.evm.exact.register import register_exact_evm_client

    client = x402ClientSync()
    register_exact_evm_client(client, EthAccountSigner(Account.from_key(private_key)))
    return x402_requests(client)


class TreasuryFiscalSnapshotInput(BaseModel):
    """No fields required -- the route takes an empty body."""


class TreasuryFiscalSnapshotTool(BaseTool):
    name: str = "treasury_fiscal_snapshot"
    description: str = (
        "Get total U.S. public debt outstanding, recent Treasury operating cash "
        "balance, and current Treasury FX rates in one call. Paid x402 call: "
        "$0.005 USDC on Base per call."
    )
    args_schema: Type[BaseModel] = TreasuryFiscalSnapshotInput

    def _run(self) -> str:
        session = _build_session()
        if session is None:
            return (
                "No BUYER_PRIVATE_KEY configured -- this tool needs a Base wallet "
                "funded with USDC to pay the $0.005 x402 charge per call."
            )
        resp = session.post(f"{ORIGIN}/v1/treasury_fiscal_snapshot", json={}, timeout=15)
        resp.raise_for_status()
        return json.dumps(resp.json())


def _dry_run() -> None:
    resp = requests.post(f"{ORIGIN}/v1/treasury_fiscal_snapshot", json={}, timeout=15)
    print(
        "Unpaid call status:",
        resp.status_code,
        "(402 = tool would need BUYER_PRIVATE_KEY to proceed)",
    )


if __name__ == "__main__":
    _dry_run()

Add TreasuryFiscalSnapshotTool() to any Crew's tools list. Dry-run (no key) prints the payment challenge and pays nothing; set BUYER_PRIVATE_KEY to actually pay $0.005 per call.

Routes you can call this way

Every example below targets one specific route to keep the snippet runnable, but the same client works against any draconic21 x402 route. Full list and schemas: /openapi.json.

RoutePriceWhat it does
POST /v1/sanctions_screen$0.006OFAC SDN name/wallet screening
POST /v1/sanctions_delta$0.008OFAC SDN list changes since a date
POST /v1/edgar_filings$0.02Recent SEC filings by ticker/CIK
POST /v1/edgar_company_facts$0.02Key XBRL facts by ticker/CIK
POST /v1/edgar_fulltext_search$0.02Full-text search of SEC filings since 2001
POST /v1/signal_latest$0.03Daily agent-economy signal brief
POST /v1/signal_delta$0.05What changed in Signal since a date