Skip to main content
Full Code
This 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

  1. Get API Keys:
  2. Environment Variables: Set up your environment variables.
  3. 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 the livekit.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 the llm_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.
The rag_context string will contain the user’s profile and recent events, formatted and ready to be used by the LLM.

Running the Agent

Finally, we set up the entry point to run the agent.
To run the code, first download the necessary assets:
Then, start the agent:
You can now have a conversation with the voice agent. It will remember information you provide across different sessions.