📢 Announcing our research paper: Zentry achieves 26% higher accuracy than OpenAI Memory, 91% lower latency, and 90% token savings! Read the paper to learn how we're revolutionizing AI agent memory.
Prerequisites
Before you begin, make sure you have:- Installed Livekit Agents SDK with voice dependencies of silero and deepgram:
- Installed Zentry SDK:
- Set up your API keys in a
.envfile:
Note: Make sure to have a Livekit and Deepgram account. You can find these variablesLIVEKIT_URL,LIVEKIT_API_KEYandLIVEKIT_API_SECRETfrom LiveKit Cloud Console and for more information you can refer this website LiveKit Documentation. ForDEEPGRAM_API_KEYyou can get from Deepgram Console refer this website Deepgram Documentation for more details.
Code Breakdown
Let’s break down the key components of this implementation:1. Setting Up Dependencies and Environment
- Importing required modules
- Loading environment variables
- Setting up logging
- Extracting user identification
- Initializing the Zentry client
2. Memory Enrichment Function
- Stores user messages in Zentry
- Performs semantic search for relevant memories
- Augments the chat context with retrieved memories
- Enables contextually aware responses
3. Prewarm and Entrypoint Functions
- Connects to LiveKit room
- Initializes Zentry memory client
- Sets up initial system context
- Creates a VoicePipelineAgent with memory enrichment
- Starts the agent with an initial greeting
Create a Memory-Enabled Voice Agent
Now that we’ve explained each component, here’s the complete implementation that combines OpenAI Agents SDK for voice with Zentry’s memory capabilities:Key Features of This Implementation
- Semantic Memory Retrieval: Uses Zentry to store and retrieve contextually relevant memories
- Voice Interaction: Leverages LiveKit for voice communication
- Intelligent Context Management: Augments conversations with past interactions
- Travel Planning Specialization: Focused on creating a helpful travel guide assistant
Running the Example
To run this example:- Install all required dependencies
- Set up your
.envfile with the necessary API keys - Ensure your microphone and audio setup are configured
- Run the script with Python 3.11 or newer and with the following command:
- After the script starts, you can interact with the voice agent using Livekit’s Agent Platform and Connect to the agent inorder to start conversations.
Best Practices for Voice Agents with Memory
- Context Preservation: Store enough context with each memory for effective retrieval
- Privacy Considerations: Implement secure memory management
- Relevant Memory Filtering: Use semantic search to retrieve only the most pertinent memories
- Error Handling: Implement robust error handling for memory operations
Debugging Function Tools
- To run the script in debug mode simply start the assistant with
devmode:
- When working with memory-enabled voice agents, use Python’s
loggingmodule for effective debugging: