Integrations / OpenAI Agents SDK
Phone call and SMS tools for the OpenAI Agents SDK
The Agents SDK can use an async function as a tool. The example below adds two tools: place_call and send_sms.
1. Install
Hail's SDK needs Python 3.11+.
pip install hail-sdk # .env HAIL_API_KEY="hl_live_9fa2..." pip install openai-agents
2. Define function tools
function_tool reads the signature and the docstring. Your agent writes the system prompt. Hail hosts the call loop and runs the conversation from that prompt. The request returns a call id. The transcript arrives as events.
from agents import Agent, Runner, function_tool
from hail import Client
@function_tool
async def place_call(to: str, system_prompt: str) -> str:
"""Call a number. Hail's voice pipeline runs the
conversation from the system prompt."""
async with Client() as hail:
call = await hail.calls.create(
to=to, system_prompt=system_prompt,
recipient_consent=True,
)
return f"dialing {call['id']}"
@function_tool
async def send_sms(to: str, body: str) -> str:
"""Text an opted-in recipient."""
async with Client() as hail:
sms = await hail.sms.create(
to=to, body=body, recipient_consent=True,
)
return f"queued {sms['id']}"3. Run the agent
The model selects a call or an SMS. Hail sends transcripts and delivery events to your webhook.
agent = Agent(
name="Scheduler",
instructions="Confirm appointments. Call if SMS gets no reply.",
tools=[place_call, send_sms],
)
result = await Runner.run(
agent, "Confirm tomorrow's 3pm with +14155550142"
)Questions
Does the agent hear the phone call?
Hail runs the call with turn detection. Hail sends the transcript as events that your agent can read.
Do I need to pick an STT or TTS vendor?
No. Your agent passes a system prompt. Hail handles the audio and the turn-taking.
Run the examples
The examples above run as written with a Hail account and an API key. You pay for usage.
Create account