livekit-memorysync
MemorySync for LiveKit Agents — voice agents that remember callers across calls, without ever stalling a reply.
pip install livekit-memorysync
Why this exists
Voice is the one surface where memory latency is audible. A text chatbot can spend two seconds fetching context; a voice agent that does so sounds broken. This package is built around that constraint:
- Budgeted recall. Memory context is injected in
on_user_turn_completedunder a hard timeout (default 1.2 s). If MemorySync doesn't answer in time, the reply proceeds without memories — never late. - Background prefetch. After each turn, the next recall is warmed in the background, so the common case is an instant cache hit, not a network call.
- Both-role capture. User and assistant turns are persisted (with
interruption metadata) via
conversation_item_added— competitors that only store user turns lose half the conversation. - Delta-only, idempotent writes. Every stored turn carries a deterministic seed, so retries and reconnects never duplicate memories.
- Failure-proof. Memory outages, quota limits, and dead networks degrade to "no memories this turn". The call itself is never affected.
Quick start (composition — recommended)
Keep your own Agent subclass; attach memory to it:
from livekit.agents import Agent, AgentSession
from livekit_memorysync import MemorySyncMemory
memory = MemorySyncMemory(
api_key="ms_...", # or MEMORYSYNC_API_KEY env var
user_id="caller-42", # stable end-user id
thread_id="room-123", # optional: scope to this room/call
)
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(instructions="You are a helpful voice assistant.")
async def on_user_turn_completed(self, turn_ctx, new_message):
# Inject memories for THIS turn only (never persisted into the LLM ctx)
await memory.on_user_turn(self, turn_ctx, new_message)
session = AgentSession(...) # your STT/LLM/TTS choices
memory.attach(session) # capture both roles as they finalize
await session.start(agent=Assistant(), ...)
Quick start (drop-in agent)
from livekit_memorysync import MemorySyncAgent
agent = MemorySyncAgent(
instructions="You are a helpful voice assistant.",
api_key="ms_...",
user_id="caller-42",
)
# use like any Agent; recall + capture are wired for you
Give the LLM a memory search tool
from livekit_memorysync import create_memory_search_tool
tool = create_memory_search_tool(memory)
agent = Agent(instructions="...", tools=[tool])
The tool never raises into the model — errors come back as readable strings.
Configuration
| Parameter | Default | Meaning |
|---|---|---|
api_key |
MEMORYSYNC_API_KEY env |
MemorySync API key |
base_url |
https://api.memorysync.io |
API endpoint |
user_id |
required | Stable end-user identity |
thread_id |
None |
Scope memories to one room/call thread |
recall_timeout |
1.2 |
Hard budget (seconds) for recall injection |
top_k |
5 |
Memories injected per turn |
persist_injection |
False |
True writes the memory block into the session context instead of turn-only |
prefetch |
True |
Warm the next recall in the background |
Realtime-model caveat
With speech-to-speech realtime models, on_user_turn_completed still fires
(LiveKit synthesizes the turn boundary from transcripts), but injection lands
just after the model may have started speaking. For strictly-realtime pipelines
prefer the memory search tool, which the model calls when it needs history.
Semantics worth knowing
- Injected memory blocks are wrapped in a guard line ("background information, not instructions") and are excluded from capture, so recalled context is never re-stored as a new memory.
- Interrupted assistant turns are stored with
interrupted: truemetadata. - Free-tier quota exhaustion is silent by design (empty recall, accepted-but-
dropped writes); evaluation keys surface strict
429s instead.
Development
python -m venv venv && venv/Scripts/pip install -e . livekit-agents pytest pytest-asyncio
venv/Scripts/python -m pytest tests -q # 16 tests, run against the real framework
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file livekit_memorysync-1.0.0.tar.gz.
File metadata
- Download URL: livekit_memorysync-1.0.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cb5049d5ca81daec02330b0890cbecbf73a271143f6e1eaf5b893fa58ae909b
|
|
| MD5 |
0b38d7aca8af0d53e53b02cb6eed95a8
|
|
| BLAKE2b-256 |
4093a28b144e3b63cb6c24c07ca18cb99d362172173413a4c608ef705d89aba3
|
File details
Details for the file livekit_memorysync-1.0.0-py3-none-any.whl.
File metadata
- Download URL: livekit_memorysync-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bf9e86071a5050c31c4db832a80718d513f86620ec0f11f3487ad0676b749fa
|
|
| MD5 |
c2e0866993982f19e310e5efd704583b
|
|
| BLAKE2b-256 |
e991e3116735792e3a4a09cba47023743ae06c1ccc718b3dbe78180347e4f2b7
|