Give your CrewAI agent a phone number
A CrewAI phone agent is a crew behind a webhook. CallNode provides the number, sends each thing the caller says to your endpoint as JSON, and speaks the text your crew returns. This tutorial wires one up in a single Python file.
From callnode.io: "The same pattern serves Hermes, openClaw, LangGraph, or a plain function: if it can answer an HTTP POST, it can answer a call."
CallNode is the phone layer: the number, the carrier side, speech to text and back. Your crew stays your crew.
What you'll build
A FastAPI endpoint that:
- greets the caller straight away, without running the crew;
- runs a one-agent crew on each thing the caller says and returns a short spoken answer;
- hangs up politely when the caller says goodbye.
What you need
From the CrewAI guide:
- A CallNode account and a number. A local number is $2.99 a month on pay as you go. "No credit card to start."
- "A Python service reachable over HTTPS with crewai and fastapi installed, and a model key for the crew."
- A shared secret. "The number sends it as a Bearer token; the handler refuses anything else."
No telephony library and no SDK: "CallNode speaks to your service over plain HTTPS: one JSON POST per caller turn, one JSON reply."
Step 1: Know the two JSON shapes
CallNode calls your endpoint "once when the call connects, then once per turn" (conversational webhook docs). The three events are call_started, user_speech and user_dtmf (keypad digits).
A user_speech request: transcript is what the caller just said, and conversationHistory is the call so far.
{
"callId": "cn-ob-7f3a18a2-9b40-4e1e-9c4e-1b8b9b8e6b3a",
"event": { "type": "user_speech" },
"transcript": "I'd like to book a demo for next Wednesday at 10 AM.",
"conversationHistory": [
{ "role": "assistant", "content": "Hi, this is Hal from CallNode...", "timestamp": 1780173386556 },
{ "role": "user", "content": "Yes, I'm interested.", "timestamp": 1780173401200 }
],
"meta": {
"from": "+15145550199",
"to": "+16135551234",
"callId": "cn-ob-7f3a18a2-9b40-4e1e-9c4e-1b8b9b8e6b3a"
}
}
Your reply needs only replyText. CallNode "renders it in the number's voice and plays that". Add hangup: true to end the call after the reply, or transfer: true with a transferDestination to hand the caller to a person.
Step 2: Write the handler
This is the reference handler from callnode.io/integrations/crewai, unchanged. Save it as main.py:
import os
from crewai import Agent, Crew, Task
from fastapi import FastAPI, Header, HTTPException, Request
app = FastAPI()
SECRET = os.environ["CALLNODE_WEBHOOK_SECRET"] # set the same value on the number as a Bearer token
receptionist = Agent(
role="Phone receptionist for Acme Plumbing",
goal="Answer the caller helpfully in one or two short spoken sentences.",
backstory="You answer the phone for a plumbing company open 8am to 6pm, Monday to Saturday.",
verbose=False,
)
def answer(transcript: str, history: list[dict]) -> str:
so_far = "\n".join(f"{t['role']}: {t['content']}" for t in history[-6:])
task = Task(
description=(
"You are on a live phone call. Conversation so far:\n"
f"{so_far}\nThe caller just said: {transcript}\n"
"Reply in plain spoken English, one or two sentences, no lists or markdown."
),
expected_output="One or two sentences the caller will hear.",
agent=receptionist,
)
return str(Crew(agents=[receptionist], tasks=[task]).kickoff()).strip()
@app.post("/voice")
async def voice(req: Request, authorization: str = Header(default="")):
if authorization != f"Bearer {SECRET}":
raise HTTPException(status_code=401)
event = await req.json()
kind = event.get("event", {}).get("type")
if kind == "call_started":
return {"replyText": "Thanks for calling Acme Plumbing. How can I help?"}
if kind == "user_speech":
said = event.get("transcript", "")
if any(w in said.lower() for w in ("bye", "that's all", "thank you, that")):
return {"replyText": "Thanks for calling. Goodbye!", "hangup": True}
return {"replyText": answer(said, event.get("conversationHistory", []))}
return {"replyText": "Sorry, I didn't catch that. Could you say it again?"}
How it works:
- The greeting skips the crew. On
call_startedit returns a fixed line "so the caller hears something at once." - Each turn runs one agent and one task. The last six turns of
conversationHistorygo into the task, "so the crew answers in context." - Goodbye ends the call with
hangup: true. "A call that ends politely is a call that ends; the caller never hears a dead line." - Anything else (for example a keypad press, which arrives as
user_dtmf) gets a "Sorry, I didn't catch that" reply. Add a branch if your crew should handle digits.
Step 3: Run it behind HTTPS
Set CALLNODE_WEBHOOK_SECRET to a long random value, install crewai and fastapi, and serve the app the way you normally serve FastAPI, at a public HTTPS URL. Your endpoint will be that URL plus /voice.
Step 4: Point your number at the crew
- In the CallNode dashboard, buy a local or toll-free number.
- Open the number and paste your endpoint URL as its voice webhook, with Bearer Token authentication and the same secret as
CALLNODE_WEBHOOK_SECRET.
Prefer the API? The numbers docs take the same settings on PATCH /api/v1/numbers/:id: voice.webhookUrl and voice.webhookAuth with "type": "bearer". "Changes take effect for the next inbound call or message."
Step 5: Call your number
Call the number from your own phone and talk to your crew. That exercises the real phone path end to end.
About test mode: test keys (cn_test_) are good for building against the API, but "a test call never reaches the call's conversational webhookUrl: no call_started and no user_message events" (test mode docs). To hear your crew answer, call the number for real.
Step 6: Keep turns fast
The caller hears silence while your crew thinks. From the docs: respond "within a few seconds. The bridge waits up to 30 seconds, but the caller hears nothing while it waits."
- One agent, one task, on the call. "Every extra agent or tool call is time the caller spends waiting."
- Do heavy work after the call. "Queue a second crew from the completed event on the status webhook."
- Need more time per turn? On calls to your number, CallNode waits for the number's
voice.webhookTimeout: 1000 to 120000 ms, default 30000. Waiting longer doesn't make silence shorter, though, so keep the crew small first. - Retries: "If your endpoint fails, times out or returns non-2xx, the bridge tries twice more, one second apart (an HTTP 401 is not retried)." Make sure a retried turn doesn't do the same work twice.
Where to go next
- Raw audio, barge-in or your own speech models? The Realtime WebSocket streams both ways to code you host. See the webhook and WebSocket quickstart.
- Prefer no code? The same number works with n8n and Flowise.
- The bigger picture: a phone number for your AI agent.
What it costs
From https://callnode.io/pricing, checked 2026-11-28:
| Item | Price (quoted) |
|---|---|
| Local number | "Local numbers $2.99 a month, toll-free $4.99 a month" |
| Inbound calls | "$0.02/minute", "Billed per whole minute, rounded up, from a prepaid balance" |
Spoken replies (CallNode speaks your replyText) | Realtime WebSocket row: "$0.02 a minute on top of the call; spoken replies with Premium Voice $0.04 a minute" |
How spoken replies bill, from the conversational webhook docs: "the realtime rate … per started minute of the call, charged once at call end and only on calls where at least one reply was rendered". "Calls where every reply carried its own audio pay nothing extra." This handler returns text only, so its calls include spoken replies.
Your model costs are on your side. You can create an account without a credit card; usage is prepaid.
FAQ
Does CrewAI need a telephony library or an SDK?
No. CallNode sends one JSON POST per caller turn over HTTPS and speaks the text you return. Any Python web framework works; the example uses FastAPI.
How fast does the crew have to answer?
Within a few seconds per turn. CallNode waits up to 30 seconds by default (or the number's voice.webhookTimeout), but the caller hears nothing while it waits.
How does the crew remember earlier turns?
Every request carries conversationHistory and a stable callId. Pass the history into the task, as the example does, or key your own memory on the call id.
Can the crew end or transfer the call?
Yes. Return hangup: true after the last reply, or transfer: true with a transferDestination (a phone number or a sip: address).
Do I need to generate audio?
No. Return replyText and CallNode speaks it in the voice chosen on the number. You can return a publicAudioUrl instead if you render your own audio.
Can I test it without a real call?
You can test API requests with test keys, but a test call never reaches your webhook. Call your number from your own phone to hear the crew.