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
MemoryItemobjects 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
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:
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 .....env
Basic integration
The smallest useful integration constructs aSynapMemoryEditor and uses it directly:
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 undermemory: with _type: synap_memory:
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 thesynap_stream exporter under general.telemetry.tracing. Nothing in the workflow changes:
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 lastmax_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:
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:
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:- One editor, many users.
user_idtravels on eachMemoryItemand eachsearchcall, so the editor is shared. customer_idis the tenant boundary. All users sharing an editor are inside the samecustomer_id, so build a separate editor per tenant for multi-tenant services.- 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:searchdegrades gracefully: returns an empty list and logs an error if Synap is unreachable.add_itemssurfaces failures: raisesSynapIntegrationErrorso 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.
Going further
- Patterns overview: reusable memory patterns across frameworks.
- Cookbook overview: end-to-end worked examples.
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.