-
Notifications
You must be signed in to change notification settings - Fork 1.3k
.Net: Update Foundry Agents for Responses API #4502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rogerbarreto
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
rogerbarreto:features/foundry-agent-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7a90dff
Stage
rogerbarreto 894a45c
Merge branch 'main' of https://github.com/microsoft/agent-framework i…
rogerbarreto e87fb99
Add FoundryAgentClient, model param, chatClientFactory, and RAPI samples
rogerbarreto 2a22cd3
Add auto-discovery constructor and simplify RAPI samples
rogerbarreto 8337980
Add remaining RAPI samples (Step04-Step12)
rogerbarreto 8af3e5d
Add all RAPI samples (Step09-Step23) and switch to AzureCliCredential
rogerbarreto e6af015
Switch Step01-03 samples to AzureCliCredential for consistency
rogerbarreto 97b2947
Clarify connection ID format in SharePoint and Fabric READMEs
rogerbarreto 71e1efa
Normalize env vars, fix structured output, update READMEs with connec…
rogerbarreto 5708e06
Refactor memory samples and switch to DefaultAzureCredential
rogerbarreto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...FoundryAgents-RAPI/FoundryAgentsRAPI_Step01_Basics/FoundryAgentsRAPI_Step01_Basics.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
|
|
||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.AzureAI\Microsoft.Agents.AI.AzureAI.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
22 changes: 22 additions & 0 deletions
22
dotnet/samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step01_Basics/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| // This sample shows how to create and run a basic agent using the Foundry Responses API directly, | ||
| // without creating a server-side agent definition. | ||
|
|
||
| using Azure.Identity; | ||
| using Microsoft.Agents.AI.AzureAI; | ||
|
|
||
| string endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set."); | ||
| string deploymentName = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; | ||
|
|
||
| // Create a FoundryAgentClient that uses the Responses API directly. | ||
| // No server-side agent is created — instructions and model are provided locally. | ||
| FoundryAgentClient agent = new( | ||
| endpoint: new Uri(endpoint), | ||
| tokenProvider: new AzureCliCredential(), | ||
| model: deploymentName, | ||
| instructions: "You are good at telling jokes.", | ||
| name: "JokerAgent"); | ||
|
|
||
| // Once you have the agent, you can invoke it like any other AIAgent. | ||
| Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); |
37 changes: 37 additions & 0 deletions
37
.../samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step01_Basics/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Creating and Running a Basic Agent with the Responses API | ||
|
|
||
| This sample demonstrates how to create and run a basic AI agent using the `FoundryAgentClient`, which uses the Azure AI Foundry Responses API directly without creating server-side agent definitions. | ||
|
|
||
| ## What this sample demonstrates | ||
|
|
||
| - Creating a `FoundryAgentClient` with instructions and a model | ||
| - Running a simple single-turn conversation | ||
| - No server-side agent creation or cleanup required | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following prerequisites: | ||
|
|
||
| - .NET 10 SDK or later | ||
| - Azure Foundry service endpoint and deployment configured | ||
| - Azure CLI installed and authenticated (for Azure credential authentication) | ||
|
|
||
| **Note**: This demo uses Azure CLI credentials for authentication. Make sure you're logged in with `az login` and have access to the Azure Foundry resource. For more information, see the [Azure CLI documentation](https://learn.microsoft.com/cli/azure/authenticate-azure-cli-interactively). | ||
|
|
||
| Set the following environment variables: | ||
|
|
||
| ```powershell | ||
| $env:AZURE_AI_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project" | ||
| $env:AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini" | ||
| ``` | ||
|
|
||
| The `FoundryAgentClient` auto-discovers these environment variables — no endpoint or credential code is needed in the sample. | ||
|
|
||
| ## Run the sample | ||
|
|
||
| Navigate to the FoundryAgents-RAPI sample directory and run: | ||
|
|
||
| ```powershell | ||
| cd dotnet/samples/02-agents/FoundryAgents-RAPI | ||
| dotnet run --project .\FoundryAgentsRAPI_Step01_Basics | ||
| ``` |
15 changes: 15 additions & 0 deletions
15
...tsRAPI_Step02_MultiturnConversation/FoundryAgentsRAPI_Step02_MultiturnConversation.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
|
|
||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.AzureAI\Microsoft.Agents.AI.AzureAI.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
41 changes: 41 additions & 0 deletions
41
...es/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step02_MultiturnConversation/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| // This sample shows how to create and use a multi-turn conversation agent using the Foundry Responses API directly. | ||
|
|
||
| using Azure.Identity; | ||
| using Microsoft.Agents.AI; | ||
| using Microsoft.Agents.AI.AzureAI; | ||
|
|
||
| string endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set."); | ||
| string deploymentName = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; | ||
|
|
||
| // Create a FoundryAgentClient that uses the Responses API directly. | ||
| // No server-side agent is created — instructions and model are provided locally. | ||
| FoundryAgentClient agent = new( | ||
| endpoint: new Uri(endpoint), | ||
| tokenProvider: new AzureCliCredential(), | ||
| model: deploymentName, | ||
| instructions: "You are good at telling jokes.", | ||
| name: "JokerAgent"); | ||
|
|
||
| // Invoke the agent with a multi-turn conversation, where the context is preserved in the session object. | ||
| AgentSession session = await agent.CreateSessionAsync(); | ||
|
|
||
| Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); | ||
| Console.WriteLine(await agent.RunAsync("Now add some emojis to the joke and tell it in the voice of a pirate's parrot.", session)); | ||
|
|
||
| // Invoke the agent with a multi-turn conversation and streaming, where the context is preserved in the session object. | ||
| session = await agent.CreateSessionAsync(); | ||
| await foreach (AgentResponseUpdate update in agent.RunStreamingAsync("Tell me a joke about a pirate.", session)) | ||
| { | ||
| Console.Write(update); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
|
|
||
| await foreach (AgentResponseUpdate update in agent.RunStreamingAsync("Now add some emojis to the joke and tell it in the voice of a pirate's parrot.", session)) | ||
| { | ||
| Console.Write(update); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
39 changes: 39 additions & 0 deletions
39
...nts/FoundryAgents-RAPI/FoundryAgentsRAPI_Step02_MultiturnConversation/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Multi-turn Conversation with the Responses API | ||
|
|
||
| This sample demonstrates how to implement multi-turn conversations using the `FoundryAgentClient`, where context is preserved across multiple agent runs using sessions. | ||
|
|
||
| ## What this sample demonstrates | ||
|
|
||
| - Creating a `FoundryAgentClient` with instructions | ||
| - Using sessions to maintain conversation context across multiple runs | ||
| - Running multi-turn conversations with text output | ||
| - Running multi-turn conversations with streaming output | ||
| - No server-side agent creation or cleanup required | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following prerequisites: | ||
|
|
||
| - .NET 10 SDK or later | ||
| - Azure Foundry service endpoint and deployment configured | ||
| - Azure CLI installed and authenticated (for Azure credential authentication) | ||
|
|
||
| **Note**: This demo uses Azure CLI credentials for authentication. Make sure you're logged in with `az login` and have access to the Azure Foundry resource. For more information, see the [Azure CLI documentation](https://learn.microsoft.com/cli/azure/authenticate-azure-cli-interactively). | ||
|
|
||
| Set the following environment variables: | ||
|
|
||
| ```powershell | ||
| $env:AZURE_AI_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project" | ||
| $env:AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini" | ||
| ``` | ||
|
|
||
| The `FoundryAgentClient` auto-discovers these environment variables — no endpoint or credential code is needed in the sample. | ||
|
|
||
| ## Run the sample | ||
|
|
||
| Navigate to the FoundryAgents-RAPI sample directory and run: | ||
|
|
||
| ```powershell | ||
| cd dotnet/samples/02-agents/FoundryAgents-RAPI | ||
| dotnet run --project .\FoundryAgentsRAPI_Step02_MultiturnConversation | ||
| ``` |
15 changes: 15 additions & 0 deletions
15
...ryAgentsRAPI_Step03_UsingFunctionTools/FoundryAgentsRAPI_Step03_UsingFunctionTools.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
|
|
||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.AzureAI\Microsoft.Agents.AI.AzureAI.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
41 changes: 41 additions & 0 deletions
41
...mples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step03_UsingFunctionTools/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| // This sample demonstrates how to use function tools with the Foundry Responses API directly. | ||
|
|
||
| using System.ComponentModel; | ||
| using Azure.Identity; | ||
| using Microsoft.Agents.AI; | ||
| using Microsoft.Agents.AI.AzureAI; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| string endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set."); | ||
| string deploymentName = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; | ||
|
|
||
| [Description("Get the weather for a given location.")] | ||
| static string GetWeather([Description("The location to get the weather for.")] string location) | ||
| => $"The weather in {location} is cloudy with a high of 15°C."; | ||
|
|
||
| // Define the function tool. | ||
| AITool tool = AIFunctionFactory.Create(GetWeather); | ||
|
|
||
| // Create a FoundryAgentClient that uses the Responses API directly with function tools. | ||
| FoundryAgentClient agent = new( | ||
| endpoint: new Uri(endpoint), | ||
| tokenProvider: new AzureCliCredential(), | ||
| model: deploymentName, | ||
| instructions: "You are a helpful assistant that can get weather information.", | ||
| name: "WeatherAssistant", | ||
| tools: [tool]); | ||
|
|
||
| // Non-streaming agent interaction with function tools. | ||
| AgentSession session = await agent.CreateSessionAsync(); | ||
| Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?", session)); | ||
|
|
||
| // Streaming agent interaction with function tools. | ||
| session = await agent.CreateSessionAsync(); | ||
| await foreach (AgentResponseUpdate update in agent.RunStreamingAsync("What is the weather like in Amsterdam?", session)) | ||
| { | ||
| Console.Write(update); | ||
| } | ||
|
|
||
| Console.WriteLine(); |
39 changes: 39 additions & 0 deletions
39
...agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step03_UsingFunctionTools/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Using Function Tools with the Responses API | ||
|
|
||
| This sample demonstrates how to use function tools with the `FoundryAgentClient`, allowing the agent to call custom functions to retrieve information. | ||
|
|
||
| ## What this sample demonstrates | ||
|
|
||
| - Creating function tools using `AIFunctionFactory` | ||
| - Passing function tools to a `FoundryAgentClient` | ||
| - Running agents with function tools (text output) | ||
| - Running agents with function tools (streaming output) | ||
| - No server-side agent creation or cleanup required | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following prerequisites: | ||
|
|
||
| - .NET 10 SDK or later | ||
| - Azure Foundry service endpoint and deployment configured | ||
| - Azure CLI installed and authenticated (for Azure credential authentication) | ||
|
|
||
| **Note**: This demo uses Azure CLI credentials for authentication. Make sure you're logged in with `az login` and have access to the Azure Foundry resource. For more information, see the [Azure CLI documentation](https://learn.microsoft.com/cli/azure/authenticate-azure-cli-interactively). | ||
|
|
||
| Set the following environment variables: | ||
|
|
||
| ```powershell | ||
| $env:AZURE_AI_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project" | ||
| $env:AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini" | ||
| ``` | ||
|
|
||
| The `FoundryAgentClient` auto-discovers these environment variables — no endpoint or credential code is needed in the sample. | ||
|
|
||
| ## Run the sample | ||
|
|
||
| Navigate to the FoundryAgents-RAPI sample directory and run: | ||
|
|
||
| ```powershell | ||
| cd dotnet/samples/02-agents/FoundryAgents-RAPI | ||
| dotnet run --project .\FoundryAgentsRAPI_Step03_UsingFunctionTools | ||
| ``` |
15 changes: 15 additions & 0 deletions
15
...unctionToolsWithApprovals/FoundryAgentsRAPI_Step04_UsingFunctionToolsWithApprovals.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
|
|
||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.AzureAI\Microsoft.Agents.AI.AzureAI.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We should avoid talking about what the samples used to do like 'no server-side agent`. Lot's more of this issue elsewhere.