.NET: Add FileMemoryProvider sample to 02-agents/AgentWithMemory - #7401
Merged
westey-m merged 3 commits intoJul 30, 2026
Conversation
westey-m
marked this pull request as ready for review
July 29, 2026 17:38
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new .NET sample under dotnet/samples/02-agents/AgentWithMemory demonstrating how to attach FileMemoryProvider directly via ChatClientAgentOptions.AIContextProviders, including configuring the provider’s per-session WorkingFolder to control memory scope/lifetime.
Changes:
- Added new sample project
AgentWithMemory_Step07_FileMemoryProvider(Program + README + csproj) showing file-based memory persisted viaFileSystemAgentFileStore. - Registered the new sample in the
AgentWithMemorysample index README. - Added the sample project to
dotnet/agent-framework-dotnet.slnx.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| dotnet/samples/02-agents/AgentWithMemory/README.md | Adds the new “File Based Memory” sample entry to the sample list. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step07_FileMemoryProvider/README.md | Documents the FileMemoryProvider tools, storage abstraction, and working-folder configuration. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step07_FileMemoryProvider/Program.cs | Implements the new Foundry-backed sample wiring FileMemoryProvider via AIContextProviders. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step07_FileMemoryProvider/AgentWithMemory_Step07_FileMemoryProvider.csproj | Introduces the new sample project targeting net10.0. |
| dotnet/agent-framework-dotnet.slnx | Includes the new sample project in the solution. |
5 tasks
SergeyMenshykh
approved these changes
Jul 30, 2026
peibekwe
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
FileMemoryProvidergives an agent file-based memory: it exposes a set offile_memory_*tools that let the agent decide what to write down and when to read it back, storing each memory as an individual file in a pluggableAgentFileStore.Until now it was only demonstrated indirectly, wired up implicitly inside
HarnessAgentOptions.FileMemoryStorein the02-agents/Harnesssamples. There was no sample showing how to attach it directly to a plain agent viaAIContextProviders, and nothing showing how to control where memory files are written — which is what determines whether memories are shared across sessions or isolated to one.This adds that sample alongside the other memory-provider samples in
02-agents/AgentWithMemory, so the file-based option sits next to the chat-history, Mem0, Valkey, Foundry and AgentMemory ones.Description & Review Guide
What are the major changes?
A new sample,
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step07_FileMemoryProvider:Program.cs— a Foundry-backed agent with aFileMemoryProviderover aFileSystemAgentFileStore, attached throughChatClientAgentOptions.AIContextProviders. It has one conversation where the user shares preferences and the agent stores them, prints the resulting files on disk, then starts a new session and shows the agent recalling those preferences with no shared chat history._ => new FileMemoryState { WorkingFolder = $"users/{UserId}" }. The surrounding comment frames the folder choice as determining scope and lifetime: a stable per-user folder gives durable memories shared across sessions (what makes the recall work here), while a unique folder per session — e.g.Guid.NewGuid().ToString()— isolates memories to a single session, which is whatAsHarnessAgentdoes by default.README.md— documents the sevenfile_memory_*tools, theAgentFileStoreabstraction, thememories.mdindex the provider injects, prerequisites/configuration, and a "Configuring the memory folder" section..csproj—net10.0,Azure.Identity, project reference toMicrosoft.Agents.AI.Foundry.Plus registration: the project is added to
dotnet/agent-framework-dotnet.slnxand to the sample table indotnet/samples/02-agents/AgentWithMemory/README.md.What is the impact of these changes?
Purely additive and samples-only — 5 files, +187 lines, no framework source under
dotnet/src/is touched, so there is no behavioural or API impact. The sample follows the conventions indotnet/samples/AGENTS.md: standalone project, singleProgram.cs, Microsoft Foundry viaAIProjectClient.AsAIAgent(...)withDefaultAzureCredential, and configuration through environment variables (FOUNDRY_PROJECT_ENDPOINT,FOUNDRY_MODEL).What do you want reviewers to focus on?
Whether the deliberately stable per-user folder is the clearest way to demonstrate the callback. It is what makes the cross-session recall demo work, but it does sit against
FileMemoryProvider's default instructions, which describe the memory as session-scoped and isolated from other sessions. I opted not to override the instructions to keep the sample minimal — happy to pass customFileMemoryProviderOptions.Instructionsinstead if reviewers would prefer the two to agree.Related Issue
Related to #6448. That issue covers additional harness samples across both Python and .NET, so this PR contributes one .NET sample towards it rather than completing it — no closing keyword is used. There is no other open PR for that issue.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.