A runnable LiveKit Agents voice agent with long-term memory backed by MemorySync. Tell the agent something, hang up, call back — it remembers.
Voice is the one surface where memory latency is audible, so the integration is built around a hard rule: recalled context is injected in on_user_turn_completed under a strict time budget (default 1.2 s). If the memory service is slow, the agent replies without memories — the conversation is never stalled. A background prefetch warms the next turn's recall, so the steady-state cost is close to zero.
- Add a
.envin this directory with your LiveKit and MemorySync credentials:Get a MemorySync API key at app.memorysync.io (Settings → API Keys).LIVEKIT_URL=your_livekit_url LIVEKIT_API_KEY=your_api_key LIVEKIT_API_SECRET=your_api_secret MEMORYSYNC_API_KEY=your_memorysync_api_key - Install dependencies:
pip install -r requirements.txt
python memorysync_memory.py consoleSay "My name is Alex and my favorite color is teal", exit, then start a new console session — the agent recalls both facts.
memory.on_user_turn(turn_ctx, new_message)runs insideon_user_turn_completedand injects a compact block of relevant memories for this turn only (it is not persisted into the LLM context, avoiding context bloat and double-learning).memory.attach(session)subscribes toconversation_item_addedand stores both user and assistant turns as they finalize, with deterministic idempotency seeds so retries and reconnects never create duplicates. Interrupted assistant turns are stored withinterrupted: truemetadata.create_memory_search_tool(memory)gives the LLM an explicit search tool for questions like "what did I tell you last week?". Errors come back to the model as readable strings, never exceptions.- Memory outages, quota limits, and dead networks all degrade to "no memories this turn" — the call itself is never affected.
With speech-to-speech realtime models, prefer the memory search tool over per-turn injection: on_user_turn_completed still fires, but injection can land after the model has started speaking.
- MemorySync LiveKit guide — full integration reference
livekit-memorysyncon PyPI