Skip to content

.NET: Add FileMemoryProvider sample to 02-agents/AgentWithMemory - #7401

Open
westey-m wants to merge 2 commits into
microsoft:mainfrom
westey-m:dotnet-filememoryprovider-sample
Open

.NET: Add FileMemoryProvider sample to 02-agents/AgentWithMemory#7401
westey-m wants to merge 2 commits into
microsoft:mainfrom
westey-m:dotnet-filememoryprovider-sample

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation & Context

FileMemoryProvider gives an agent file-based memory: it exposes a set of file_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 pluggable AgentFileStore.

Until now it was only demonstrated indirectly, wired up implicitly inside HarnessAgentOptions.FileMemoryStore in the 02-agents/Harness samples. There was no sample showing how to attach it directly to a plain agent via AIContextProviders, 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 a FileMemoryProvider over a FileSystemAgentFileStore, attached through ChatClientAgentOptions.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.
    • Memory folder configuration is demonstrated with the state-initializer callback, _ => 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 what AsHarnessAgent does by default.
    • README.md — documents the seven file_memory_* tools, the AgentFileStore abstraction, the memories.md index the provider injects, prerequisites/configuration, and a "Configuring the memory folder" section.
    • .csprojnet10.0, Azure.Identity, project reference to Microsoft.Agents.AI.Foundry.

    Plus registration: the project is added to dotnet/agent-framework-dotnet.slnx and to the sample table in dotnet/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 in dotnet/samples/AGENTS.md: standalone project, single Program.cs, Microsoft Foundry via AIProjectClient.AsAIAgent(...) with DefaultAzureCredential, 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 custom FileMemoryProviderOptions.Instructions instead 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

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings July 29, 2026 17:38
@westey-m
westey-m temporarily deployed to github-app-auth July 29, 2026 17:38 — with GitHub Actions Inactive
@westey-m
westey-m temporarily deployed to github-app-auth July 29, 2026 17:38 — with GitHub Actions Inactive
@westey-m
westey-m temporarily deployed to github-app-auth July 29, 2026 17:38 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Jul 29, 2026
@westey-m
westey-m marked this pull request as ready for review July 29, 2026 17:38

Copilot AI 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 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 via FileSystemAgentFileStore.
  • Registered the new sample in the AgentWithMemory sample 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.

Comment on lines +51 to +53
using var fileMemoryProvider = new FileMemoryProvider(
fileStore,
_ => new FileMemoryState { WorkingFolder = workingFolder });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants