-
Notifications
You must be signed in to change notification settings - Fork 1.7k
.NET: Add a file memory provider #5315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westey-m
merged 5 commits into
microsoft:feature-harness
from
westey-m:file-memory-provider
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
128 changes: 128 additions & 0 deletions
128
dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/AgentFileStore.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.FileSystemGlobbing; | ||
| using Microsoft.Shared.DiagnosticIds; | ||
|
|
||
| namespace Microsoft.Agents.AI; | ||
|
|
||
| /// <summary> | ||
| /// Provides an abstract base class for file storage operations. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// All paths are relative to an implementation-defined root. Implementations may map these | ||
| /// paths to a local file system, in-memory store, remote blob storage, or other mechanisms. | ||
| /// </para> | ||
| /// <para> | ||
| /// Paths use forward slashes as separators and must not escape the root (e.g., via <c>..</c> segments). | ||
| /// It is up to each implementation to ensure that this is enforced. | ||
| /// </para> | ||
| /// </remarks> | ||
| [Experimental(DiagnosticIds.Experiments.AgentsAIExperiments)] | ||
| public abstract class AgentFileStore | ||
| { | ||
| /// <summary> | ||
| /// Writes content to a file, creating or overwriting it. | ||
| /// </summary> | ||
| /// <param name="path">The relative path of the file to write.</param> | ||
| /// <param name="content">The content to write to the file.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>A task representing the asynchronous operation.</returns> | ||
| public abstract Task WriteFileAsync(string path, string content, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Reads the content of a file. | ||
| /// </summary> | ||
| /// <param name="path">The relative path of the file to read.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>The file content, or <see langword="null"/> if the file does not exist.</returns> | ||
| public abstract Task<string?> ReadFileAsync(string path, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Deletes a file. | ||
| /// </summary> | ||
| /// <param name="path">The relative path of the file to delete.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns><see langword="true"/> if the file was deleted; <see langword="false"/> if it did not exist.</returns> | ||
| public abstract Task<bool> DeleteFileAsync(string path, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Lists files in a directory. | ||
| /// </summary> | ||
| /// <param name="directory">The relative path of the directory to list. Use an empty string for the root.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>A list of file names in the specified directory (direct children only).</returns> | ||
| public abstract Task<IReadOnlyList<string>> ListFilesAsync(string directory, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Checks whether a file exists. | ||
| /// </summary> | ||
| /// <param name="path">The relative path of the file to check.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns><see langword="true"/> if the file exists; otherwise, <see langword="false"/>.</returns> | ||
| public abstract Task<bool> FileExistsAsync(string path, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Searches for files whose content matches a regular expression pattern. | ||
| /// </summary> | ||
| /// <param name="directory">The relative path of the directory to search. Use an empty string for the root.</param> | ||
| /// <param name="regexPattern"> | ||
| /// A regular expression pattern to match against file contents. The pattern is matched case-insensitively. | ||
| /// For example, <c>"error|warning"</c> matches lines containing "error" or "warning". | ||
| /// </param> | ||
| /// <param name="filePattern"> | ||
| /// An optional glob pattern to filter which files are searched (e.g., <c>"*.md"</c>, <c>"research*"</c>). | ||
| /// When <see langword="null"/>, all files in the directory are searched. | ||
| /// Uses standard glob syntax from <see cref="Matcher"/>. | ||
| /// </param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>A list of search results with matching file names, snippets, and matching lines.</returns> | ||
| public abstract Task<IReadOnlyList<FileSearchResult>> SearchFilesAsync(string directory, string regexPattern, string? filePattern = null, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Ensures a directory exists, creating it if necessary. | ||
| /// </summary> | ||
| /// <param name="path">The relative path of the directory to create.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>A task representing the asynchronous operation.</returns> | ||
| public abstract Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Creates a <see cref="Matcher"/> for the specified glob pattern. Use the returned instance | ||
| /// to test multiple file names without allocating a new matcher for each one. | ||
| /// </summary> | ||
| /// <param name="filePattern"> | ||
| /// The glob pattern to match against (e.g., <c>"*.md"</c>, <c>"research*"</c>). | ||
| /// </param> | ||
| /// <returns>A <see cref="Matcher"/> configured with the specified pattern.</returns> | ||
| protected static Matcher CreateGlobMatcher(string filePattern) | ||
| { | ||
| var matcher = new Matcher(System.StringComparison.OrdinalIgnoreCase); | ||
| matcher.AddInclude(filePattern); | ||
| return matcher; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether a file name matches a pre-built glob <see cref="Matcher"/>. | ||
| /// </summary> | ||
| /// <param name="fileName">The file name to test (not a full path — just the name).</param> | ||
| /// <param name="matcher"> | ||
| /// A pre-built <see cref="Matcher"/> to test against. | ||
| /// When <see langword="null"/>, this method returns <see langword="true"/> for any file name. | ||
| /// </param> | ||
| /// <returns><see langword="true"/> if the file name matches the pattern or if the matcher is <see langword="null"/>; otherwise, <see langword="false"/>.</returns> | ||
| protected static bool MatchesGlob(string fileName, Matcher? matcher) | ||
| { | ||
| if (matcher is null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| PatternMatchingResult result = matcher.Match(fileName); | ||
| return result.HasMatches; | ||
|
westey-m marked this conversation as resolved.
|
||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/FileListEntry.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Shared.DiagnosticIds; | ||
|
|
||
| namespace Microsoft.Agents.AI; | ||
|
|
||
| /// <summary> | ||
| /// Represents a file entry returned by the <see cref="FileMemoryProvider"/> list files tool, | ||
| /// containing the file name and an optional description. | ||
| /// </summary> | ||
| [Experimental(DiagnosticIds.Experiments.AgentsAIExperiments)] | ||
| public sealed class FileListEntry | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the name of the file. | ||
| /// </summary> | ||
| [JsonPropertyName("fileName")] | ||
| public string FileName { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the description of the file, or <see langword="null"/> if no description is available. | ||
| /// </summary> | ||
| [JsonPropertyName("description")] | ||
| public string? Description { get; set; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.