Building the Memory Layer for a Voice AI Agent
From the publisher’s feed, collected in the ZeroLabs newsroom.
Photo by Enchanted Tools on UnsplashVoice AI raises the bar for responsiveness completely.In a chatbot, a two or three second delay feels acceptable. In voice, that same delay feels strange. People start wondering if the app heard them, whether the microphone failed, or if they should repeat themselves. Voice is much less forgiving.That was the main thing I kept running into while experimenting with a voice journal app: a voice-first app powered by Sarvam AI for speech to text and text to speech conversion and Redis Agent Memory Server for memory.It’s a pretty straight forward app. A user speaks, the app transcribes the audio, decides whether the user wants to save something or ask something, fetches the right context, and then responds back in voice.What makes it interesting is building the memory layer for this.Screenshot of the landing pageWithout memory, a voice assistant can answer one turn at a time, but it does not really feel personal. It cannot remember what you said earlier, what you were working on, or what patterns have been showing up across conversations. It behaves more like a stateless tool than a companion.I wanted the assistant to remember useful things across sessions, while still keeping recent conversation context available during an active interaction.Very early into the implementation, I realized I have two major problems at hand : structuring the right memory layer and reducing the latency.The memory model I usedI built the memory layer around Redis Agent Memory Server because it gives me the two memory types I care about most:- Working memory for session continuity- Long-term memory for cross-session recallWorking memory is the short-term scratchpad. It holds the recent conversation in the current session so the assistant can stay coherent within the flow of a voice interaction.Long-term memory is what survives beyond the session. That is where I store journal entries, mood signals, and the kinds of details that should still matter the next time the user comes back.For this voice journal app, that split turned out to be the right abstraction.When the user logs a note, I create a long-term memory directly. Journal entries are stored as episodic memories because they are tied to personal experiences, moments, and reflections. For lighter conversational continuity, I keep the back-and-forth in working memory.This is a simplified version of the long-term memory write from the project:memory = ClientMemoryRecord(text=transcript,memory_type=MemoryTypeEnum.EPISODIC,user_id=user_id,session_id=session_id,namespace="voice-journal",topics=["journal", "voice_entry"],created_at=now,)await client.create_long_term_memory(memories=[memory],deduplicate=True,)I like this pattern because it makes the write intentional. I am not just storing a raw transcript. I am deciding what kind of memory it is, who it belongs to, and how it should be retrieved later.That separation matters a lot. If you treat every spoken turn as equally important, memory becomes noisy very quickly. Voice apps generate a lot of filler: corrections, pauses, half-finished thoughts, “wait no,” and repeated phrasing. Not all of that belongs in the same retrieval path.One of the most useful things I learned is that memory quality is not only about what you store. It is also about what you do not store, what you keep session-scoped, and what you explicitly filter when reading it back.Why Redis Agent Memory Server worked well hereRedis Agent Memory Server gave me an opinionated but flexible memory layer without making me build memory infrastructure from scratch.I could:- isolate memories with a namespace- filter by `user_id`- store episodic and semantic memories- retrieve memories semantically instead of relying on keyword search- keep working memory separate from long-term memoryThat was especially useful in a voice product because the retrieval has to be tight. If the assistant pulls too much context, generation slows down and the reply becomes less focused. If it pulls irrelevant context, the assistant sounds confused. Both are bad voice experiences.So instead of treating memory like a giant history dump, I designed it more like a performance-sensitive context service.What I did to make the voice experience fasterArchitecture diagram of the appHere are the tweaks that made the biggest difference for me.1. Used streaming speech APIs wherever possibleFor speech-to-text and text-to-speech, I used streaming paths so the system could begin processing earlier and reduce time-to-first-response.For TTS in particular, streaming matters a lot. The app can start receiving audio chunks before the entire response is synthesized. That makes the assistant feel much more alive.Here is the simplified shape of the streaming TTS flow:async with self.async_client.text_to_speech_streaming.connect(model="bulbul:v3",send_completion_event=True,) as ws:await ws.configure(target_language_code=language_code,speaker=speaker,output_audio_codec="mp3",)await ws.convert(text)await ws.flush()async for message in ws:if isinstance(message, AudioOutput):yield base64.b64decode(message.data.audio)The point is not just to stream for the sake of streaming. The point is to start playback earlier, because that is what makes the assistant feel fast.In voice UX, first audio byte matters more than total completion time.2. Ran independent fetches in parallelWhen the user asks something that needs a response, the app may need three things:- recent working memory- relevant long-term memories- calendar contextThose do not need to happen one after another. So I fetch them in parallel.This is the simplified version of that pattern:conversation_context, memories, calendar_context = await asyncio.gather(fetch_conversation(),search_memories(),fetch_calendar(),)It is a very normal async optimization, but in voice it matters more because users feel the whole delay as one silence.This is one of those changes that feels very normal in backend engineering, but it becomes even more important in voice systems because users experience the total delay as one continuous pause.3. Kept retrieval boundedFor semantic search, I do not dump a huge list of memories into the response generation step. I retrieve a small number of results and only use the top memory for context in the fast path.The search call itself stays tightly scoped:results = await client.search_long_term_memory(text=query,filters={"namespace": {"eq": "voice-journal"}, "user_id": {"eq": user_id}},limit=5,distance_threshold=0.8,)pAnd in the response path, I only keep the top result:def get_top_memory(memories):if not memories:return ""text = memories[0].get("text", "")return text[:200]pThat keeps context useful without letting the prompt grow uncontrollably.This is a tradeoff, but it is a good one for voice.A voice reply usually needs one relevant anchor, not a full research packet. Keeping the context small reduces retrieval overhead and also keeps generation concise.4. Used semantic routing instead of sending everything to an LLMIntent detection is one of those hidden latency sinks. If every user utterance goes to a large model just to figure out whether it is a note, a journal question, or a calendar request, you burn time before the real work even starts.So I used a RedisVL semantic router for intent detection. It is a much better fit for this kind of task than a full LLM hop. It is fast, predictable, and good enough for routing requests like:- log this- remind me what I said yesterday- what’s on my calendarThat let me reserve model time for the response itself instead of spending it on classification.That helped me keep the top of the pipeline fast before memory retrieval and response generation even began.5. Kept responses short on purposeThis is a voice system, not a blog generator. Shorter responses help reduce model generation time and also reduce TTS time. That means lower latency and a better conversational rhythm.A voice assistant that responds in one or two crisp sentences often feels smarter than one that delivers a long paragraph after a pause.What nextI am working on better structuring and expiration of memories. Working memory should stay strictly session-based with a TTL, while long-term memory should be split more intentionally by purpose, for example separating daily updates, incidents, profile facts, and user preferences. Redis Agent Memory Server already gives useful building blocks here through memory_type, topics, namespace, event_date, pinned memories, recency-aware reranking, and forgetting policies.The next step is to use those features more deliberately. Temporal questions like “what changed today?” should not be handled with plain semantic search alone. They should be detected as time-sensitive queries, then routed through recency-aware retrieval with stronger freshness weighting and date filters. At the same time, preferences and stable profile facts should be preserved separately from short-lived operational updates, ideally in their own namespace and protected from cleanup.This opens up a more realistic enterprise memory model: session memory for live conversations, durable semantic memory for user facts and preferences, episodic memory for updates and incidents, and policy-driven forgetting for everything that should not live forever. That is the direction I’d take next to make the system more useful and closer to real-world enterprise AI behavior.Show me the codeThis project is still a work in progress, and I’m continuing to shape it as I learn. If you’d like to explore it, build on it, or help turn it into a really great voice journal app, you can find the code here:https://github.com/redis-developer/voice-ai-redis-memory-demoBuilding the Memory Layer for a Voice AI Agent was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.