Skip to content

.NET: Implement Microsoft.Agents.AI.FoundryLocal package for C##5170

Open
DavidLuong98 wants to merge 6 commits intomicrosoft:mainfrom
DavidLuong98:davidluong98/foundry-local-support
Open

.NET: Implement Microsoft.Agents.AI.FoundryLocal package for C##5170
DavidLuong98 wants to merge 6 commits intomicrosoft:mainfrom
DavidLuong98:davidluong98/foundry-local-support

Conversation

@DavidLuong98
Copy link
Copy Markdown
Member

@DavidLuong98 DavidLuong98 commented Apr 8, 2026

Motivation and Context

The existing Microsoft.Agents.AI.Foundry package only supports cloud-based Azure AI Foundry. There is no .NET support for AI Foundry Local. Microsoft's on-device model inference product that runs models locally via an OpenAI-compatible HTTP API.

A Python implementation already exists in this repo (python/packages/foundry_local/), but C# developers have no equivalent. This PR adds that parity.

Description

Adds a new Microsoft.Agents.AI.FoundryLocal package that enables on-device model inference through the Microsoft.AI.Foundry.Local SDK (v0.9.0).

Architecture: The Foundry Local SDK internally uses Betalgo.Ranul.OpenAI, which is incompatible with Microsoft.Extensions.AI.IChatClient. To solve this, we use the SDK for model management (catalog, download, load, web service lifecycle) but create the chat client by pointing the official OpenAI NuGet package at the SDK's local HTTP endpoint (localhost:5272/v1), the same approach the Python implementation uses.

Key classes:

  • FoundryLocalChatClient - DelegatingChatClient with async CreateAsync factory that handles manager bootstrapping, model download/load, and web service startup
  • FoundryLocalClientOptions - Configuration (model alias, bootstrap, prepare model, web service URL, env var support via FOUNDRY_LOCAL_MODEL)
  • FoundryLocalChatClientExtensions 0 .AsAIAgent() extension methods matching the OpenAIChatClientExtensions pattern

Design decisions:

  • No Azure dependencies - zero references to Azure.AI.Projects or Azure.Identity
  • net9.0 only - constrained by the Microsoft.AI.Foundry.Local SDK's target framework
  • Static async factory (CreateAsync) because SDK initialization requires async operations (model download, load, web service start)
  • Default web service URL (http://localhost:5272) always configured, matching the Python SDK's default endpoint

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass (12/12), and I have added new tests where possible
  • Is this a breaking change? Nope, this is a new package with no changes to existing code.

…l inference

Adds AI Foundry Local support to the .NET Agent Framework, enabling
on-device model inference via the Microsoft.AI.Foundry.Local SDK.

The package creates an OpenAI-compatible IChatClient pointed at the
Foundry Local HTTP endpoint (localhost:5272), following the same
pattern as the Python foundry_local package.

New files:
- FoundryLocalChatClient: DelegatingChatClient with async CreateAsync factory
- FoundryLocalClientOptions: Configuration (model, bootstrap, web service)
- FoundryLocalChatClientExtensions: .AsAIAgent() extension methods
- Unit tests (12 passing) and smoke test
@DavidLuong98 DavidLuong98 marked this pull request as ready for review April 8, 2026 16:58
Copilot AI review requested due to automatic review settings April 8, 2026 16:58
@moonbox3 moonbox3 added the .NET label Apr 8, 2026
@github-actions github-actions bot changed the title Implement Microsoft.Agents.AI.FoundryLocal package for C# .NET: Implement Microsoft.Agents.AI.FoundryLocal package for C# Apr 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new .NET package (Microsoft.Agents.AI.FoundryLocal) to enable AI Foundry Local on-device inference by managing models via Microsoft.AI.Foundry.Local while using the official OpenAI client against the local OpenAI-compatible HTTP endpoint.

Changes:

  • Introduces FoundryLocalChatClient, FoundryLocalClientOptions, and FoundryLocalChatClientExtensions for Foundry Local-backed IChatClient / agent creation.
  • Adds unit tests for options validation and basic factory/extension argument checks.
  • Adds a standalone smoke test console project and wires the new package into the .NET solution + dependency versions.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.FoundryLocal/Microsoft.Agents.AI.FoundryLocal.csproj New package project targeting net9.0 and referencing Foundry Local + OpenAI dependencies
dotnet/src/Microsoft.Agents.AI.FoundryLocal/FoundryLocalClientOptions.cs Adds options object with env-var model resolution
dotnet/src/Microsoft.Agents.AI.FoundryLocal/FoundryLocalChatClient.cs Implements async factory that bootstraps manager, resolves/downloads/loads model, starts service, and builds OpenAI chat client
dotnet/src/Microsoft.Agents.AI.FoundryLocal/FoundryLocalChatClientExtensions.cs Adds .AsAIAgent() convenience extensions for FoundryLocalChatClient
dotnet/tests/Microsoft.Agents.AI.FoundryLocal.UnitTests/Microsoft.Agents.AI.FoundryLocal.UnitTests.csproj Adds new unit test project for FoundryLocal package
dotnet/tests/Microsoft.Agents.AI.FoundryLocal.UnitTests/FoundryLocalClientOptionsTests.cs Unit tests for model resolution and default option values
dotnet/tests/Microsoft.Agents.AI.FoundryLocal.UnitTests/FoundryLocalChatClientTests.cs Unit tests for CreateAsync argument/option validation
dotnet/tests/Microsoft.Agents.AI.FoundryLocal.UnitTests/FoundryLocalChatClientExtensionsTests.cs Unit tests for extension method null argument behavior
dotnet/tests/FoundryLocal.SmokeTest/FoundryLocal.SmokeTest.csproj Adds a non-test executable project for manual local integration verification
dotnet/tests/FoundryLocal.SmokeTest/Program.cs Smoke test that creates a client/agent and runs a prompt against a local model
dotnet/agent-framework-dotnet.slnx Adds the new FoundryLocal project to the solution
dotnet/Directory.Packages.props Pins Microsoft.AI.Foundry.Local dependency version (0.9.0)

David Luong and others added 3 commits April 8, 2026 15:07
Co-Authored-By: David Luong <davidluong98@gmail.com>
Co-Authored-By: David Luong <davidluong98@gmail.com>
Add explicit guard for uninitialized FoundryLocalManager and serialize
env-var-mutating tests with xUnit collection attribute.

Co-Authored-By: David Luong <davidluong98@gmail.com>
Co-Authored-By: David Luong <davidluong98@gmail.com>
Co-Authored-By: David Luong <davidluong98@gmail.com>
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.

3 participants