mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
de791fb8a9
* Add 3 new hosted agent samples: AgentWithTools, AgentWithLocalTools, AgentThreadAndHITL - AgentWithTools: Foundry tools (MCP + code interpreter) via UseFoundryTools - AgentWithLocalTools: Local C# function tool (Seattle hotel search) with AIProjectClient - AgentThreadAndHITL: Human-in-the-loop with ApprovalRequiredAIFunction and thread persistence All samples follow agent-framework conventions (net10.0, AzureCliCredential, CPM disabled). AgentWithTools includes comprehensive README with setup guide and troubleshooting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add root HostedAgents README, replace test_requests.py with .http, update sample READMEs - Create root README.md with shared prerequisites, Azure AI Foundry setup, troubleshooting, and samples index - Replace test_requests.py with run-requests.http in AgentThreadAndHITL - Add pointer to root README in all 6 sample READMEs - Trim AgentWithTools README to concise style Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix dotnet format issues in AgentWithLocalTools/Program.cs - Add UTF-8 BOM (CHARSET) - Sort System.ClientModel.Primitives import alphabetically (IMPORTS) - Use target-typed new for AIProjectClient (IDE0090) - Add internal accessibility modifier to Hotel record (IDE0040) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR review: align model names and package versions - Change default model from gpt-4.1-mini to gpt-4o-mini in AgentWithLocalTools (Program.cs, agent.yaml, README.md) to match existing samples - Change README example from gpt-5.2 to gpt-4o-mini in AgentWithTools and root README - Align AgentWithLocalTools package versions with other samples: Azure.AI.AgentServer.AgentFramework beta.6 -> beta.8 Azure.AI.OpenAI 2.8.0-beta.1 -> 2.7.0-beta.2 Microsoft.Extensions.AI.OpenAI 10.2.0-preview -> 10.1.1-preview Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Upgrade new samples to latest package versions - Azure.AI.OpenAI: 2.7.0-beta.2 -> 2.8.0-beta.1 - Microsoft.Extensions.AI.OpenAI: 10.1.1-preview -> 10.3.0 Aligns with AgentWithHostedMCP which uses the latest versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Pin AgentThreadAndHITL to Microsoft.Extensions.AI.OpenAI 10.1.1 Azure.AI.AgentServer.AgentFramework beta.8 was compiled against Microsoft.Extensions.AI.Abstractions with the single-param FunctionApprovalRequestContent.CreateResponse(bool). Version 10.3.0 changed the signature to include an optional reason parameter, causing a binary incompatibility at runtime. Pin to 10.1.1 until the framework is recompiled against the newer abstractions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
de791fb8a9
ยท
2026-03-02 10:56:28 +00:00
History
What this sample demonstrates
This sample demonstrates how to use Foundry tools with an AI agent via the UseFoundryTools extension. The agent is configured with two tool types: an MCP (Model Context Protocol) connection for fetching Microsoft Learn documentation and a code interpreter for running code when needed.
Key features:
- Configuring Foundry tools using
UseFoundryToolswith MCP and code interpreter - Connecting to an external MCP tool via a Foundry project connection
- Using
AzureCliCredentialfor Azure authentication - OpenTelemetry instrumentation for both the chat client and agent
For common prerequisites and setup instructions, see the Hosted Agent Samples README.
Prerequisites
In addition to the common prerequisites:
- An Azure AI Foundry project with a chat model deployed (e.g.,
gpt-5.2,gpt-4o-mini) - The Azure AI Developer role assigned on the Foundry resource (includes the
agents/writedata action required byUseFoundryTools) - An MCP tool connection configured in your Foundry project pointing to
https://learn.microsoft.com/api/mcp
Environment Variables
In addition to the common environment variables in the root README:
# Your Azure AI Foundry project endpoint (required by UseFoundryTools)
$env:AZURE_AI_PROJECT_ENDPOINT="https://your-resource.services.ai.azure.com/api/projects/your-project"
# Chat model deployment name (defaults to gpt-4o-mini if not set)
$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"
# The MCP tool connection name (just the name, not the full ARM resource ID)
$env:MCP_TOOL_CONNECTION_ID="SampleMCPTool"
How It Works
- An
AzureOpenAIClientis created withAzureCliCredentialand used to get a chat client - The chat client is wrapped with
UseFoundryToolswhich registers two Foundry tool types:- MCP connection: Connects to an external MCP server (Microsoft Learn) via the project connection name, providing documentation fetch and search capabilities
- Code interpreter: Allows the agent to execute code snippets when needed
UseFoundryToolsresolves the connection usingAZURE_AI_PROJECT_ENDPOINTinternally- A
ChatClientAgentis created with instructions guiding it to use the MCP tools for documentation queries - The agent is hosted using
RunAIAgentAsyncwhich exposes the OpenAI Responses-compatible API endpoint