PyAI + ContextDB
Give PyAI voice agents customer memory across every call.
PyAI Omni gives you the realtime voice agent. ContextDB gives that agent a caller history it can defend: what was confirmed, what was only mentioned, and what must not be acted on without asking. The integration is one tool endpoint on your backend.
recall_for_action before bookings and
account changes, and write sourced facts back from your call-completion
handler.
The tool endpoint
Use one backend endpoint before every booking or account change.
Configure the tool on your PyAI agent to hit your backend with the caller identity and the intended action. Your backend consults trusted memory and returns either the go-ahead with evidence or the exact question to ask.
# backend endpoint your PyAI agent tool calls
from contextdb_cloud_client import CloudClient
@app.post("/pyai/tools/gate-action")
async def gate_action(req: Request):
body = await req.json()
caller, intent = body["caller_id"], body["intent"]
async with CloudClient(BASE_URL, api_key=KEY) as cdb:
evidence = await cdb.recall_for_action(caller, intent)
if evidence:
return {"decision": "act",
"evidence": [m.content for m in evidence]}
pending = await cdb.pending_confirmations(caller)
if pending:
return {"decision": "ask",
"say": f"Just to confirm: {pending[0].content}. "
"Is that right?"}
return {"decision": "ask",
"say": "I don't have that on file yet. "
"Could you confirm the details?"}
After the call
The completion handler saves what the customer said.
When PyAI reports the call finished, store the durable facts with the confidence they deserve. Explicit instructions are high-confidence memories; musings are wishes that stay behind the gate until someone confirms them.
@app.post("/pyai/on-call-complete")
async def on_call_complete(req: Request):
call = await req.json()
caller = call["caller_id"]
async with CloudClient(BASE_URL, api_key=KEY) as cdb:
for fact in call["extracted_facts"]:
await cdb.remember(
caller,
fact["content"],
source="user_stated",
confidence=fact["confidence"],
)
# explicit yes during the call → close the loop
if call.get("confirmed_memory_id"):
await cdb.confirm(caller, call["confirmed_memory_id"])
return {"ok": True}
Action map
Add memory at four points in a PyAI call.
| Moment | PyAI surface | ContextDB call |
|---|---|---|
| Call connects | Agent context / greeting variables | recall → caller snapshot |
| Booking, refund, account change | Agent tool → your backend | recall_for_action → act, ask, or abstain |
| Caller confirms | Agent tool → your backend | confirm → fact graduates |
| Call completes | Completion handler | remember with source and confidence |
Questions
PyAI-specific questions.
Why gate in my backend instead of prompting the agent to be careful?
Prompts drift and models comply with confident-sounding transcripts.
The gate is a deterministic check against sourced evidence, outside
the model, with the decision recorded. "Be careful" is a wish;
recall_for_action is a policy.
Does memory work across voice and chat channels?
Yes, if you use the same user_id for the same human
across channels. The caller on today's PyAI call and tomorrow's chat
widget share one partition, which is where most repeated-questions
pain disappears.
What stays in PyAI and what goes to ContextDB?
Recordings, transcripts, and call analytics stay in PyAI. ContextDB holds the extracted action-relevant facts, their provenance, and the decision log for the actions your agent took.
Add customer memory before your next PyAI call.
The quickstart covers the gate and write calls above.