Skip to content

.NET: added Mem0Sharp integration for in-memory storage in agent samples. - #7792

Open
Jay Khawaja (jihadkhawaja) wants to merge 7 commits into
microsoft:mainfrom
jihadkhawaja:dotnet-mem0sharp-long-term-memory-sample
Open

.NET: added Mem0Sharp integration for in-memory storage in agent samples.#7792
Jay Khawaja (jihadkhawaja) wants to merge 7 commits into
microsoft:mainfrom
jihadkhawaja:dotnet-mem0sharp-long-term-memory-sample

Conversation

@jihadkhawaja

Copy link
Copy Markdown

@jihadkhawaja

Copy link
Copy Markdown
Author

Jay Khawaja (Jay Khawaja (@jihadkhawaja)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@agent-framework-automationagent-framework-automationBot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Aug 20, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 Mem0Sharp-based in-memory provider sample demonstrating memory sharing across agent sessions.

Changes:

  • Adds the Mem0Sharp provider and runnable sample.
  • Documents configuration and persistence alternatives.
  • Registers the dependency and sample project.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
AgentWithMemory/README.mdLinks the new sample.
Step09.../README.mdDocuments setup and storage providers.
Step09.../Program.csDemonstrates cross-session recall.
Step09.../Mem0SharpProvider.csImplements memory storage and retrieval.
Step09...csprojDefines dependencies and framework reference.
Directory.Packages.propsPins Mem0Sharp 0.2.1.
agent-framework-dotnet.slnxRegisters the sample project.
Suppressed comments (2)

dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step09_MemoryUsingMem0Sharp/Mem0SharpProvider.cs:28

  • GetAllAsync injects every memory for the user on every invocation. With the persistent stores documented for this provider, prompt size and retrieval cost grow without bound and unrelated memories are labeled as relevant; use the current external request text to call Mem0Sharp's bounded SearchAsync instead.
 var memories = await memory.GetAllAsync(
new MemoryFilter(UserId: userId),
cancellationToken: cancellationToken);

dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step09_MemoryUsingMem0Sharp/Mem0SharpProvider.cs:34

  • These memories originate verbatim from user messages, but placing them in Instructions promotes that untrusted text to the model's instruction channel. A user can persist an instruction in one session and have it override behavior in later sessions. Return the recalled text as a user-role context message instead, matching the repository's built-in memory providers.
 Instructions = $"Relevant memories for this user:\n{string.Join(Environment.NewLine, memories.Select(item => $"- {item.Text}"))}",

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actionsgithub-actionsBot changed the title added Mem0Sharp integration for in-memory storage in agent samples..NET: added Mem0Sharp integration for in-memory storage in agent samples.Aug 20, 2026
@rogerbarreto

Roger Barreto (rogerbarreto) commented Aug 21, 2026

Copy link
Copy Markdown
Member

Hi Jay Khawaja (@jihadkhawaja) Thanks for the contribution.

Please make this change as a README.md only file that points to your MAF sample in the original repo.

https://github.com/jihadkhawaja/mem0sharp/blob/main/samples/AgentFrameworkMemory/README.md

Additionally would be interesting to make your library also multi TFM net8,9 + netstandard 2.0 friendly for a more broader audience.

@jihadkhawaja

Jay Khawaja (jihadkhawaja) commented Aug 21, 2026

Copy link
Copy Markdown
Author

Roger Barreto (@rogerbarreto) done, Also added support for multi TFM (net8,9 and netstandard 2.0), thanks!

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

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docs.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jihadkhawaja@rogerbarreto