supermemory/apps/docs/integrations/pipecat.mdx
Mahesh Sanikommu 351091bb16
fix(pipecat): keep the prompt cache in voice pipelines and cap recall at 1.5s (#1915)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-22 00:38:01 +00:00

260 lines
11 KiB
Text

---
title: "Pipecat"
sidebarTitle: "Pipecat (voice)"
description: "Integrate Supermemory with Pipecat for conversational memory in voice AI agents"
icon: "/images/pipecat.svg"
---
Supermemory integrates with [Pipecat](https://github.com/pipecat-ai/pipecat), providing long-term memory capabilities for voice AI agents. Your Pipecat applications will remember past conversations and provide personalized responses based on user history.
## Installation
To use Supermemory with Pipecat, install the required dependencies:
```bash
pip install supermemory-pipecat
```
Version 0.2.0 uses the Supermemory Python SDK v5. Keep using `user_id=`;
the service passes that value as the namespace for profile, search, and writes.
`session_id` is passed as the v5 document `id` (previously `custom_id`).
Set up your API key as an environment variable:
```bash
export SUPERMEMORY_API_KEY=your_supermemory_api_key
```
You can obtain an API key from [console.supermemory.ai](https://console.supermemory.ai).
## Configuration
Supermemory integration is provided through the `SupermemoryPipecatService` class in Pipecat:
```python
from supermemory_pipecat import InputParams, SupermemoryPipecatService
memory = SupermemoryPipecatService(
api_key=os.getenv("SUPERMEMORY_API_KEY"),
user_id="unique_user_id",
session_id="session_123",
params=InputParams(
mode="full", # "profile" | "query" | "full"
search_limit=10, # Max memories to retrieve
search_threshold=0.1, # Relevance threshold (0.0-1.0)
system_prompt="Based on previous conversations:\n\n",
),
)
```
## Pipeline integration
The `SupermemoryPipecatService` should be positioned between your context aggregator and LLM service in the Pipecat pipeline:
```python
pipeline = Pipeline([
transport.input(),
stt, # Speech-to-text
context_aggregator.user(),
memory, # <- Supermemory memory service
llm,
tts, # Text-to-speech
transport.output(),
context_aggregator.assistant(),
])
```
## How it works
When integrated with Pipecat, Supermemory provides two key functionalities:
### 1. Memory retrieval
Supermemory reads the v5 profile once per conversation, on the first context
frame, and searches the same namespace once for each new user message when query
results are enabled:
- **Static Profile**: Persistent facts about the user
- **Dynamic Profile**: Recent context and preferences
- **Search Results**: Semantically relevant past memories
### 2. Context enhancement
Retrieved memories are added to the LLM context before generation, each inside a `<user_memories>` block:
- **Profile**: appended to the first system message (or sent as a new leading system message when there is none). It is fetched once and never refreshed, so it stays byte-identical on every later request and never appears in a user message.
- **Search results**: appended to the user message they were retrieved for. Earlier user messages keep the block they first received, tool-call steps reuse their turn's block without searching again, and results the profile already covers are skipped.
Because the system prompt and earlier turns never change, provider prompt caching keeps working. A turn is identified by its text plus the assistant reply before it, so a repeated question after a new reply gets its own search, and trimming old history from the front keeps every kept message's block. Search results carry absolute dates (`[2026-03-04]`), never relative times.
Recall waits at most 3 seconds and makes no retries. If Supermemory is slow or unavailable, the turn continues without memories; a profile that failed to load is fetched again on the next user turn.
## Memory modes
| Mode | Static Profile | Dynamic Profile | Search Results | Use Case |
| ----------- | -------------- | --------------- | -------------- | ------------------------------ |
| `"profile"` | Yes | Yes | No | Personalization without search |
| `"query"` | No | No | Yes | Finding relevant past context |
| `"full"` | Yes | Yes | Yes | Complete memory (default) |
The profile (static and dynamic) goes in the system message; search results go on the user message.
## Configuration options
You can customize how memories are retrieved and used:
### InputParams
```python
InputParams(
mode="full", # Memory mode (default: "full")
search_limit=10, # Max memories to retrieve (default: 10)
search_threshold=0.1, # Similarity threshold 0.0-1.0 (default: 0.1)
system_prompt="Based on previous conversations:\n\n",
inject_mode="auto", # "auto" | "user" | "system" (default: "auto")
storage_drain_timeout=3.0, # Seconds cleanup waits for pending writes (default: 3.0)
)
```
| Parameter | Type | Default | Description |
| ------------------ | ----- | -------------------------------------- | ------------------------------------------------------------ |
| `search_limit` | int | 10 | Maximum number of memories to retrieve per query |
| `search_threshold` | float | 0.1 | Minimum similarity threshold for memory retrieval |
| `mode` | str | "full" | Memory retrieval mode: `"profile"`, `"query"`, or `"full"` |
| `system_prompt` | str | "Based on previous conversations, I recall:\n\n" | Prefix text for memory context |
| `inject_mode` | str | "auto" | Where search results go: `"auto"` or `"user"` append them to the user message, `"system"` rewrites them into the system prompt. The profile always goes in the system prompt |
| `storage_drain_timeout` | float | 3.0 | Seconds cleanup waits for pending conversation writes |
## Injection modes
The `inject_mode` parameter controls where per-turn search results are added. The profile block always goes in the system message.
| Mode | Behavior |
| ---------- | -------- |
| `"auto"` | Default. Same as `"user"`, for text and voice pipelines alike. |
| `"user"` | Appends each turn's search results once to that turn's user message. The system prompt and earlier turns never change, so prompt caching keeps working. |
| `"system"` | Rewrites this integration's search block in the system prompt on every user turn, next to the profile block (blocks never stack). The system prompt changes each turn, so prompt caching does not apply. |
## Speech-to-speech models (Gemini Live, etc.)
Pipecat's Gemini Live and OpenAI Realtime services read only the first context they receive (Pipecat 0.0.98 through 1.7.0). Apart from reconnects, later context frames only forward new tool results, so neither a changed system message nor a new text user message reaches the model mid-session, whichever `inject_mode` you use.
The default configuration still gives these models the user profile: it is fetched on the first context frame, before the first user message, and is part of the system instruction the session starts with. Per-turn search results do not reach them. If you pass `system_instruction=` to `GeminiLiveLLMService`, Pipecat 1.x uses it instead of the context's system message, so put your prompt in the `LLMContext` instead:
```python
from supermemory_pipecat import SupermemoryPipecatService
memory = SupermemoryPipecatService(
api_key=os.getenv("SUPERMEMORY_API_KEY"),
user_id="unique_user_id",
)
context = LLMContext([{"role": "system", "content": "You are a helpful assistant."}])
```
## Example: Voice agent with memory
Here's a complete example of a Pipecat voice agent with Supermemory integration:
```python
import os
from fastapi import FastAPI, WebSocket
from fastapi.middleware.cors import CORSMiddleware
from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineTask
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
from pipecat.serializers.protobuf import ProtobufFrameSerializer
from pipecat.services.openai.llm import OpenAILLMService
from pipecat.services.openai.tts import OpenAITTSService
from pipecat.services.openai.stt import OpenAISTTService
from pipecat.transports.websocket.fastapi import (
FastAPIWebsocketParams,
FastAPIWebsocketTransport,
)
from supermemory_pipecat import InputParams, SupermemoryPipecatService
app = FastAPI()
SYSTEM_PROMPT = """You are a helpful voice assistant with memory capabilities.
You remember information from past conversations and use it to provide personalized responses.
Keep responses brief and conversational."""
async def run_bot(websocket_client, user_id: str, session_id: str):
transport = FastAPIWebsocketTransport(
websocket=websocket_client,
params=FastAPIWebsocketParams(
audio_in_enabled=True,
audio_out_enabled=True,
vad_enabled=True,
vad_analyzer=SileroVADAnalyzer(),
vad_audio_passthrough=True,
serializer=ProtobufFrameSerializer(),
),
)
stt = OpenAISTTService(api_key=os.getenv("OPENAI_API_KEY"))
llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-5-mini")
tts = OpenAITTSService(api_key=os.getenv("OPENAI_API_KEY"), voice="alloy")
# Supermemory memory service
memory = SupermemoryPipecatService(
user_id=user_id,
session_id=session_id,
params=InputParams(
mode="full",
search_limit=10,
search_threshold=0.1,
),
)
context = LLMContext([{"role": "system", "content": SYSTEM_PROMPT}])
context_aggregator = LLMContextAggregatorPair(context)
pipeline = Pipeline([
transport.input(),
stt,
context_aggregator.user(),
memory,
llm,
tts,
transport.output(),
context_aggregator.assistant(),
])
task = PipelineTask(pipeline)
@transport.event_handler("on_client_disconnected")
async def on_client_disconnected(transport, client):
await task.cancel()
runner = PipelineRunner(handle_sigint=False)
await runner.run(task)
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
await run_bot(websocket, user_id="alice", session_id="session-123")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
```
## Example: Gemini Live with memory
For a complete example using Gemini Live speech-to-speech with Supermemory, check out the reference implementation:
<Card
title="Pipecat Memory Example"
icon="/images/github-icon.svg"
href="https://github.com/supermemoryai/pipecat-memory"
>
Full working example with Gemini Live, including frontend and backend code.
</Card>