-
-
Notifications
You must be signed in to change notification settings - Fork 14
MicrosoftFoundry
- 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
dotnet add package AgentFrameworkToolkit.MicrosoftFoundry
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 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 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.
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.
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.
-
Endpoint(required Microsoft Foundry project endpoint) -
AuthenticationTokenProvider(optional, defaults toDefaultAzureCredential) NetworkTimeout-
DefaultClientType(Responses API by default) AdditionalProjectClientOptions
builder.Services.AddMicrosoftFoundryAgentFactory("<projectEndpoint>", new AzureCliCredential());
builder.Services.AddMicrosoftFoundryAgentFactory(new MicrosoftFoundryConnection
{
Endpoint = "<projectEndpoint>",
AuthenticationTokenProvider = new AzureCliCredential()
});-
MicrosoftFoundryAgentFactorycreates 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.