Give an OpenAI Agent persistent, per-user memory by exposing two function tools: one that searches Synap and one that stores new memories. The agent decides when to call each — no hidden injection, no chain modifications.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.
Overview
This guide shows how to add Synap to an OpenAI Agents SDK application to build agents that:- Recall user-specific facts, preferences, and past conversations
- Persist new information surfaced during a conversation for future runs
- Stay fully in control of when memory is queried or written
FunctionTool.
| Export | Returns | Purpose |
|---|---|---|
create_search_tool | async (query, max_results) -> list[dict] | Function tool that searches Synap memory |
create_store_tool | async (content, memory_type) -> dict | Function tool that stores a memory in Synap |
Setup
Install the package alongside the OpenAI Agents SDK:.env
Basic integration
The smallest useful integration registers both tools on an agent and runs a query. The agent reads its tool descriptions, decides whether to search or store, and calls the matching function:user_id, optional customer_id) is bound when you construct the tool — the agent only ever sees the query and content parameters, never the user identity. This keeps the model from leaking or spoofing user IDs.
Core concepts
Search tool
create_search_tool returns an async callable that takes a natural-language query and returns a list of memory objects.
{"content": "...", "type": "fact", "confidence": 0.91}. The agent sees the JSON list and can quote or reason over the entries directly.
Search failures degrade gracefully — the tool returns an empty list and logs an error, so the agent continues without recall rather than aborting.
Store tool
create_store_tool returns a companion callable that ingests a new memory.
{"status": "stored", "id": "..."} on success. Store failures surface explicitly — the tool raises SynapIntegrationError so the agent (and you) know if persistence failed.
Complete example: assistant with explicit memory control
The following agent is told to consult its memory before answering and store anything the user shares. The Synap calls only happen when the model elects to invoke the tools:- The agent owns the memory loop. Search and store calls are model-driven, not framework-driven — the prompt steers the behavior.
- Scope is bound at construction. The model never sees
user_idorcustomer_id, so even a prompt-injection attempt cannot make it query memories for someone else. - Failure modes split. Search is best-effort (empty list on failure); store is strict (raises on failure) so silent data loss is impossible.
Advanced patterns
Multi-tenant scoping
Both factories accept the same scoping triple —user_id (required), optional customer_id. customer_id is required on B2B Synap instances and ignored on single-tenant ones. See Memory Scopes.
Per-request scoping
If your service handles many users in one process, build a fresh pair of tools per request rather than caching them — each agent run should have its scope baked in to prevent cross-user leakage:Failure semantics
The integration follows the Synap-wide contract:- Search failures degrade gracefully —
synap_searchreturns[]and logs an error so the agent can continue. - Store failures surface explicitly —
synap_storeraisesSynapIntegrationErrorso the agent (and caller) know persistence failed.
Next steps
Pydantic AI
Type-safe deps and tools for Pydantic AI agents.
AutoGen
BaseTool implementations for AutoGen agents.Context Fetch
The retrieval API that powers
synap_search — modes, scopes, and response shapes.Memory Scopes
How
user_id and customer_id interact across reads and writes.