Integrations
Add Payments to Your CrewAI Agents
Give your CrewAI agents financial capabilities using the Wallgent Python SDK.
Coming Soon: The Wallgent Python SDK is currently in development. This guide shows the planned API so you can design your integration today. Use the REST fallback section below to get started now.
Prerequisites
- A Wallgent account and API key (get one here)
- Python 3.9+
1. Install
pip install wallgent crewai crewai-tools2. Define Wallgent Tools
CrewAI uses the @tool decorator to wrap any function as an agent tool:
from crewai.tools import tool
from wallgent import Wallgent
wg = Wallgent(api_key="wg_test_your_key_here")
@tool("Check wallet balance")
def check_balance(wallet_id: str) -> str:
"""Check the available balance of a Wallgent wallet."""
balance = wg.wallets.get_balance(wallet_id)
return f"Available: ${balance.available}, Pending: ${balance.pending}"
@tool("Send payment")
def send_payment(from_wallet: str, to_wallet: str, amount: str, description: str) -> str:
"""Send a payment between two Wallgent wallets."""
txn = wg.payments.send(
from_wallet=from_wallet,
to_wallet=to_wallet,
amount=amount,
description=description,
)
return f"Payment {txn.id} — status: {txn.state}"3. Create Agents and Crew
from crewai import Agent, Task, Crew
researcher = Agent(
role="Research Analyst",
goal="Find market data and pay for premium API access when needed",
tools=[check_balance, send_payment],
llm="gpt-4o",
)
writer = Agent(
role="Content Writer",
goal="Write reports and pay for stock images when needed",
tools=[check_balance, send_payment],
llm="gpt-4o",
)
research_task = Task(
description="Research Q4 trends. Use wal_research to pay for any premium data sources (max $20).",
agent=researcher,
expected_output="A summary of Q4 market trends with sources cited.",
)
writing_task = Task(
description="Write a report on the research findings. Use wal_content to purchase images (max $10).",
agent=writer,
expected_output="A formatted report with images.",
)
crew = Crew(agents=[researcher, writer], tasks=[research_task, writing_task])
result = crew.kickoff()
print(result)Each agent operates with its own wallet and budget. The policy engine enforces spending limits per wallet, so the researcher cannot exceed $20 and the writer cannot exceed $10.
REST Fallback
You can use Wallgent with CrewAI today by wrapping REST API calls:
import requests
from crewai.tools import tool
API_KEY = "wg_test_your_key_here"
BASE = "https://api.wallgent.com"
HEADERS = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
@tool("Check wallet balance")
def check_balance(wallet_id: str) -> str:
"""Check the available balance of a Wallgent wallet."""
resp = requests.get(f"{BASE}/v1/wallets/{wallet_id}/balance", headers=HEADERS)
data = resp.json()
return f"Available: ${data['available']}, Pending: ${data['pending']}"
@tool("Send payment")
def send_payment(from_wallet: str, to_wallet: str, amount: str, description: str) -> str:
"""Send a payment between two Wallgent wallets."""
resp = requests.post(
f"{BASE}/v1/payments",
headers=HEADERS,
json={"from": from_wallet, "to": to_wallet, "amount": amount, "description": description},
)
data = resp.json()
return f"Payment {data['id']} — status: {data['state']}"Next Steps
- Explore spending policies to set per-agent budgets
- Set up webhooks for real-time payment notifications
- See the full REST API Reference for all available endpoints