SDK available Cloud alpha View status

Retell AI + ContextDB

Retell handles the call. ContextDB remembers the caller.

Retell gives you low-latency voice conversations. What it cannot know is that this caller phoned twice last month, prefers mornings, and never actually confirmed Friday. Two integration points fix that: a custom function during the call, and a webhook after it.

The integration in one sentence: point a Retell custom function at your backend, have the backend call recall_for_action before any booking or account change, and write durable facts back with remember from the post-call webhook.

During the call

Check the customer's confirmed details before booking.

Retell custom functions call your HTTPS endpoint mid-conversation and speak the result. Before the agent books, your endpoint asks ContextDB for evidence trusted enough to act on. Empty means ask the caller, not guess.

# FastAPI endpoint behind a Retell custom function
# name: check_before_booking
from contextdb_cloud_client import CloudClient

@app.post("/retell/check-before-booking")
async def check_before_booking(req: Request):
    args = (await req.json())["args"]
    caller = args["caller_id"]

    async with CloudClient(BASE_URL, api_key=KEY) as cdb:
        evidence = await cdb.recall_for_action(
            caller, f"book {args['service']} on {args['day']}"
        )

    if not evidence:
        # nothing confirmed → the agent asks, not books
        return {"result": "no confirmed preference on file; "
                          "ask the caller to confirm the day"}
    return {"result": f"confirmed: {evidence[0].content}"}

After the call

Save the important customer details after the call.

Retell posts call events to your webhook when the call ends. Store the durable facts with a source label and honest confidence. A caller thinking aloud is a wish, not an instruction; store it that way and the gate treats it that way.

@app.post("/retell/webhook")
async def on_call_ended(req: Request):
    event = await req.json()
    if event["event"] != "call_analyzed":
        return {"ok": True}

    caller = event["call"]["metadata"]["caller_id"]
    async with CloudClient(BASE_URL, api_key=KEY) as cdb:
        # explicit, confirmed instruction from the call
        await cdb.remember(
            caller,
            "prefers morning appointments",
            source="user_stated",
            confidence=0.95,
        )
        # thinking aloud → low confidence, gated from action
        await cdb.remember(
            caller,
            "might switch to the annual maintenance plan",
            source="user_stated",
            confidence=0.4,
        )
    return {"ok": True}

Action map

Add memory at four points in the Retell call.

Moment Retell surface ContextDB call
Call connects Inbound webhook / dynamic variables recall → caller snapshot into the prompt
Agent wants to book, refund, change Custom function recall_for_action → act, ask, or abstain
Caller says an explicit yes Custom function confirm → the fact graduates
Call ends Post-call webhook remember with source and confidence

Questions

Retell-specific questions.

Does this add latency to the conversation?

Ordinary turns are untouched; the model talks as fast as Retell lets it. The gate runs only inside custom functions guarding consequential actions, where a beat of "let me check that for you" is natural and the alternative is booking the wrong day.

Should I store the Retell transcript in ContextDB?

No. Keep transcripts and recordings in Retell or your archive. Store the extracted, action-relevant facts with provenance, and keep the call ID in your own systems as the pointer back to the transcript.

How do I identify the caller across calls?

Use a stable identifier you control, such as your customer ID resolved from the caller's number, as the ContextDB user_id. The partition is yours; ContextDB isolates it per project and per user.

Help your Retell agent remember every caller.

One custom function and one webhook. The quickstart covers both calls.