Skip to content

Python: samples: add Synap context provider example#5620

Open
visy-ani wants to merge 5 commits intomicrosoft:mainfrom
visy-ani:add-synap-context-provider
Open

Python: samples: add Synap context provider example#5620
visy-ani wants to merge 5 commits intomicrosoft:mainfrom
visy-ani:add-synap-context-provider

Conversation

@visy-ani
Copy link
Copy Markdown

@visy-ani visy-ani commented May 4, 2026

Adds a sample demonstrating SynapContextProvider — a Microsoft Agent Framework ContextProvider backed by Synap, a managed memory layer for AI agents.

What's included

  • python/samples/02-agents/context_providers/synap/synap_basic.py — basic usage showing context injection and turn recording
  • python/samples/02-agents/context_providers/synap/README.md — setup and run instructions

How SynapContextProvider works

  • before_run: fetches Synap context relevant to the user's input and appends it to the agent's instructions via context.extend_instructions(...)
  • after_run: records input and response messages to Synap via sdk.conversation.record_message(...) for future retrieval

Read failures degrade gracefully (log + skip). Write failures are logged but never re-raised — the agent run always completes. This matches the contract established by Mem0ContextProvider.

Memory is scoped to user_id and customer_id, ensuring strict isolation in multi-tenant applications.

Install: pip install maximem-synap-microsoft-agent
PyPI: https://pypi.org/project/maximem-synap-microsoft-agent/
Docs: https://docs.maximem.ai/integrations/microsoft-agent
Open source: Integration package source at maximem-ai/maximem_synap_sdk — contributions welcome

Copilot AI review requested due to automatic review settings May 4, 2026 09:07
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels May 4, 2026
@github-actions github-actions Bot changed the title samples: add Synap context provider example Python: samples: add Synap context provider example May 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 Python sample under the context provider samples to demonstrate integrating SynapContextProvider as a managed long-term memory source for Agent Framework agents.

Changes:

  • Adds synap_basic.py to show wiring a Synap SDK instance and context provider into an agent flow.
  • Adds a sample README with setup, run steps, and external Synap documentation links.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
python/samples/02-agents/context_providers/synap/synap_basic.py New sample script intended to demonstrate Synap-backed context injection and memory recall across runs.
python/samples/02-agents/context_providers/synap/README.md New documentation describing the sample, setup steps, execution command, and related resources.

Comment on lines +26 to +30
async with Agent(
name="MemoryAssistant",
instructions="You are a helpful assistant with long-term memory.",
context_providers=[provider],
) as agent:
Comment on lines +20 to +24
provider = SynapContextProvider(
sdk=sdk,
user_id=user_id,
customer_id="acme_corp",
)
Comment on lines +21 to +24
## Run

```bash
python synap_basic.py
@visy-ani
Copy link
Copy Markdown
Author

visy-ani commented May 4, 2026

@microsoft-github-policy-service agree [company="Maximem"]

@visy-ani
Copy link
Copy Markdown
Author

visy-ani commented May 4, 2026

@microsoft-github-policy-service agree company=Maximem

@visy-ani
Copy link
Copy Markdown
Author

visy-ani commented May 4, 2026

Hi @moonbox3 and @eavanvalkenburg — would appreciate a review when you get a chance! This adds a SynapContextProvider sample showing persistent cross-session memory with the Microsoft Agent Framework.

Copilot-flagged issues are now resolved: replaced the random uuid.uuid4() user ID (which broke cross-session persistence) with a stable "demo-user-001", and replaced the hardcoded API key placeholder with os.environ["SYNAP_API_KEY"]. Thanks!

@sphenry
Copy link
Copy Markdown
Member

sphenry commented May 5, 2026

@visy-ani normally we prefer for this type of integration to live in a separate repo, and we can link from our docs

@visy-ani
Copy link
Copy Markdown
Author

visy-ani commented May 5, 2026

Got it, thanks @sphenry . The code already lives in our repo and is published as maximem-synap-microsoft-agent on PyPI. I'd be happy to convert this PR into a docs-only change that just links to it from your community integrations page , would that work? Just point me at the right file and I'll update the PR.

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

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants