Async tool. Reads tenant_id + rag_top_k from runtime state. Loads per-tenant FAISS index and retrieves chunks via MMR (lambda_mult=0.7). Sources surfaced to UI.
search_web_tool
Tavily · tenant domain filters
Async tool. POSTs to api.tavily.com/search scoped to tenant's search_include_domains allowlist and search_exclude_domains blocklist.
State, Context & Persistence
AgentRuntimeState
Extends AgentState with sources: list[dict]. Tenant system prompt injected per-invocation as context.
multi_chatbot_core/agent_runtime.py
CopilotKitMiddleware
Emits AG-UI streaming events — tool calls, intermediate tokens, and source citations — to the CopilotKit runtime proxy.
copilotkit package
MongoDBSaver Checkpointer
Persistent state. Threads resume across sessions and channels. A separate MemorySaver instance powers the suggestions agent.
checkpoints · checkpoint_writes · TTL 24h
Voice Pipeline — Twilio ⇄ Azure Voice Live
VoiceSessionHandler
azure.ai.voicelive.aio
Full session lifecycle: config, audio relay, transcription, barge-in, function calls. Replays up to 10 prior thread messages on connect. Persists turns to LangGraph checkpoint.
Function Tools
retrieve_documentssearch_web
TwilioMediaAdapter
μ-law 8kHz ⇄ PCM16 24kHz
Bidirectional codec bridge via audioop. Installed as send_message callback on VoiceSessionHandler. Handles ulaw2lin + ratecv both directions.
Route
WS /voice/twilio/stream/{tenant}
voice_metrics
ring buffer · maxlen=500
Tracks end-of-speech → first-audio TTFT per tenant. In-memory deque. Exposed via GET /voice/stats.
Methods
record_turn()snapshot()
webhook: POST /voice/twilio/incomingstatus: POST /voice/twilio/statushangup: POST /voice/twilio/calls/{sid}/hangupbrowser: WS /voice/ws/{client_id}
API Endpoints — FastAPI :8001
/vectorstoreRAG
POST refillrefill-selectedwipestatusdocumentsvalidateupload