Integration · CrewAI and your own code

Let a CrewAI crew answer the phone

A CrewAI phone agent is a crew behind a webhook. CallNode provides the number, turns each thing the caller says into a JSON request to your endpoint, and speaks the text your crew returns. The same pattern serves Hermes, openClaw, LangGraph, or a plain function: if it can answer an HTTP POST, it can answer a call.

The webhook contract is the one every CallNode integration runs on; the crew handler below is a reference pattern you adapt to your own agents.

What your endpoint receives, and what it returns

One request per caller turn. transcript is what the caller just said, conversationHistory is the call so far. Reply with replyText and CallNode speaks it.

Request

JSON
{
  "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"
  }
}

Reply

JSON
{
  "callId":         "cn-ob-7f3a18a2-9b40-4e1e-9c4e-1b8b9b8e6b3a",
  "replyText":      "Got it. What's the biggest bottleneck with your current calling setup?",
  "publicAudioUrl": "https://cdn.yourdomain.example/audio/reply-xyz456.mp3"
}

Add hangup: true to end the call after this reply, or transfer: true with a destination to hand the caller to a person. The full contract is on the conversational webhook page.

A crew behind a webhook, in one file

FastAPI receives the turn, one agent with a short task produces a phone-sized answer, and the handler returns it. The greeting is answered without the crew so the caller hears something at once. Run it behind HTTPS and paste the URL into your number with Bearer Token authentication.

Python
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?"}
  • Keep the on-call crew to one agent and one task. Every extra agent or tool call is time the caller spends waiting.
  • Put the conversation history in the task, as the example does, so the crew answers in context.
  • Say goodbye with hangup: true. A call that ends politely is a call that ends; the caller never hears a dead line.
  • Run heavier work after the call: queue a second crew from the completed event on the status webhook.

What you need

  • A CallNode account and a number. Sign up, buy a local or toll-free number, and paste your endpoint URL into it. 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.
  • An answer within about fifteen seconds per turn.

Need raw audio, barge-in, or your own speech models? The realtime WebSocket streams both ways to code you host. Prefer no code at all? The n8n guide and the Flowise guide use the same number. All integrations are listed under phone numbers for AI agents.

Frequently asked questions

Does CrewAI need a telephony library or an SDK?

No. CallNode speaks to your service over plain HTTPS: one JSON POST per caller turn, one JSON reply. The handler on this page is a normal web endpoint that runs a crew and returns text. Any Python web framework works; the example uses FastAPI.

How fast does the crew have to answer?

Reply within about fifteen seconds per turn. A single agent with a short task answers in a few seconds; a multi-agent crew with tools can take longer, so answer first and finish slow work in the background, or keep the on-call crew small and hand research to a second crew after the call.

How does the crew remember earlier turns of the call?

Every request carries conversationHistory, the turns so far, and a stable callId. Pass the history into the task description, or key your own memory on the call id; the example does the first.

Can the crew end or transfer the call?

Yes. Return hangup: true after the last reply, or transfer: true with a transferDestination to hand the caller to a person. A keypad press arrives as a user_dtmf event with the digits.

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.

What does it cost?

The number is $2.99 a month and inbound calls bill at $0.02 a minute on pay as you go, including speech recognition and the spoken replies. Your model costs are on your side. Every CallNode rate is on the pricing page.

Your crew can take its first call today