Skip to main content
Plug Synap into NVIDIA NeMo Agent Toolkit (NAT) as a first-class MemoryEditor. NAT workflows that declare a memory backend in YAML (or instantiate one programmatically) get persistent, semantically searchable, per-user memory. Two more YAML components report each run to Synap and send an agent Synap’s compacted history instead of its earlier turns.
Requires Python 3.11 to 3.13.

Overview

This guide shows how to add Synap to a NAT workflow to build pipelines that:
  • Persist MemoryItem objects across workflow executions
  • Retrieve memories via semantic search inside any NAT step
  • Be declared in NAT’s YAML config without writing additional integration code
  • Report every run (turns, tool calls, tool results) to Synap
  • Give an agent Synap’s compaction in place of its earlier turns
The package registers four components with NAT through its nat.components entry point, so there is no registration code to write: The three non-memory components each have a ...Config class too (SynapStreamExporterConfig, SynapHistoryMiddlewareConfig, SynapShortTermConfig).

Setup

Install the package. It requires Python 3.11 to 3.13, and brings in NAT itself (nvidia-nat-core 1.0 or later), maximem-synap (0.5.3 or later) and maximem-synap-integrations-common (0.2.3 or later) as dependencies:
Do not run pip install nat. The package named nat on PyPI is an unrelated project, and installing it breaks from nat.memory.models import MemoryItem.
The pip package is maximem-synap-nemo-agent-toolkit, but the import drops the maximem- prefix and uses underscores: from synap_nemo_agent_toolkit import ....
Configure your API key. Generate one from the Synap Dashboard.
.env
Initialize the SDK once at application startup:
Alternatively, wire the components in YAML (below) to skip the SDK setup; they build and initialize one shared SDK for you. See SDK Initialization for the full lifecycle and configuration options.

Basic integration

The smallest useful integration constructs a SynapMemoryEditor and uses it directly:
Notice that user_id is supplied per item and per query: a single SynapMemoryEditor instance serves all users in the workflow. customer_id is set once at construction.

Core concepts

MemoryEditor interface

SynapMemoryEditor implements the full MemoryEditor protocol. NAT workflows that accept a MemoryEditor work without modification:
The two retrieval modes trade latency against comprehensiveness: 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. Reads degrade gracefully: search returns an empty list and logs an error on a Synap outage. Writes surface failures: add_items raises SynapIntegrationError so workflows know if persistence failed. NAT’s auto_memory_agent hands the editor every user and assistant message as a conversation-only MemoryItem. The editor records each one as a conversation turn (on the real-time stream, or over REST when the stream cannot carry it), under NAT’s own conversation id for the run. Synap extracts memories from the conversation it keeps, so writing the same turns again as documents would extract them twice. A turn that the synap_stream exporter already wrote is skipped, one for one. A turn that cannot be recorded falls back to a document, so nothing is lost.

Wire it in YAML

NAT loads the Synap components from the package’s entry point, so declaring them in YAML is enough. The memory backend goes under memory: with _type: synap_memory:
The config takes customer_id, mode, document_type (default ai-chat-conversation), and optionally api_key and instance_id. Leave api_key out and the component reads SYNAP_API_KEY from the environment; do not put a key in the file. Every Synap component in a process shares one SDK per set of credentials. The first to start builds and initializes it, the last to stop shuts it down, so the real-time stream that the exporter opens also serves the reads of the memory backend and the history middleware.

Report each run to Synap

Add the synap_stream exporter under general.telemetry.tracing. Nothing in the workflow changes:
The exporter turns NAT’s own events into Synap events: the start of a run is the user’s turn, the end of a run is the assistant’s turn, and each tool start and end is a tool call and a tool result. The model outputs that came before the final answer are reported as reasoning. The user and conversation ids come from NAT’s context for the run; user_id and conversation_id in the config are fallbacks for when NAT has none. You do not call listen(). The exporter opens the stream when the workflow starts, so what the stream brings back is there for the first fetch. If the stream cannot open, the user and assistant turns are written over REST, which needs a conversation id (NAT’s, else the configured one), and tool calls, tool results and reasoning, which exist only on the stream, are dropped. Set SYNAP_AUTO_LISTEN=false to stay on REST. On shutdown the exporter waits up to drain_timeout_s seconds (5 by default) for queued events to reach Synap.

Send an agent Synap’s compaction

NAT agents are handed the conversation as a request and keep the last max_history messages of it. The synap_history middleware changes what the agent is handed. Once Synap has compacted the conversation, every message before the current one is replaced by Synap’s compaction block (in <synap_conversation_history> tags) and the turns after it. The current turn is untouched. Before the first compaction, or if Synap cannot answer, the agent gets the request as it was, and its own trimming stays in place as the fallback. Declare the middleware, then list it on the agent function. This is not on by default:
The conversation id is NAT’s own for the run (set by the HTTP front end or by session.run). The conversation_id in the middleware config is only a fallback; with neither, the input is left as it is. The id must be a UUID.

Short-term context as a function

synap_short_term registers a function that returns Synap’s short-term context for a conversation as a string, ready to template into a prompt:
Once Synap has compacted the conversation it returns the compaction alone, because an agent already receives the recent turns in its request; before that it returns the compacted summary and recent turns. Pin a conversation_id in the config, or pass one per call. On an SDK error it returns an empty string, or raises SynapIntegrationError with on_error: raise. To replace the agent’s own earlier turns, use synap_history instead.

Complete example: NAT workflow with persistent memory

The pattern below sets up a workflow with Synap-backed memory at startup, ingests a batch of memories, and runs a recall query:
Three things to notice in this pattern:
  1. One editor, many users. user_id travels on each MemoryItem and each search call, so the editor is shared.
  2. customer_id is the tenant boundary. All users sharing an editor are inside the same customer_id, so build a separate editor per tenant for multi-tenant services.
  3. Mode is fixed at construction. Set mode="fast" for low-latency NAT steps; "accurate" for higher-recall lookups.

Advanced patterns

Multi-tenant scoping

SynapMemoryEditor takes customer_id at construction; user_id is supplied per call. 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.

Choosing between SDK-managed and YAML-managed lifecycles

  • Use SynapMemoryEditor(sdk=...) when your application owns the SDK lifecycle (recommended for production, since you control init/shutdown).
  • Use the YAML components for workflows where you would rather not manage the SDK explicitly; they share one SDK per set of credentials.

Failure semantics

The integration follows the Synap-wide contract:
  • search degrades gracefully: returns an empty list and logs an error if Synap is unreachable.
  • add_items surfaces failures: raises SynapIntegrationError so the workflow and caller know persistence failed.
  • The exporter and the middleware never raise. The exporter logs and carries on; the middleware leaves the agent’s input alone on any error.
This is by design: read failures shouldn’t break a workflow step mid-flight, but silent write failures would corrupt the memory pool.

Going further


Next steps

Semantic Kernel

Plugin for Microsoft Semantic Kernel.

Pydantic AI

Type-safe deps and tools for Pydantic AI.

Memory Scopes

How user_id and customer_id interact across reads and writes.

Ingestion

Direct ingestion API for pipelines that need finer control than add_items.