Files
Roger Barreto a54afd5e6c .NET: Add Foundry Agents Tool Sample - OpenAPI Tools (#3702)
* .NET: Add OpenAPI Tools sample #3674

* Apply format fixes

* Add MEAI and Native SDK creation options for OpenAPI Tools sample

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

* Address PR review: DefaultAzureCredential and CS8321 in NoWarn

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

* Add project to slnx

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
a54afd5e6c ยท 2026-02-19 15:49:04 +00:00
History
..

Using OpenAPI Tools with AI Agents

This sample demonstrates how to use OpenAPI tools with AI agents. OpenAPI tools allow agents to call external REST APIs defined by OpenAPI specifications.

What this sample demonstrates

  • Creating agents with OpenAPI tool capabilities
  • Using AgentTool.CreateOpenApiTool with an embedded OpenAPI specification
  • Anonymous authentication for public APIs
  • Running an agent that can call external REST APIs
  • Managing agent lifecycle (creation and deletion)

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 DefaultAzureCredential for authentication, which supports multiple authentication methods including Azure CLI, managed identity, and more. Make sure you're logged in with az login and have access to the Azure Foundry resource. For more information, see the Azure Identity documentation.

Set the following environment variables:

$env:AZURE_FOUNDRY_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project" # Replace with your Azure Foundry resource endpoint
$env:AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME="gpt-4o-mini"  # Optional, defaults to gpt-4o-mini

Run the sample

Navigate to the FoundryAgents sample directory and run:

cd dotnet/samples/GettingStarted/FoundryAgents
dotnet run --project .\FoundryAgents_Step19_OpenAPITools

Expected behavior

The sample will:

  1. Create an agent with an OpenAPI tool configured to call the REST Countries API
  2. Ask the agent: "What countries use the Euro (EUR) as their currency?"
  3. The agent will use the OpenAPI tool to call the REST Countries API
  4. Display the response containing the list of countries that use EUR
  5. Clean up resources by deleting the agent