* Update Microsoft.Agents.AI.AzureAI for Azure.AI.Projects SDK 2.0.0 - Bump Azure.AI.Projects to 2.0.0-alpha.20260213.1 - Bump Azure.AI.Projects.OpenAI to 2.0.0-alpha.20260213.1 - Bump System.ClientModel to 1.9.0 (transitive dependency) - Switch both GetAgent and CreateAgentVersion to protocol methods with MEAI user-agent policy injection via RequestOptions - Migrate 29 CREATE-path tests from FakeAgentClient to HttpHandlerAssert pattern for real HTTP pipeline testing - Fix StructuredOutputDefinition constructor (BinaryData -> IDictionary) - Fix responses endpoint path (openai/responses -> /responses) - Add local-packages NuGet source for pre-release nupkgs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update Azure.AI.Projects to 2.0.0-beta.1 from NuGet.org - Update Azure.AI.Projects and Azure.AI.Projects.OpenAI to 2.0.0-beta.1 - Remove local-packages NuGet source (packages now on nuget.org) - Fix MemorySearchTool -> MemorySearchPreviewTool rename - Fix RedTeams.CreateAsync ambiguous call - Fix CreateAgentVersion/Async signature change (BinaryData -> string) - Suppress AAIP001 experimental warning for WorkflowAgentDefinition Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Move s_modelWriterOptionsWire field before methods that use it Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix flaky test: prevent spurious workflow_invoke Activity on timeout wake-up The StreamingRunEventStream run loop uses a 1-second timeout on WaitForInputAsync. When the timeout fires before the consumer calls StopAsync, the loop would create a spurious workflow_invoke Activity even though no actual input was provided. This caused the WorkflowRunActivity_IsStopped_Streaming_OffThread_MultiTurnAsync test to intermittently fail (expecting 2 activities but finding 3). Fix: guard the loop body with a HasUnprocessedMessages check. On timeout wake-ups with no work, the loop waits again without creating an activity or changing the run status. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix epoch race condition causing unit tests to hang on net10.0 and net472 The HasUnprocessedMessages guard (previous commit) correctly prevents spurious workflow_invoke Activity creation on timeout wake-ups, but exposed a latent race in the epoch-based signal filtering. The race: when the run loop processes messages quickly and calls Interlocked.Increment(ref _completionEpoch) before the consumer calls TakeEventStreamAsync, the consumer reads the already-incremented epoch and sets myEpoch = epoch + 1. This causes the consumer to skip the valid InternalHaltSignal (its epoch < myEpoch) and block forever waiting for a signal that will never arrive (since the guard prevents spurious signal generation). Fix: read _completionEpoch without +1. The +1 was originally needed to filter stale signals from timeout-driven spurious loop iterations, but those no longer exist thanks to the HasUnprocessedMessages guard. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Revert "Fix epoch race condition causing unit tests to hang on net10.0 and net472" This reverts commit6ce7f01be8. * Revert "Fix flaky test: prevent spurious workflow_invoke Activity on timeout wake-up" This reverts commit98963e17f2. * Skip hanging multi-turn declarative integration tests The ValidateMultiTurnAsync tests (ConfirmInput.yaml, RequestExternalInput.yaml) hang indefinitely in CI, blocking the merge queue. The hang is SDK-independent (reproduces with both Azure.AI.Projects 1.2.0-beta.5 and 2.0.0-beta.1) and is a pre-existing issue in the declarative workflow multi-turn test logic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove unused using directive in IntegrationTest.cs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Restore Azure.AI.Projects 2.0.0-beta.1 version bump The merge from main accidentally reverted the package versions back to 1.2.0-beta.5. This is the primary change of this PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address merge conflict * Skip flaky WorkflowRunActivity_IsStopped_Streaming_OffThread_MultiTurnAsync test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Skip CheckSystem test cases temporarily Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Getting started with Foundry Agents
The getting started with Foundry Agents samples demonstrate the fundamental concepts and functionalities of Azure Foundry Agents and can be used with Azure Foundry as the AI provider.
These samples showcase how to work with agents managed through Azure Foundry, including agent creation, versioning, multi-turn conversations, and advanced features like code interpretation and computer use.
Classic vs New Foundry Agents
Note
Recently, Azure Foundry introduced a new and improved experience for creating and managing AI agents, which is the target of these samples.
For more information about the previous classic agents and for what's new in Foundry Agents, see the Foundry Agents migration documentation.
For a sample demonstrating how to use classic Foundry Agents, see the following: Agent with Azure AI Persistent.
Agent Versioning and Static Definitions
One of the key architectural changes in the new Foundry Agents compared to the classic experience is how agent definitions are handled. In the new architecture, agents have versions and their definitions are established at creation time. This means that the agent's configuration—including instructions, tools, and options—is fixed when the agent version is created.
Important
Agent versions are static and strictly adhere to their original definition. Any attempt to provide or override tools, instructions, or options during an agent run or request will be ignored by the agent, as the API does not support runtime configuration changes. All agent behavior must be defined at agent creation time.
This design ensures consistency and predictability in agent behavior across all interactions with a specific agent version.
The Agent Framework intentionally ignores unsupported runtime parameters rather than throwing exceptions. This abstraction-first approach ensures that code written against the unified agent abstraction remains portable across providers (OpenAI, Azure OpenAI, Foundry Agents). It removes the need for provider-specific conditional logic. Teams can adopt Foundry Agents without rewriting existing orchestration code. Configurations that work with other providers will gracefully degrade, rather than fail, when the underlying API does not support them.
Getting started with Foundry Agents prerequisites
Before you begin, ensure you have the following prerequisites:
- .NET 10 SDK or later
- Azure Foundry service endpoint and project configured
- Azure CLI installed and authenticated (for Azure credential authentication)
Note: These samples use Azure Foundry Agents. For more information, see Azure AI Foundry documentation.
Note: These samples use 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.
Samples
| Sample | Description |
|---|---|
| Basics | This sample demonstrates how to create and manage AI agents with versioning |
| Running a simple agent | This sample demonstrates how to create and run a basic Foundry agent |
| Multi-turn conversation | This sample demonstrates how to implement a multi-turn conversation with a Foundry agent |
| Using function tools | This sample demonstrates how to use function tools with a Foundry agent |
| Using function tools with approvals | This sample demonstrates how to use function tools where approvals require human in the loop approvals before execution |
| Structured output | This sample demonstrates how to use structured output with a Foundry agent |
| Persisted conversations | This sample demonstrates how to persist conversations and reload them later |
| Observability | This sample demonstrates how to add telemetry to a Foundry agent |
| Dependency injection | This sample demonstrates how to add and resolve a Foundry agent with a dependency injection container |
| Using MCP client as tools | This sample demonstrates how to use MCP clients as tools with a Foundry agent |
| Using images | This sample demonstrates how to use image multi-modality with a Foundry agent |
| Exposing as a function tool | This sample demonstrates how to expose a Foundry agent as a function tool |
| Using middleware | This sample demonstrates how to use middleware with a Foundry agent |
| Using plugins | This sample demonstrates how to use plugins with a Foundry agent |
| Code interpreter | This sample demonstrates how to use the code interpreter tool with a Foundry agent |
| Computer use | This sample demonstrates how to use computer use capabilities with a Foundry agent |
| File search | This sample demonstrates how to use the file search tool with a Foundry agent |
| OpenAPI tools | This sample demonstrates how to use OpenAPI tools with a Foundry agent |
| Bing Custom Search | This sample demonstrates how to use Bing Custom Search tool with a Foundry agent |
| SharePoint grounding | This sample demonstrates how to use the SharePoint grounding tool with a Foundry agent |
| Microsoft Fabric | This sample demonstrates how to use Microsoft Fabric tool with a Foundry agent |
| Web search | This sample demonstrates how to use the Responses API web search tool with a Foundry agent |
| Memory search | This sample demonstrates how to use memory search tool with a Foundry agent |
| Local MCP | This sample demonstrates how to use a local MCP client with a Foundry agent |
Evaluation Samples
Evaluation is critical for building trustworthy and high-quality AI applications. The evaluation samples demonstrate how to assess agent safety, quality, and performance using Azure AI Foundry's evaluation capabilities.
| Sample | Description |
|---|---|
| Red Team Evaluation | This sample demonstrates how to use Azure AI Foundry's Red Teaming service to assess model safety against adversarial attacks |
| Self-Reflection with Groundedness | This sample demonstrates the self-reflection pattern where agents iteratively improve responses based on groundedness evaluation |
For details on safety evaluation, see the Red Team Evaluation README.
Running the samples from the console
To run the samples, navigate to the desired sample directory, e.g.
cd FoundryAgents_Step01.2_Running
Set the following environment variables:
$env:AZURE_AI_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project" # Replace with your Azure Foundry resource endpoint
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini" # Optional, defaults to gpt-4o-mini
If the variables are not set, you will be prompted for the values when running the samples.
Execute the following command to build the sample:
dotnet build
Execute the following command to run the sample:
dotnet run --no-build
Or just build and run in one step:
dotnet run
Running the samples from Visual Studio
Open the solution in Visual Studio and set the desired sample project as the startup project. Then, run the project using the built-in debugger or by pressing F5.
You will be prompted for any required environment variables if they are not already set.