Skip to content

.NET: [BREAKING] Align FileAccess tools with Python; add directory discovery and recursive search#6474

Merged
westey-m merged 3 commits into
microsoft:mainfrom
westey-m:net-file-access-align
Jun 12, 2026
Merged

.NET: [BREAKING] Align FileAccess tools with Python; add directory discovery and recursive search#6474
westey-m merged 3 commits into
microsoft:mainfrom
westey-m:net-file-access-align

Conversation

@westey-m

@westey-m westey-m commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

The Python and .NET implementations of the file-access function tools had diverged, and there were two functional gaps on the .NET side:

  1. No directory discovery. file_access_list_files only surfaces direct-child files; child directory names were never exposed, so an agent could not discover that subdirectories existed.
  2. Search was not recursive. file_access_search_files only scanned the direct children of a single directory, with no way to search an entire subtree.

This PR closes both gaps and aligns the .NET tool surface with Python (same file_access_* snake_case tool names).

#6398

Description

Tool layer (FileAccessProvider)

  • Added a new file_access_list_subdirectories tool that lists the direct child subdirectories of a directory (root when omitted), enabling the agent to discover and walk the directory tree one level at a time.
  • Made file_access_search_files recursive across all descendants from the store root. Removed the directory parameter from the search tool; subtree scoping is now expressed purely through the glob filePattern, which is matched against the store-root-relative path of each file. Results return root-relative paths in fileName, directly usable by read/delete tools.
  • Updated tool descriptions/instructions to document the recursive behavior and the .NET glob syntax (** for cross-directory matching).

Store layer (AgentFileStore, InMemoryAgentFileStore, FileSystemAgentFileStore)

  • Added ListDirectoriesAsync (direct child subdirectories; FileSystem store skips symlinked/reparse-point directories).
  • Added an opt-in bool recursive = false parameter to SearchFilesAsync. The default preserves the existing behavior that FileMemoryProvider depends on (direct children, basename results); FileAccessProvider opts into recursion. Glob and result FileName are defined relative to the search directory. FileSystem recursive enumeration skips symlinked files and directories.

Glob semantics are intentionally kept native per language (Python fnmatch, .NET Microsoft.Extensions.FileSystemGlobbing.Matcher); the expected format is documented to the model via the tool descriptions rather than unified in code.

Misc

  • Improved the PlanningQuestion.Choices description in the Harness sample to clarify that the model must provide valid free-form-compatible choices.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible (full unit test project: 1579 passing; added recursive-search, subtree-glob, nested-extension, ListDirectories, and symlink-skip tests)
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings June 11, 2026 13:58
@moonbox3 moonbox3 added the .NET label Jun 11, 2026

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by westey-m's agents

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

This PR aligns the .NET “File Access” tool surface with the Python implementation by adding directory discovery and making content search recursive across the store, while updating tool naming to snake_case (file_access_*). These changes improve an agent’s ability to explore a file tree and find content without prior knowledge of subdirectory structure.

Changes:

  • Added directory discovery via a new file_access_list_subdirectories tool and corresponding AgentFileStore.ListDirectoriesAsync API.
  • Updated store search APIs to support optional recursive enumeration and glob matching against store-root-relative (or search-root-relative) paths.
  • Renamed .NET FileAccess tool names to file_access_* and updated tests + sample instructions accordingly.

Reviewed changes

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

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileStore/InMemoryAgentFileStoreTests.cs Adds unit tests for recursive search and directory listing in the in-memory store.
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileStore/FileSystemAgentFileStoreTests.cs Adds unit tests for recursive search, directory listing, and symlink-skipping behavior in the filesystem store.
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileAccess/FileAccessProviderTests.cs Updates tests for snake_case tool names and adds coverage for new list-subdirectories + recursive search behavior.
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/InMemoryAgentFileStore.cs Implements ListDirectoriesAsync and adds optional recursive search semantics in-memory.
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/FileSystemAgentFileStore.cs Implements recursive search enumeration + ListDirectoriesAsync, with reparse-point skipping.
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/AgentFileStore.cs Extends the abstract store contract with ListDirectoriesAsync and a recursive search option + updated glob semantics.
dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/FileMemoryProvider.cs Pins FileMemoryProvider to non-recursive search to preserve existing behavior.
dotnet/src/Microsoft.Agents.AI/Harness/FileAccess/FileAccessProvider.cs Renames tools to file_access_*, adds list-subdirectories tool, and documents recursive search + ** glob semantics.
dotnet/samples/02-agents/Harness/Harness_Step03_DataProcessing/Program.cs Updates sample instructions to reference file_access_* tools.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/PlanningResponse.cs Clarifies PlanningQuestion.Choices constraints to ensure choices are valid free-form-compatible inputs.

Comment thread dotnet/src/Microsoft.Agents.AI/Harness/FileStore/FileSystemAgentFileStore.cs Outdated
@westey-m westey-m changed the title .NET: Align FileAccess tools with Python; add directory discovery and recursive search .NET: [BREAKING] Align FileAccess tools with Python; add directory discovery and recursive search Jun 11, 2026
@westey-m westey-m added this pull request to the merge queue Jun 11, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2026
@westey-m westey-m added this pull request to the merge queue Jun 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 12, 2026
@westey-m westey-m enabled auto-merge June 12, 2026 14:15
@westey-m westey-m added this pull request to the merge queue Jun 12, 2026
Merged via the queue into microsoft:main with commit 3f77c55 Jun 12, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants