examples: add Synap memory integration example#327
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new TypeScript example demonstrating how to integrate Synap as a persistent, cross-session memory layer for a Claude Agent, using both hook-based automatic context injection and MCP tool-based explicit memory operations.
Changes:
- Added
examples/synap-memory.tsshowcasingcreateSynapHooksandcreateSynapMcpServerusage withquery(). - Documented basic install steps and required Synap environment configuration in the example header.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } from "@maximem/synap-claude-agent"; | ||
|
|
||
| async function main(): Promise<void> { | ||
| const sdk = new MaximemSynapSDK({ apiKey: process.env.SYNAP_API_KEY! }); |
| * Set SYNAP_API_KEY in your environment. Get a free key at | ||
| * https://synap.maximem.ai. |
| import { query } from "@anthropic-ai/claude-agent-sdk"; | ||
| import { MaximemSynapSDK } from "@maximem/synap-sdk"; | ||
| import { | ||
| createSynapHooks, | ||
| createSynapMcpServer, | ||
| } from "@maximem/synap-claude-agent"; | ||
|
|
||
| async function main(): Promise<void> { | ||
| const sdk = new MaximemSynapSDK({ apiKey: process.env.SYNAP_API_KEY! }); | ||
| await sdk.initialize(); | ||
|
|
||
| const userId = "demo-user-001"; | ||
| const customerId = "demo-customer"; | ||
|
|
||
| // Pattern 1 — automatic context injection via hook | ||
| console.log("=== Hook-based context injection ==="); | ||
| for await (const message of query({ | ||
| prompt: "What did I tell you about my dietary preferences?", | ||
| options: { | ||
| hooks: createSynapHooks({ sdk, userId, customerId }), | ||
| }, | ||
| })) { | ||
| console.log(message); | ||
| } | ||
|
|
||
| // Pattern 2 — explicit search / remember via MCP tools | ||
| console.log("\n=== MCP tool-based memory access ==="); | ||
| for await (const message of query({ | ||
| prompt: "Remember that I prefer concise answers, then search my memory.", | ||
| options: { | ||
| mcpServers: { | ||
| synap: createSynapMcpServer({ sdk, userId, customerId }), | ||
| }, | ||
| allowedTools: [ | ||
| "mcp__synap__synap_search", | ||
| "mcp__synap__synap_remember", | ||
| ], | ||
| }, | ||
| })) { | ||
| console.log(message); | ||
| } | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
|
Hi @ddworken and @ashwin-ant 👋 — friendly follow-up on this whenever you have a moment! This adds I addressed Copilot's review on the latest push: style now matches the repo (single quotes, no semicolons), env vars are validated at runtime instead of using non-null assertion, and Paired with the Python sibling: anthropics/claude-agent-sdk-python#954. Thanks! |
|
Hi @ddworken @ashwin-ant 👋 — final gentle nudge on this one. Since the original filing, the Synap SDK has been merged into Pipecat, NVIDIA NeMo Agent Toolkit, Google ADK docs, Haystack integrations, and two Awesome-AI-Memory lists — so the underlying integration is battle-tested and the pattern is proven. Would love a review whenever you get a moment. Happy to close it out if the timing isn't right — just let me know either way. Thanks! |
Summary
Adds
examples/synap-memory.tsshowing how to give a Claude Agent persistent, cross-session memory via Synap, using both plug points:createSynapHooks— UserPromptSubmit hook that fetches Synap context and injects it viaadditionalContextcreateSynapMcpServer— exposessynap_search/synap_rememberas MCP tools the model can call explicitlyThe package is published on npm as
@maximem/synap-claude-agent. Source code lives in our open source repo: https://github.com/maximem-ai/maximem_synap_sdk/tree/main/packages/integrations/synap-claude-agent-tsPaired with the Python sibling PR: anthropics/claude-agent-sdk-python#954
Test plan
SYNAP_API_KEYsetsynap_search/synap_rememberare callable