> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maximem.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Maximem Synap is a managed memory layer for AI agents: it ingests conversations and documents, extracts structured memory, and returns scoped context to the agent at retrieval time.
> The Python and JavaScript/TypeScript SDKs are the supported way to use Synap. Write integration code with SDK calls, not raw HTTP requests.
> Start with the Quickstart: https://docs.maximem.ai/getting-started/quickstart.md. Every SDK method is documented in the SDK reference: https://docs.maximem.ai/sdk-reference/overview.md.
> For requests about adding Vity memory to OpenClaw, Hermes, an MCP client, or a browser, start with the Vity Quickstart: https://docs.maximem.ai/vity/quickstart.md.

# Pipecat

> Frame processors that add memory injection, turn and tool-call recording, and compacted history to Pipecat voice pipelines.

Add persistent memory to a Pipecat voice pipeline as frame processors: one that injects the user's relevant memories into the shared LLM context before each reply, and one that records each completed turn, with its tool calls, after the response and replaces a long call's earlier turns with Synap's compaction.

> [!NOTE]
>
> Requires Python 3.11+ and `pipecat-ai` 0.0.80 or later, with the universal context aggregators (`LLMContext`).

## Overview

This guide shows how to add Synap to a Pipecat application to build voice pipelines that:

* Inject the most relevant memories as a system message before the LLM responds
* Record each completed user + assistant turn, and each tool call, back to Synap
* Send the LLM Synap's compaction in place of a long call's earlier turns
* Compose with any other Pipecat frame processor without changing the pipeline shape

The Synap Pipecat integration ships three frame processors and one helper. They follow Pipecat's processor contract, so they slot into any pipeline alongside STT, LLM, and TTS. All of them work on the shared `LLMContext` that your aggregators use, so pass it in as `context=`.

| Class | Pipeline position | Purpose |
| - | - | - |
| `SynapMemoryProcessor` | Before the user aggregator | Adds relevant memories to the shared context as a system message |
| `SynapRecorder` | After the assistant aggregator | Records the completed turn and its tool calls, then replaces earlier turns with Synap's compaction |
| `SynapShortTermProcessor` | Before the user aggregator | Adds Synap's short-term context, or applies its compaction, before each user turn |
| `splice_synap_history` | Helper | Replaces the earlier turns in an `LLMContext` with Synap's compaction, in place |

## Setup

Install the package alongside Pipecat. It also installs `maximem-synap` (0.5.3 or later) and `maximem-synap-integrations-common` (0.2.3 or later):

```bash pip theme={null}
pip install maximem-synap-pipecat pipecat-ai
```

```bash uv theme={null}
uv add maximem-synap-pipecat pipecat-ai
# pip-compatible (existing venv): uv pip install maximem-synap-pipecat pipecat-ai
```

> [!NOTE]
>
> The pip package is `maximem-synap-pipecat`, but the import drops the `maximem-` prefix and uses underscores: `from synap_pipecat import ...`.

