Skip to main content
Add persistent, per-user memory to a Semantic Kernel application as a single plugin. Both kernel functions (search_memory and store_memory) are auto-invokable, so the kernel can decide when to query or persist memories on its own.
Requires Python 3.11+.

Overview

This guide shows how to add Synap to a Semantic Kernel application to build kernels that:
  • Recall user-specific facts, preferences, and past conversations
  • Persist new information surfaced during a conversation
  • Auto-invoke memory functions when the model decides they are relevant
The Synap Semantic Kernel integration ships a single plugin class with two kernel functions.

Setup

Install the package alongside Semantic Kernel:
The pip package is maximem-synap-semantic-kernel, but the import drops the maximem- prefix and uses underscores: from synap_semantic_kernel import ....
Configure your API key. Generate one from the Synap Dashboard.
.env
Initialize the SDK once at application startup:
See SDK Initialization for the full lifecycle and configuration options.

Basic integration

The smallest useful integration adds SynapPlugin to a kernel and invokes a prompt that references the plugin’s functions:
The scoping triple (user_id, optional customer_id) is bound when you construct the plugin. The kernel functions only ever see query, content, and other model-supplied parameters. This prevents prompts (or prompt injections) from spoofing scope. For automatic invocation (the kernel chooses when to call memory functions), enable auto function calling. See “Auto function calling” below.

Core concepts

SynapPlugin

SynapPlugin is a regular Semantic Kernel plugin class with @kernel_function annotated methods. Adding it to the kernel registers both functions under the plugin name you choose:
After registration, the kernel can invoke synap.search_memory and synap.store_memory either through prompt templating, manual invocation, or auto function calling.

search_memory

Function signature exposed to the kernel:
Returns a formatted string of results, suitable for direct interpolation into prompt templates. Search failures degrade gracefully: the function returns an empty result string and logs an error so the prompt template renders without breaking.

store_memory

Function signature exposed to the kernel:
Returns "Memory stored successfully." on success. Store failures surface explicitly: the function raises SynapIntegrationError so the kernel (and caller) know if persistence failed.

Complete example: chat function with auto-invoked memory

The following kernel auto-invokes synap.search_memory and synap.store_memory whenever the model decides they are relevant. The application just adds messages to a ChatHistory and the kernel handles the rest:
Three things to notice in this pattern:
  1. FunctionChoiceBehavior.Auto() lets the model drive memory. No prompt-template plumbing; the model calls the right function when it’s the right time.
  2. Scope is per-kernel. build_kernel(...) constructs a fresh kernel per user so concurrent requests cannot bleed scope.
  3. The system message is the policy. Tell the model when to search and when to store; the plugin just enforces it.

Advanced patterns

Multi-tenant scoping

SynapPlugin accepts the standard scoping triple: user_id (required), optional customer_id, optional conversation_id. customer_id is required on B2B Synap instances and ignored on single-tenant ones. See Memory Scopes.
For multi-tenant services, build the plugin (and kernel) per request rather than sharing one across users.

Prompt-template invocation

Outside of auto function calling, you can interpolate plugin calls directly in prompt templates:
This pattern is useful when you want deterministic recall (the function always runs) rather than letting the model decide.

Failure semantics

The integration follows the Synap-wide contract:
  • search_memory degrades gracefully: returns an empty result string and logs an error if Synap is unreachable.
  • store_memory surfaces failures: raises SynapIntegrationError so the kernel and caller know persistence failed.
This is by design: read failures shouldn’t break a user-facing answer, but silent write failures would let the memory drift away from reality.

Going further


Next steps

Microsoft Agent Framework

Context and history providers for MAF agents.

OpenAI Agents

Function tools for the OpenAI Agents SDK.

Context Fetch

The retrieval API behind search_memory: modes, scopes, and response shapes.

Memory Scopes

How user_id and customer_id interact across reads and writes.