Integrations / LangGraph
Add phone, SMS, and email tools to a LangGraph agent
Add SMS, email, and call tools to a LangGraph agent with the Hail Python SDK. The SDK is async, so the tools work in an async graph. One API key covers SMS, email, and voice.
1. Install
The Hail Python SDK needs Python 3.11+.
pip install hail-sdk # .env HAIL_API_KEY="hl_live_9fa2..." pip install langgraph langchain
2. Define the tools
Each tool makes one SDK call. Every send must set recipient_consent. The API refuses a send without it.
from langchain_core.tools import tool
from hail import Client
@tool
async def send_sms(to: str, body: str) -> str:
"""Text an opted-in recipient."""
async with Client() as hail: # reads HAIL_API_KEY
sms = await hail.sms.create(
to=to, body=body, recipient_consent=True,
)
return f"queued {sms['id']}"
@tool
async def send_email(to: str, subject: str, body_text: str) -> str:
"""Email a recipient from your Hail inbox."""
async with Client() as hail:
msg = await hail.emails.create(
to=[to], subject=subject,
body_text=body_text, recipient_consent=True,
)
return f"queued {msg['id']}"3. Add the tools to the graph
The prebuilt ReAct agent selects the tool for the task. Calls work the same way with hail.calls.create.
from langgraph.prebuilt import create_react_agent
agent = create_react_agent(
"anthropic:claude-sonnet-5",
tools=[send_sms, send_email],
)
result = await agent.ainvoke(
{"messages": [("user", "Text +14155550142 that order 4471 shipped")]}
)4. Receive replies
Hail sends inbound SMS and email to your webhook or to the event stream. The graph can then continue with the reply.
async with Client() as hail:
async for ev in hail.events.tail():
if ev["type"] == "sms.received":
# feed the reply back into the graph
handle(ev)Questions
Does the Hail SDK work with LangGraph's async graphs?
Yes. The SDK is async. Tools that you define with async def work in LangGraph without a wrapper.
Can the LangGraph agent receive SMS replies?
Yes. Register a webhook for sms.received, or read the event stream. Then resume the graph with the reply.
Do I need Twilio behind this?
No. Hail provides the number, the carrier registration, and the email domain.
Run the examples
The examples above run as written with a Hail account and an API key. You pay for usage.
Create account