OpenAI Agents SDK Integration
Add payment capabilities to OpenAI Agents SDK agents with native function_tool support. Three tools with automatic schema generation.
Installation
pip install sardis-openai-agentsThe OpenAI Agents SDK integration wraps Sardis payment operations as native function_tool decorated functions, so they work seamlessly with the Agents SDK's tool-calling loop.
Quick Start
get_sardis_tools()
Returns all Sardis tools ready to pass to an Agent. Configure credentials once with configure() or via environment variables.
from agents import Agent, Runner
from sardis_openai_agents import configure, get_sardis_tools
# Configure credentials (or use SARDIS_API_KEY + SARDIS_WALLET_ID env vars)
configure(api_key="sk_live_...", wallet_id="wallet_abc123")
agent = Agent(
name="ProcurementAgent",
instructions="""You are a procurement agent with access to a Sardis payment wallet.
Always check policy before executing a payment. Never exceed spending limits.""",
tools=get_sardis_tools(),
)
result = await Runner.run(agent, "Pay $50 to api.openai.com for API credits")
print(result.final_output)Available Tools
Three tools are available, each decorated with @function_tool for automatic schema generation.
sardis_pay
Execute a policy-controlled payment from the agent's wallet. Spending limits are checked automatically before execution.
# Tool signature
sardis_pay(amount: float, merchant: str, purpose: str = "Payment") -> str
# Example outputs
"APPROVED: $50.00 to api.openai.com (tx: pay_xyz789)"
"BLOCKED by policy: Daily limit of $100 would be exceeded"sardis_check_balance
Check current wallet balance and remaining spending limit.
# Tool signature
sardis_check_balance(token: str = "USDC") -> str
# Example output
"Balance: $500.00 USDC | Remaining limit: $100.00"sardis_check_policy
Dry-run policy check — verify whether a payment would pass before executing it.
# Tool signature
sardis_check_policy(amount: float, merchant: str) -> str
# Example outputs
"WOULD BE ALLOWED: $50.00 to api.openai.com"
"WOULD BE BLOCKED: $50.00 exceeds remaining limit $20.00"Configuration
configure()
Call configure() before get_sardis_tools() to set credentials programmatically. Alternatively, set SARDIS_API_KEY and SARDIS_WALLET_ID environment variables and skip configure() entirely.
from sardis_openai_agents import configure
# Programmatic configuration
configure(api_key="sk_live_...", wallet_id="wallet_abc123")
# Environment variable configuration (no configure() call needed)
# export SARDIS_API_KEY=sk_live_...
# export SARDIS_WALLET_ID=wallet_abc123Example: Interactive Payment Agent
Complete interactive agent that checks policy before every payment.
import asyncio
from agents import Agent, Runner
from sardis_openai_agents import get_sardis_tools
SYSTEM_PROMPT = """You are a procurement agent with access to a Sardis payment wallet.
You can check your balance, verify spending policy, and execute payments.
Always check policy before executing a payment. Never exceed spending limits."""
async def main():
agent = Agent(
name="ProcurementAgent",
instructions=SYSTEM_PROMPT,
tools=get_sardis_tools(),
)
print("Sardis Payment Agent ready. Type 'quit' to exit.\n")
while True:
user_input = input("You: ").strip()
if user_input.lower() in ("quit", "exit"):
break
result = await Runner.run(agent, user_input)
print(f"Agent: {result.final_output}\n")
asyncio.run(main())Example: Handoff Workflow
Use handoffs to create a two-agent workflow where a planner delegates to a payment agent.
from agents import Agent, Runner, handoff
from sardis_openai_agents import get_sardis_tools
# Specialist payment agent
payment_agent = Agent(
name="PaymentSpecialist",
instructions="Execute payments only after verifying policy. Report tx IDs.",
tools=get_sardis_tools(),
)
# Orchestrator that hands off to payment agent
orchestrator = Agent(
name="Orchestrator",
instructions="""Plan tasks and delegate payments to the PaymentSpecialist.
Never execute payments yourself.""",
handoffs=[handoff(payment_agent)],
)
result = await Runner.run(
orchestrator,
"I need to pay $30 to Anthropic for Claude API credits"
)
print(result.final_output)Best Practices
- Always include
sardis_check_policyin the agent instructions to enforce pre-payment checks - Use environment variables for credentials to keep API keys out of source code
- For multi-agent setups, use handoffs so only one specialist agent has payment tools
- Set wallet spending policies before deploying agents to production
configure()is idempotent — calling it multiple times updates the shared default client