Skip to content

examples: add Synap memory integration example#327

Open
visy-ani wants to merge 2 commits into
anthropics:mainfrom
visy-ani:add-synap-memory-example
Open

examples: add Synap memory integration example#327
visy-ani wants to merge 2 commits into
anthropics:mainfrom
visy-ani:add-synap-memory-example

Conversation

@visy-ani

Copy link
Copy Markdown

Summary

Adds examples/synap-memory.ts showing 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 via additionalContext
  • createSynapMcpServer — exposes synap_search / synap_remember as MCP tools the model can call explicitly

The 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-ts

Paired with the Python sibling PR: anthropics/claude-agent-sdk-python#954

Test plan

  • Manually ran the example with SYNAP_API_KEY set
  • Verified hook injection adds Synap context
  • Verified MCP tools synap_search / synap_remember are callable

Copilot AI review requested due to automatic review settings May 14, 2026 10:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts showcasing createSynapHooks and createSynapMcpServer usage with query().
  • 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.

Comment thread examples/synap-memory.ts Outdated
} from "@maximem/synap-claude-agent";

async function main(): Promise<void> {
const sdk = new MaximemSynapSDK({ apiKey: process.env.SYNAP_API_KEY! });
Comment thread examples/synap-memory.ts Outdated
Comment on lines +17 to +18
* Set SYNAP_API_KEY in your environment. Get a free key at
* https://synap.maximem.ai.
Comment thread examples/synap-memory.ts Outdated
Comment on lines +23 to +69
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);
});
@visy-ani

Copy link
Copy Markdown
Author

Hi @ddworken and @ashwin-ant 👋 — friendly follow-up on this whenever you have a moment! This adds examples/synap-memory.ts showing both Claude Agent SDK plug points (UserPromptSubmit hooks + MCP tools) used together for persistent long-term memory via Synap.

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 ANTHROPIC_API_KEY is documented as a prereq.

Paired with the Python sibling: anthropics/claude-agent-sdk-python#954. Thanks!

@visy-ani

Copy link
Copy Markdown
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants