Files
Ben Thomas 5fe8941ff9 .NET: dotnet: Add server-side Foundry Toolbox support and fix SDK beta.4 br… (#5450)
* dotnet: Add server-side Foundry Toolbox support and fix SDK beta.4 breaking changes

Add FoundryToolbox and AIProjectClient extensions to Microsoft.Agents.AI.Foundry.Hosting
for server-side toolbox tool integration matching Python's FoundryChatClient.get_toolbox()
pattern. Tools are fetched from the Foundry project SDK and passed as server-side tools
in the Responses API request.

New files:
- FoundryToolbox.cs: Core implementation using AgentAdministrationClient SDK
- AIProjectClientToolboxExtensions.cs: Extension methods on AIProjectClient
- Agent_Step25_ToolboxServerSideTools sample with create helper and combine flow
- 19 unit tests covering param validation, conversion, sanitization, and extensions

SDK breaking changes (Azure.AI.AgentServer.Responses beta.3 -> beta.4):
- FunctionToolCallOutputResource renamed to OutputItemFunctionToolCallOutput
- AzureAIAgentServerResponsesModelFactory made internal, replaced with direct constructors
- ResponseUsage constructor now requires non-null token details parameters

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: reuse endpoint variable in CreateSampleToolboxAsync

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: pass endpoint through static local functions to avoid capture

Static local functions cannot capture top-level variables. Thread the
endpoint parameter through Main, CombineToolboxes, and CreateSampleToolboxAsync.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* refactor: remove unused projectClient param from CreateSampleToolboxAsync

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Update dotnet/samples/02-agents/AgentsWithFoundry/Agent_Step25_ToolboxServerSideTools/README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dotnet/samples/02-agents/AgentsWithFoundry/Agent_Step25_ToolboxServerSideTools/Program.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* Update dotnet/samples/02-agents/AgentsWithFoundry/Agent_Step25_ToolboxServerSideTools/Program.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* Removing GetToolbocVersion.

* Removing tests for GetToolboxVersion

* fix: map cached/reasoning token counts in ConvertUsage instead of hardcoding zeros

Extract InputTokenDetails.CachedTokenCount and OutputTokenDetails.ReasoningTokenCount
from UsageDetails.AdditionalCounts, matching the pattern in AgentResponseExtensions.
Also accumulate detail counts when merging with existing usage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: alliscode <bentho@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
5fe8941ff9 · 2026-04-23 18:52:03 +00:00
History
..

Agent_Step25_ToolboxServerSideTools

This sample demonstrates loading a named Foundry toolbox and passing its tools as server-side tools when creating an agent via AsAIAgent().

When tools from a toolbox are passed this way, they are sent as tool definitions in the Responses API request. The Foundry platform handles tool execution — the agent process does not invoke tools locally.

This is the dotnet equivalent of the Python sample: python/samples/02-agents/providers/foundry/foundry_chat_client_with_toolbox.py

Prerequisites

  • A Microsoft Foundry project
  • AZURE_AI_PROJECT_ENDPOINT environment variable set to your Foundry project endpoint
  • AZURE_AI_MODEL_DEPLOYMENT_NAME environment variable set (defaults to gpt-5.4-mini)

The sample recreates the toolbox on each run, replacing any existing toolbox with the same name. Comment out the CreateSampleToolboxAsync call if you want to keep an existing toolbox unchanged.

How it works

  1. projectClient.GetToolboxVersionAsync(name) fetches the toolbox definition from the Foundry project API (resolving the default version if none is specified)
  2. ToolboxVersion.ToAITools() converts each tool definition to an AITool instance
  3. The tools are passed to AsAIAgent(tools: ...) which includes them in the Responses API request as server-side tool definitions

For a one-liner, use projectClient.GetToolboxToolsAsync(name) to fetch and convert in one call.

Sample flows

Flow Description
Main (default) Loads a single toolbox and runs an agent with its tools
CombineToolboxes Loads two toolboxes and merges their tools into one agent

Uncomment the desired flow in the top-level statements to try each one.

Running the sample

dotnet run