Guides

Use Unslept with CrewAI

Wrap Unslept as a CrewAI tool so a crew can pay for the data it needs.

terminal
pip install "unslept[web3]" crewai
crew.py
import os
from crewai.tools import tool
from eth_account import Account
from unslept import Unslept
from unslept.web3_chain import EthAccountSigner
from unslept.langchain_tool import pay_x402_request

unslept = Unslept(
    os.environ["UNSLEPT_AGENT_ACCOUNT"],
    signer=EthAccountSigner(Account.from_key(os.environ["UNSLEPT_SIGNER_KEY"])),
    network="robinhood-chain",
)

@tool("pay_x402_request")
def pay(url: str, max_amount_usdg: str = "1") -> str:
    """Fetch a URL, paying an x402 paywall within the agent's spending policy."""
    return pay_x402_request(unslept, url, max_amount_usdg=max_amount_usdg)

Add pay to an agent's tools. Give each crew member that spends money its own agent account if you want separate budgets and separate payment histories.