OpenAI Agents SDK
Wrap B2A endpoints as Agents SDK function_tools.
Wrap the B2A REST endpoints as function_tools. The agent will call them when the
conversation involves accommodation.
Example
from agents import Agent, function_tool
import httpx, os, uuid
API = "https://api.b2a.bluepillow.com/v1"
KEY = os.environ["B2A_API_KEY"]
@function_tool
def b2a_decide(location_id: str, check_in: str, check_out: str, adults: int) -> dict:
"""Return one booking recommendation."""
r = httpx.post(
f"{API}/decide",
headers={
"Authorization": f"Bearer {KEY}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"location": {"type": "destination_id", "value": location_id},
"dates": {"check_in": check_in, "check_out": check_out},
"guests": {"adults": adults},
"context": {"end_user_country": "US", "currency": "USD"},
},
timeout=10.0,
)
r.raise_for_status()
return r.json()
agent = Agent(name="travel", tools=[b2a_decide])
Wrap the other endpoints (/validate, /bookings/initiate) the same way.