Skip to main content

Overview

The OpenAI Agents SDK lets you build agents with custom tools, handoffs, and guardrails. You can create Laso Finance tools that give your agent the ability to order cards and send payments via x402.

Prerequisites

  • Python 3.10+
  • A funded agent wallet with USDC on Base (Locus or Sponge)
  • openai-agents installed

Setup

1. Install dependencies

pip install openai-agents requests

2. Define Laso Finance tools

from agents import Agent, Runner, function_tool
import requests

LASO_BASE_URL = "https://laso.finance"


@function_tool
def order_card(amount: int) -> str:
    """Order a prepaid card loaded with the specified USD amount.
    Amount must be between 5 and 1000."""

    url = f"{LASO_BASE_URL}/get-card?amount={amount}"

    response = requests.get(url)
    if response.status_code == 402:
        payment_requirements = response.json()
        x_payment = sign_x402_payment(payment_requirements)
        response = requests.get(url, headers={"X-PAYMENT": x_payment})

    data = response.json()
    return f"Card ordered. Card ID: {data['card']['card_id']}. Use get_card_data to poll for details."


@function_tool
def get_card_data(card_id: str, id_token: str) -> str:
    """Check the status of a card order. Returns card details when ready.
    Poll every few seconds until status is 'ready'."""

    response = requests.get(
        f"{LASO_BASE_URL}/get-card-data?card_id={card_id}",
        headers={"Authorization": f"Bearer {id_token}"},
    )
    return str(response.json())


@function_tool
def send_venmo_payment(amount: int, phone_number: str) -> str:
    """Send a Venmo payment. Amount in USD (5-1000). phone_number is the recipient's 10-digit US phone number."""

    url = f"{LASO_BASE_URL}/send-payment?amount={amount}&platform=venmo&recipient_id={phone_number}"

    response = requests.get(url)
    if response.status_code == 402:
        payment_requirements = response.json()
        x_payment = sign_x402_payment(payment_requirements)
        response = requests.get(url, headers={"X-PAYMENT": x_payment})

    return str(response.json())

3. Create the agent

agent = Agent(
    name="Payment Agent",
    instructions="""You help users order prepaid cards and send payments
    using the Laso Finance API. When ordering a card, always poll for the card
    details until the status is 'ready' before presenting the card number.""",
    tools=[order_card, get_card_data, send_venmo_payment],
)

4. Run it

result = Runner.run_sync(
    agent,
    "Order a $25 prepaid card and give me the card details.",
)
print(result.final_output)

Multi-agent handoff

For complex workflows, use handoffs to delegate between specialized agents:
card_agent = Agent(
    name="Card Agent",
    instructions="You order and manage prepaid cards.",
    tools=[order_card, get_card_data],
)

payment_agent = Agent(
    name="Payment Agent",
    instructions="You send Venmo and PayPal payments.",
    tools=[send_venmo_payment],
)

triage_agent = Agent(
    name="Triage Agent",
    instructions="""Route card requests to the Card Agent and payment
    requests to the Payment Agent.""",
    handoffs=[card_agent, payment_agent],
)

result = Runner.run_sync(triage_agent, "Send $50 to 5551234567 on Venmo")

Guardrails

Add guardrails to prevent accidental overspending:
from agents import GuardrailFunctionOutput, input_guardrail

@input_guardrail
async def spending_limit(ctx, agent, input) -> GuardrailFunctionOutput:
    """Block requests that exceed the spending limit."""
    # Parse the requested amount from the input
    # Return tripwire_triggered=True to block
    return GuardrailFunctionOutput(
        output_info={"checked": True},
        tripwire_triggered=False,
    )

agent = Agent(
    name="Payment Agent",
    tools=[order_card, send_venmo_payment],
    input_guardrails=[spending_limit],
)

OpenAI Agents SDK

Official SDK documentation and examples.