Skip to content

MicrosoftFoundry

Rasmus Wulff Jensen edited this page Aug 4, 2026 · 2 revisions

NuGet README

Features

  • AgentFactory (MicrosoftFoundryAgentFactory)
  • Declarative agent creation and management (MicrosoftFoundryDeclarativeAgentFactory)
  • Hosted agent deployment and connection (MicrosoftFoundryHostedAgentFactory)
  • AIToolsFactory integration (tools in AgentOptions.Tools)
  • ChatClient and Responses API support
  • Azure RBAC authentication

Package

dotnet add package AgentFrameworkToolkit.MicrosoftFoundry

Quick start

MicrosoftFoundryAgentFactory agentFactory = new("<projectEndpoint>", new AzureCliCredential());
MicrosoftFoundryAgent agent = agentFactory.CreateAgent(new AgentOptions
{
    Model = "gpt-5",
    Instructions = "You are a nice AI"
});

AgentResponse response = await agent.RunAsync("Hello World");
Console.WriteLine(response);

Declarative agents

Declarative agents persist in the Microsoft Foundry project. Creating an agent with an existing name and a changed definition creates a new version.

MicrosoftFoundryAgentFactory agentFactory = new("<projectEndpoint>", new AzureCliCredential());
MicrosoftFoundryDeclarativeAgentFactory declarativeFactory = agentFactory.DeclarativeAgentFactory;

MicrosoftFoundryAgent agent = declarativeFactory.CreateAgent(new DeclarativeAgentCreationOptions
{
    Name = "my-agent",
    Model = "gpt-5-nano",
    Instructions = "You are a concise assistant.",
    Tools = [],
    McpTools = [],
    WebSearchTool = false,
    CodeInterpreterTool = false
});

AgentResponse response = await agent.RunAsync("Hello World");

The declarative factory can also retrieve agents and versions with GetAgent, GetAgents, and GetAgentVersions, or remove an agent with DeleteAgent.

Hosted agents

Hosted agents run your .NET agent project in Microsoft Foundry managed hosting. The factory uploads the project source for a remote build and creates a persistent hosted agent version. Reusing an agent name deploys a new version.

Deploy from source

MicrosoftFoundryAgentFactory agentFactory = new(
    "<projectEndpoint>",
    new AzureCliCredential());

MicrosoftFoundryHostedAgentFactory hostedFactory = agentFactory.HostedAgentFactory;

MicrosoftFoundryAgent agent = hostedFactory.CreateAgent(new HostedAgentCreationOptions
{
    Name = "my-hosted-agent",
    SourceDirectory = Path.GetFullPath("../MyHostedAgent"),
    AssemblyName = "MyHostedAgent.dll",
    DotNetRuntime = "dotnet_10",
    Cpu = "0.5",
    Memory = "1Gi"
});

AgentResponse response = await agent.RunAsync("Hello Foundry!");
Console.WriteLine(response);
Option Description
Name Unique hosted agent name. Reusing it deploys a new version.
SourceDirectory Directory containing the project and C# source files.
AssemblyName Output DLL used as the hosted process entry point.
DotNetRuntime Foundry runtime, for example dotnet_10.
Cpu CPU allocation: "0.5", "1", or "2".
Memory Memory allocation: "1Gi", "2Gi", or "4Gi".

The factory excludes launchSettings.json, bin, obj, .git, and .vs from the upload. CreateAgent waits for the deployment to become active and throws InvalidOperationException if deployment fails.

Connect to an existing deployment

GetAgent connects to the deployed endpoint without uploading source or creating a new version:

MicrosoftFoundryAgentFactory agentFactory = new(
    "<projectEndpoint>",
    new AzureCliCredential());

MicrosoftFoundryAgent agent =
    agentFactory.HostedAgentFactory.GetAgent("my-hosted-agent");

AgentResponse response = await agent.RunAsync("Hello again!");
Console.WriteLine(response);

Both methods return MicrosoftFoundryAgent, which is compatible with Microsoft Agent Framework's AIAgent APIs.

Connection options

  • Endpoint (required Microsoft Foundry project endpoint)
  • AuthenticationTokenProvider (optional, defaults to DefaultAzureCredential)
  • NetworkTimeout
  • DefaultClientType (Responses API by default)
  • AdditionalProjectClientOptions

Dependency injection

builder.Services.AddMicrosoftFoundryAgentFactory("<projectEndpoint>", new AzureCliCredential());
builder.Services.AddMicrosoftFoundryAgentFactory(new MicrosoftFoundryConnection
{
    Endpoint = "<projectEndpoint>",
    AuthenticationTokenProvider = new AzureCliCredential()
});

Notes

  • MicrosoftFoundryAgentFactory creates model-backed agents without persisting an agent definition.
  • Declarative agents persist in the Foundry project; delete temporary agents when they are no longer needed.
  • See AgentFactories for shared agent options and middleware.
  • See AIToolsFactory for tool creation and MCP support.

Clone this wiki locally