Full CodeThis tutorial demonstrates how to build a voice agent with long-term memory using Memobase and LiveKit. This combination is ideal for applications like AI companions, customer support bots, and more.
Setup
-
Get API Keys:
- Memobase: Sign up at Memobase or run a local server.
- LiveKit: Get your
LIVEKIT_URL
,API_KEY
, andAPI_SECRET
from the LiveKit Cloud Console. - Deepgram: Get your
DEEPGRAM_API_KEY
from the Deepgram Console.
-
Environment Variables: Set up your environment variables.
-
Install Dependencies:
Code Breakdown
The full code is available here. We will be using the LiveKit Agents SDK v1.0. The core of the integration involves subclassing thelivekit.agents.Agent
class and overriding the llm_node
method to inject memory context from Memobase.
Agent Initialization
First, we initialize the Memobase client and define our custom agent class.Injecting Memory
Next, we override thellm_node
method. This method is called just before the chat history is sent to the LLM. Here, we will retrieve the user’s memory from Memobase and add it to the system prompt.
rag_context
string will contain the user’s profile and recent events, formatted and ready to be used by the LLM.