Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dotnet/agent-framework-dotnet.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@
<Project Path="samples/02-agents/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/AgentWithRAG_Step03_CustomRAGDataSource.csproj" />
<Project Path="samples/02-agents/AgentWithRAG/AgentWithRAG_Step04_FoundryServiceRAG/AgentWithRAG_Step04_FoundryServiceRAG.csproj" />
</Folder>
<Folder Name="/Samples/02-agents/FoundryAgents-RAPI/">
<File Path="samples/02-agents/FoundryAgents-RAPI/README.md" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step01_Basics/FoundryAgentsRAPI_Step01_Basics.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step02_MultiturnConversation/FoundryAgentsRAPI_Step02_MultiturnConversation.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step03_UsingFunctionTools/FoundryAgentsRAPI_Step03_UsingFunctionTools.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step04_UsingFunctionToolsWithApprovals/FoundryAgentsRAPI_Step04_UsingFunctionToolsWithApprovals.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step05_StructuredOutput/FoundryAgentsRAPI_Step05_StructuredOutput.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step06_PersistedConversations/FoundryAgentsRAPI_Step06_PersistedConversations.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step07_Observability/FoundryAgentsRAPI_Step07_Observability.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step08_DependencyInjection/FoundryAgentsRAPI_Step08_DependencyInjection.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step10_UsingImages/FoundryAgentsRAPI_Step10_UsingImages.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step11_AsFunctionTool/FoundryAgentsRAPI_Step11_AsFunctionTool.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step12_Middleware/FoundryAgentsRAPI_Step12_Middleware.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step09_UsingMcpClientAsTools/FoundryAgentsRAPI_Step09_UsingMcpClientAsTools.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step13_Plugins/FoundryAgentsRAPI_Step13_Plugins.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step14_CodeInterpreter/FoundryAgentsRAPI_Step14_CodeInterpreter.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step15_ComputerUse/FoundryAgentsRAPI_Step15_ComputerUse.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step16_FileSearch/FoundryAgentsRAPI_Step16_FileSearch.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step17_OpenAPITools/FoundryAgentsRAPI_Step17_OpenAPITools.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step18_BingCustomSearch/FoundryAgentsRAPI_Step18_BingCustomSearch.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step19_SharePoint/FoundryAgentsRAPI_Step19_SharePoint.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step20_MicrosoftFabric/FoundryAgentsRAPI_Step20_MicrosoftFabric.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step21_WebSearch/FoundryAgentsRAPI_Step21_WebSearch.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step22_MemorySearch/FoundryAgentsRAPI_Step22_MemorySearch.csproj" />
<Project Path="samples/02-agents/FoundryAgents-RAPI/FoundryAgentsRAPI_Step23_LocalMCP/FoundryAgentsRAPI_Step23_LocalMCP.csproj" />
</Folder>
<Folder Name="/Samples/02-agents/FoundryAgents/">
<File Path="samples/02-agents/FoundryAgents/README.md" />
<Project Path="samples/02-agents/FoundryAgents/FoundryAgents_Evaluations_Step01_RedTeaming/FoundryAgents_Evaluations_Step01_RedTeaming.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
persistentAgentsClientOptions.Retry.NetworkTimeout = TimeSpan.FromMinutes(20);

// Get a client to create/retrieve server side agents with.
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
PersistentAgentsClient persistentAgentsClient = new(endpoint, new DefaultAzureCredential(), persistentAgentsClientOptions);
PersistentAgentsClient persistentAgentsClient = new(endpoint, new AzureCliCredential(), persistentAgentsClientOptions);

// Define and configure the Deep Research tool.
DeepResearchToolDefinition deepResearchTool = new(new DeepResearchDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ Before running this sample, ensure you have:

Pay special attention to the purple `Note` boxes in the Azure documentation.

**Note**: The Bing Connection ID must be from the **project**, not the resource. It has the following format:
**Note**: The Bing Grounding Connection ID must be the **full ARM resource URI** from the project, not just the connection name. It has the following format:

```
/subscriptions/<sub_id>/resourceGroups/<rg_name>/providers/<provider_name>/accounts/<account_name>/projects/<project_name>/connections/<connection_name>
/subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.CognitiveServices/accounts/<account>/projects/<project>/connections/<connection-name>
```

You can find this in the Azure AI Foundry portal under **Management > Connected resources**, or retrieve it programmatically via the connections API (`.id` property).

## Environment Variables

Set the following environment variables:
Expand All @@ -37,8 +39,8 @@ Set the following environment variables:
# Replace with your Azure AI Foundry project endpoint
$env:AZURE_AI_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/"

# Replace with your Bing connection ID from the project
$env:AZURE_AI_BING_CONNECTION_ID="/subscriptions/.../connections/your-bing-connection"
# Replace with your Bing Grounding connection ID (full ARM resource URI)
$env:AZURE_AI_BING_CONNECTION_ID="/subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.CognitiveServices/accounts/<account>/projects/<project>/connections/<connection-name>"

# Optional, defaults to o3-deep-research
$env:AZURE_AI_REASONING_DEPLOYMENT_NAME="o3-deep-research"
Expand Down
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>
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."));
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
```
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>
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.
Comment on lines +12 to +13
Copy link
Member

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.

Suggested change
// Create a FoundryAgentClient that uses the Responses API directly.
// No server-side agent is created — instructions and model are provided locally.
// Create a FoundryAgentClient

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();
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
```
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>
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();
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
```
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>
Loading
Loading