Agents
An agent is a saved brain: instructions, greeting, AI line, voice, tools and
limits. A number routes its incoming calls to one agent and its incoming texts
to one agent. POST /calls can place outbound calls with the same agent.
# 1. Save an agent.
curl -X POST "$HAIL_API_URL/v1/agents" -H "Authorization: Bearer $HAIL_API_KEY" \
-H 'Content-Type: application/json' -d '{
"name": "Front desk",
"system_prompt": "You are the front desk of Acme Dental. Book, change or cancel appointments.",
"first_message": "Thanks for calling. Are you booking, changing, or cancelling an appointment?",
"voice_config": {"language": "en"}
}'
# → {"id": "a1b2...", ...}
# 2. Point a number at it. Calls and texts to the number are now answered.
curl -X PATCH "$HAIL_API_URL/v1/numbers/$NUMBER_ID" -H "Authorization: Bearer $HAIL_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"voice_agent_id": "a1b2...", "sms_agent_id": "a1b2..."}'
# 3. Or place an outbound call with it.
curl -X POST "$HAIL_API_URL/v1/calls" -H "Authorization: Bearer $HAIL_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"to": "+14155550100", "agent_id": "a1b2...", "recipient_consent": true}'CLI: hail agents create "Front desk" --prompt-file ./front-desk.md, then
hail numbers route <number-id> --calls <agent-id> --texts <agent-id>.
Restrict tools with hail agents update <id> --tools end_call,send_sms; allow
all again with hail agents update <id> --all-tools.
MCP: list_agents, get_agent, create_agent, update_agent, delete_agent, route_number, and place_call(agent_id=...).
SDK: client.agents.create(...), client.numbers.route(...).
Schemas: AgentCreate, AgentUpdate, AgentResponse, PhoneNumberRoutingUpdate
in openapi/openapi.yaml.
Hand over to a person
Let the agent pass a live call to a person you picked: a team member with a
phone number, or a contact. Use the id that GET /contacts (or
hail contacts list) shows: a contact's uuid, or member:<user id> for a
team member.
curl -X PATCH "$HAIL_API_URL/v1/agents/$AGENT_ID" -H "Authorization: Bearer $HAIL_API_KEY" \
-H 'Content-Type: application/json' -d '{
"handover_contacts": [
{"contact_id": "member:6f1c2a9e-3b7d-4c51-9a8e-2d4f6b1e0c37", "note": "sales questions"},
{"contact_id": "'"$CONTACT_ID"'", "note": "billing questions or an angry caller"}
]
}'CLI: hail agents update <id> --handover "member:<user-id>=sales questions"
(repeat the flag for more people; --no-handover clears the list).
MCP: create_agent(handover_contacts=[{"contact_id": "...", "note": "..."}]) sets the list;
update_agent(agent_id, handover_contacts=[...]) replaces it, and [] removes every contact.
- Up to 10 people. Each needs a phone number in a country Hail sells
numbers in. A team member must belong to the organization; one who leaves
it is skipped and cannot be dialed. It must pass the do-not-call and premium-rate checks, on save
and again before dialing.
noteis 1-200 characters and tells the agent when to hand over. - The agent gets the
transfer_calltool. Iftoolsis a list, saving contacts addstransfer_callto it and clearing them removes it;null(all tools) staysnull. The agent never sees a phone number. - The contact sees your Hail number as caller ID.
- The contact has 30 seconds to answer. If not, the agent comes back and
offers to take a message. While it rings the agent keeps listening: the
caller can say stop, or ask for someone else, and the agent hangs up the
ringing phone (
cancel_transfer, which comes withtransfer_call). - While the phone rings, the contact gets a text from your Hail number and an email with the caller's number and the reason (links, emails and phone numbers removed), once per call. A text from a US number to a US number needs an approved US SMS registration; without one the call still rings, with no text. The email needs a verified email domain and an email on the contact (a team member's login email); without one, no email.
- A plain forward: when the phone picks up, the two people are connected
and the agent stops listening and speaking. It says nothing to the
contact. If voicemail answers, the caller hears it and can leave a
message. If nobody on the contact's side makes a sound for 15 seconds
(some mailboxes answer in silence), or the line hangs up within 10
seconds of its first sound (a carrier message), the agent hangs up that
line and comes back to the caller. Code:
handover_watch.py. Once connected, if either side hangs up, the call ends. max_duration_secondsstops applying once the contact answers.handover_max_duration_seconds(60..3600, default 1800 = 30 minutes; CLI--handover-max-minutes) counts from the answer. When it is reached the agent says goodbye and the call ends for both people. Either person can hang up sooner.- Billed as one call at the normal voice rate. The text and the email to the contact are billed as a normal SMS and email.
- Sends a
call.transferredwebhook once someone on the contact's side has spoken and stayed on the line for 10 seconds. PATCHwith[]clears the list; omit the field (or sendnull) to leave it.
What happens on an inbound call
- The carrier sends the call to LiveKit. LiveKit creates a room and dispatches the voicebot (setup).
- The voicebot reads the dialed number and the caller from the SIP
participant and asks
hailhq.core.inbound_callswho answers:- number not yours, a pool number, or a number on the wrong trunk: the call is dropped, no record;
- no live voice agent (paused, or
voice_enabled: false): the call is recorded asfailed,end_reasonno_agent, andcall.failedis sent; - no credits, or voice suspended:
failedwithinsufficient_funds(oruser_rejected), andcall.failed; - otherwise a
ringingcall,call.received, then the agent speaks.
- The agent speaks the AI line, then
first_message(or waits), then followssystem_promptwith the agent's tools. With afirst_messageand no custom AI line, the agent speaks one greeting instead: the first sentence offirst_message, thenI'm an AI assistant for {org}., then the rest.call.answeredandcall.completedfollow as on outbound calls. Each answered minute costs the same as an outbound minute.
The AI line on inbound calls defaults to
Hi, this is an AI assistant answering on behalf of {org}. (or the short
line inside first_message, above); the workspace
default lives in Call settings (organization_call_settings.ai_disclosure_line)
and an agent can set its own ai_disclosure_line. ai_disclosure: false on the
agent skips it; the responsibility for that is yours.
The built-in lines are spoken in the call's language (voice_config.language,
else the workspace voice's language). A custom ai_disclosure_line is spoken
as written.
What happens on an inbound text
- Hail stores the text and sends
sms.receivedas before. STOP,CANCEL,END,QUIT,UNSUBSCRIBEandHELP/INFOare answered by Hail and never reach the agent.YES,STARTandUNSTOPare an opt-in only from a person who opted out; Hail turns texts back on and replies. From anyone else they are an answer, and the agent gets them.- Any other text to a number with
sms_agent_idset (agentlive,sms_enabled: true) is answered by the agent: one reply, written fromsystem_promptand the last 20 texts of the last 24 hours with the caller (plus texts between that number and the caller that have no agent: sent throughPOST /sms, or received before the number had a text agent). Older texts and calls it reads with thethread_historytool (see Threads). The reply is sent from the same number through its carrier. The agent sends at most 20 replies per thread in any 24 hours; past that it stays quiet until older replies leave the window. Replies bill as outbound SMS. Inbound rows carryagent_reply_state(pending,processing,done,skipped,failed) in the database; replies carryagent_id.
The text worker runs inside the voicebot service
(hailhq.voicebot.textbot) and
needs HAIL_INTERNAL_SECRET and HAIL_API_URL. It answers
HAIL_TEXT_REPLY_CONCURRENCY texts at once. A failed model or API call is
retried up to 3 times with backoff; a text still unanswered after
HAIL_TEXT_REPLY_MAX_AGE_SECONDS is skipped. A text to a workspace with no
credits gets no reply. If the balance is under 1 cent when the worker picks
the text up, it is skipped before the model runs, with
metadata.skipped_reason: "insufficient_funds". If credits run out while the
model writes, the text is skipped without that key.
Threads
A caller texts an order number to the agent's SMS number, then calls the agent.
When the caller asks about it, the agent looks it up with the thread_history
tool. A text sent during a call goes to the voice agent and is then marked
done. A text sent from the moment the call row is created (ringing included)
counts. If the voice agent never got it, the text agent answers it when the
call ends, or when the stale-call sweep closes the call. The reply age limit
(HAIL_TEXT_REPLY_MAX_AGE_SECONDS) restarts then.
-
Scope: agent + caller number. Texts and call turns both count.
-
Prompts carry no history. Both agents read it with the
thread_historytool:sourceissms(texts),voice(call turns) orall;beforepages back over the last 7 days;item_idreturns one full message. The voice prompt gets one line telling the agent to use the tool when the call has it; the text prompt always has it. Why: history in the prompt also held the agent's own past "I don't have that" lines, and the model repeated them. -
The text agent's chat holds the last 20 texts of the last 24 hours, no call turns.
thread_historyis its only tool. -
thread_historyalso returns texts between the number and the caller that have no agent. -
Hidden or invalid caller numbers get no history.
-
Caller ID on a phone call can be faked. Do not put secrets in an agent's instructions or in texts it sends.
-
History the tool returns is sent to the agent's LLM, including a bring-your-own endpoint.
-
send_smspicks the number in this order:- the dialed number, if it can text and is not bound to another agent.
Bound to this agent: used. Free: it is bound to this agent when the agent
has
sms_enabled, else used unbound; - the oldest org SMS number bound to this agent;
- the oldest free org SMS number: bound to this agent when it has
sms_enabled, else used unbound; - none: the agent says it cannot text.
It never uses a number bound to another agent. A number bound this way makes the agent answer every text sent to it (audit entry
number.route). A number used unbound stays unrouted. - the dialed number, if it can text and is not bound to another agent.
Bound to this agent: used. Free: it is bound to this agent when the agent
has
Code: threads.py,
text_watch.py,
thread_history.py.
Routing rules
voice_agent_idneeds thevoicecapability and an agent withvoice_enabled: true; otherwise the request returns 422. Setting it attaches the number for inbound at the carrier and lists it on Hail's LiveKit inbound trunk for that carrier (hailhq.core.inbound_routing);nullundoes both.PhoneNumberResponse.inbound_registeredsays where it stands.sms_agent_idneeds thesmscapability and an agent withsms_enabled: true; otherwise the request returns 422. No carrier work: inbound texts already reach Hail.- Releasing a number, or deleting its agent, unregisters it first.
- A paused agent (
status: paused) answers nothing; calls to its numbers fail withno_agent, andPOST /callswith itsagent_idreturns 409.POST /callswith an agent that hasvoice_enabled: falsealso returns 409.
MCP clients
Hail exposes MCP as a remote server. Hail Cloud uses OAuth. Paste the URL into your client. Click Allow in the browser. Your agent then gets the call, SMS, email, agent, number and verification tools. There are no keys to manage and no installation.
Webhooks
When a subscribed event occurs — inbound mail or SMS, a delivery report, a call outcome — Hail POSTs a signed JSON event to your URL. Verify the X-Hail-Signature header against the once-shown secret. Return any 2xx, and you are done. Hail retries a non-2xx response (or a timeout) on a fixed ladder.