Configure your API key. Generate one from the [Synap Dashboard](https://synap.maximem.ai).

```bash .env theme={null}
SYNAP_API_KEY=synap_your_key_here
OPENAI_API_KEY=your-openai-api-key
```

Initialize the SDK once at the worker's startup:

```python theme={null}
from maximem_synap import MaximemSynapSDK

sdk = MaximemSynapSDK()
await sdk.initialize()
```

See [SDK Initialization](https://docs.maximem.ai/sdk/initialization.md) for the full lifecycle and configuration options.

## Basic integration

The smallest useful integration shares one `LLMContext` between the aggregators and the Synap processors: memory injection before the user aggregator, recording after the assistant aggregator:

```python theme={null}
# pip install maximem-synap-pipecat pipecat-ai
import uuid
from maximem_synap import MaximemSynapSDK
from pipecat.pipeline.pipeline import Pipeline
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
from synap_pipecat import SynapMemoryProcessor, SynapRecorder

sdk = MaximemSynapSDK()
await sdk.initialize()

context = LLMContext(messages=[{"role": "system", "content": "You are a voice assistant."}])
aggregators = LLMContextAggregatorPair(context)

memory = SynapMemoryProcessor(
    sdk=sdk,
    user_id="alice",
    customer_id="acme",   # optional, required for B2B instances
    context=context,
    max_results=6,
)

# A UUID, so Synap can read the compacted conversation back.
recorder = SynapRecorder(
    sdk=sdk,
    user_id="alice",
    customer_id="acme",
    conversation_id=str(uuid.uuid4()),
    context=context,
)

pipeline = Pipeline([
    transport.input(),
    stt,
    memory,                 # inject memory before the user aggregator
    aggregators.user(),
    llm,
    tts,
    transport.output(),
    aggregators.assistant(),
    recorder,               # record the turn after the response
])
```

**Memory injection failures degrade gracefully**: the frame passes through unmodified if context retrieval fails. **A turn that cannot be written** is logged and reported as an `ErrorFrame` pushed upstream; it does not stop the pipeline.

***

## Core concepts

### Memory processor

`SynapMemoryProcessor` acts on each `TranscriptionFrame`. It fetches the user's relevant memories for the transcribed text and puts them in the shared `LLMContext` as one system message, then passes the frame on unchanged so the user aggregator still sees it. Each turn replaces the previous memory block, so the context never accumulates stale blocks over a long call.

```python theme={null}
from synap_pipecat import SynapMemoryProcessor

memory = SynapMemoryProcessor(
    sdk=sdk,
    user_id="alice",
    customer_id="acme",
    context=context,
    max_results=6,
    mode="fast",          # "fast" or "accurate"; the default is "accurate"
)
```

Without `context=` the processor is inert: frames pass through and nothing is injected. You can attach the context later with `memory.set_context(context)`.

The default is `mode="accurate"` with `max_results=10`. Voice latency is tight, so pass `mode="fast"` when the added wait before the reply matters. The two retrieval modes trade latency against comprehensiveness:

| | `fast` | `accurate` |
| - | - | - |
| Search | Vector search (no graph traversal, no LLM subquery decomposition) | Vector search + graph traversal + LLM subquery decomposition + reranking |
| Best for | Real-time chat | Multi-entity queries |

`fast` is lower-latency and suited to the hot path; `accurate` adds LLM-driven query decomposition and reranking for relationship-aware queries at a higher latency cost.

**Failures degrade gracefully**: if context retrieval fails, the frame passes through and the context is left as it was.

### Recorder

`SynapRecorder` records the completed user and assistant turn at the end of each response. Pass the shared `context=`: behind the universal aggregators the user's `TranscriptionFrame` never reaches the recorder, so it reads the user turn back from the context.

```python theme={null}
from synap_pipecat import SynapRecorder

recorder = SynapRecorder(
    sdk=sdk,
    user_id="alice",
    customer_id="acme",
    conversation_id=str(uuid.uuid4()),
    context=context,
)
```

* **Where it sits decides what it sees.** After the assistant aggregator (the standard position), the recorder gets one end-of-turn frame carrying the assistant text as stored in the context, and records both turns from that. It also reads the turn's tool calls and results back out of the context and reports them, just before the reply they led to. Reasoning is not recoverable there. To get each tool call at the moment it is dispatched, and reasoning from models that emit it, put the recorder before the assistant aggregator, for example right after the LLM service.
* **Real-time stream.** You do not call `listen()`. The first turn opens the stream, and the turns go out on it. If the stream cannot open, each turn is written over REST instead, never both; tool calls and reasoning exist only on the stream and are dropped in that case. Set `SYNAP_AUTO_LISTEN=false` to stay on REST, or open the stream yourself and the recorder uses it as is. See [gRPC vs REST](https://docs.maximem.ai/concepts/grpc-vs-rest.md#framework-integrations).
* **Failures.** A turn that cannot be written is logged, and an `ErrorFrame` carrying a `SynapIntegrationError` is pushed upstream so observability hooks see it. The recorder never raises inside `process_frame`.

On `pipecat-ai` 1.7 and later the assistant aggregator lets one end-of-turn frame through, and the recorder uses it. On earlier versions the recorder ends the turn on `LLMFullResponseEndFrame`.

Left out, `conversation_id` is a new random UUID for each session (0.2.3 or later; earlier versions generated an id that was not a UUID, which Synap rejected for reads and REST writes). Pass your own UUID to continue one conversation across sessions.

### Compacted history

A Pipecat `LLMContext` only grows unless you turn on Pipecat's own auto-summarization, which is off by default. When you pass `context=` to the recorder, then after it records each turn, and once Synap has compacted the conversation, it replaces every turn before the current one in the shared context with Synap's compaction block (in `<synap_conversation_history>` tags) and the turns after it. The next LLM request carries that instead of every turn so far. The current turn is untouched.

This runs one turn later than a fetch before each request, and off the latency path, because it happens after the turn has been recorded. Before the first compaction, or when Synap cannot answer, the context is left as the aggregators built it, and Pipecat's own summarization, if you turned it on, stays the fallback. A voice call cannot wait on a slow read: if Synap takes longer than 1.5 seconds, the read is skipped and not tried again for 30 seconds.

`splice_synap_history(context, sdk, conversation_id=...)` does the same replacement on demand, in place, and returns whether it changed anything.

### Short-term context

`SynapShortTermProcessor` goes in the same position as the memory processor, before the user aggregator. On each user turn it reads Synap's short-term context for the conversation. Once Synap has compacted the conversation, it replaces the context's earlier turns with the compaction, as above, but before the request rather than after the previous turn. Before that, it keeps one tagged system message in the context with the turns the context does not already hold.

```python theme={null}
from synap_pipecat import SynapShortTermProcessor

short_term = SynapShortTermProcessor(
    sdk,
    conversation_id=conversation_id,   # a UUID, required
    context=context,
)
```

Without `context=` it is inert. On an SDK error it leaves the context untouched; pass `on_error="raise"` to get `SynapIntegrationError` instead. The read adds to the wait before each reply, so prefer the recorder's replacement unless you need the context current on the very next request.

### Positioning in the pipeline

The processors expect specific positions:

```text theme={null}
transport.input()
    │
    ▼
   STT
    │
    ▼
SynapMemoryProcessor  ← fetches memories, adds them to the shared context
    │
    ▼
 UserAggregator
    │
    ▼
   LLM
    │
    ▼
   TTS
    │
    ▼
transport.output()
    │
    ▼
AssistantAggregator
    │
    ▼
 SynapRecorder        ← records the completed turn, then compacts the context
```

`SynapMemoryProcessor` must be between STT and the user aggregator, because it acts on the `TranscriptionFrame` the aggregator consumes. `SynapRecorder` goes after the assistant aggregator, or before it if you want dispatch-time tool calls and reasoning (see above).

***

## Complete example: full voice pipeline with memory

The pattern below sets up an end-to-end voice pipeline with Synap-backed memory. Scope is pulled per-call, so the same worker can serve multiple users:

```python theme={null}
import uuid
from pipecat.pipeline.pipeline import Pipeline
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.services.openai.llm import OpenAILLMService
from synap_pipecat import SynapMemoryProcessor, SynapRecorder


async def build_pipeline(sdk, transport, user_id: str, customer_id: str | None = None) -> Pipeline:
    stt = ...   # your STT service
    llm = OpenAILLMService(model="gpt-4o")
    tts = ...   # your TTS service

    context = LLMContext(messages=[{"role": "system", "content": "You are a voice assistant."}])
    aggregators = LLMContextAggregatorPair(context)

    memory = SynapMemoryProcessor(
        sdk=sdk,
        user_id=user_id,
        customer_id=customer_id,
        context=context,
        max_results=6,
        mode="fast",
    )

    recorder = SynapRecorder(
        sdk=sdk,
        user_id=user_id,
        customer_id=customer_id,
        conversation_id=str(uuid.uuid4()),
        context=context,
    )

    return Pipeline([
        transport.input(),
        stt,
        memory,
        aggregators.user(),
        llm,
        tts,
        transport.output(),
        aggregators.assistant(),
        recorder,
    ])


# Usage: invoked per call; transport is your Pipecat transport for the call
async def run_call(sdk, transport, user_id: str, customer_id: str | None = None):
    pipeline = await build_pipeline(sdk, transport, user_id=user_id, customer_id=customer_id)
    task = PipelineTask(pipeline)
    await task.run()
```

Three things to notice in this pattern:

1. **Memory injection happens once per user turn**, not once per audio frame; the processor only acts on the final `TranscriptionFrame`.
2. **Recording is async and non-blocking.** The audio path never waits on a Synap write.
3. **Scope is per-call.** Each `run_call` invocation gets its own processor instances with the right `user_id` / `customer_id`.

***

## Advanced patterns

### Multi-tenant scoping

The memory processor and the recorder take `user_id` (required) and `customer_id` (B2B instances only); the recorder also takes an optional `conversation_id`, and the short-term processor requires one. `customer_id` is required on B2B Synap instances and **not accepted** on B2C (single-tenant) ones, where a call carrying it is rejected with HTTP 400. See [Memory Scopes](https://docs.maximem.ai/concepts/memory-scopes.md).

```python theme={null}
memory = SynapMemoryProcessor(sdk=sdk, user_id="alice", customer_id="acme", context=context)
```

For multi-tenant deployments, build processors per call rather than caching them globally; each call should have its scope baked in.

### Tuning retrieval mode

`mode="accurate"` is the default. For most voice flows pass `mode="fast"` to keep the wait before each reply short, and switch to `"accurate"` only for use cases where missing relevant memory is worse than the additional pre-LLM latency that LLM-driven query decomposition and reranking add.

### Failure semantics

The integration follows the Synap-wide contract, adapted for voice latency:

* **`SynapMemoryProcessor` degrades gracefully**: the frame passes through unmodified and the context is left alone if retrieval fails.
* **`SynapRecorder` reports failures as frames**: a turn that cannot be written is logged and pushed upstream as an `ErrorFrame` carrying a `SynapIntegrationError`; Pipecat's contract is frames, not raised exceptions.
* **The compacted-history replacement leaves the context alone** whenever Synap has no compaction, is slow or errors.

This is by design: a voice call should never break because of a transient memory glitch, but write failures must be visible to monitoring.

***

## Going further

* [Voice agent pattern](https://docs.maximem.ai/patterns/voice-agent-livekit.md): the reference architecture for memory-backed voice agents.
* [Voice concierge cookbook](https://docs.maximem.ai/cookbook/voice-concierge.md): an end-to-end worked voice example.

***

## Next steps

> [card] [LiveKit Agents](https://docs.maximem.ai/integrations/livekit-agents.md)
>
> Context preloading and recording for LiveKit voice agents.

> [card] [Claude Agent SDK](https://docs.maximem.ai/integrations/claude-agent.md)
>
> Hooks and MCP server for the Claude Agent SDK.

> [card] [Context Fetch](https://docs.maximem.ai/sdk/context-fetch.md)
>
> The retrieval API behind `SynapMemoryProcessor`: modes, scopes, and response shapes.

> [card] [Memory Scopes](https://docs.maximem.ai/concepts/memory-scopes.md)
>
> How `user_id`, `customer_id`, and `conversation_id` interact across reads.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.