mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
c79f886dc3
* dotnet: refresh Foundry sample guidance Carry forward the still-relevant sample guidance and Foundry-specific documentation fixes from the old stacked sample migration work, adapted to the current repo layout and policy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * dotnet: rename Foundry sample env vars Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * dotnet: remove persistent provider sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * dotnet: drop SAMPLE_GUIDELINES.md from this PR Defer the guidelines doc and its cross-link to a follow-on PR to avoid broken-link failures in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * dotnet: add DefaultAzureCredential warning to remaining samples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * dotnet: address PR review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c79f886dc3
ยท
2026-06-11 17:26:00 +00:00
History
Getting started with Foundry Agents
These samples demonstrate how to use Microsoft Foundry with Agent Framework.
Quick start
You can create a Foundry agent directly with the FoundryAgent type:
FoundryAgent agent = new(
new Uri(endpoint),
new DefaultAzureCredential(),
model: "gpt-5.4-mini",
instructions: "You are good at telling jokes.",
name: "JokerAgent");
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
Or using the AIProjectClient.AsAIAgent(...) extensions:
AIProjectClient aiProjectClient = new(new Uri(endpoint), new DefaultAzureCredential());
FoundryAgent agent = aiProjectClient.AsAIAgent(
model: deploymentName,
instructions: "You are good at telling jokes.",
name: "JokerAgent");
Prerequisites
- .NET 10 SDK or later
- Foundry project endpoint
- An authenticated Azure identity (for example, sign in with
az login)
Set:
$env:FOUNDRY_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project"
$env:FOUNDRY_MODEL="gpt-5.4-mini"
Some samples require extra tool-specific environment variables. See each sample for details.
Samples
| Sample | Description |
|---|---|
| FoundryAgent lifecycle | Create a FoundryAgent directly with endpoint and credentials |
| Basics (Responses API) | Create and run an agent using AsAIAgent extensions |
| Multi-turn conversation | Multi-turn using sessions and response ID chaining |
| Multi-turn with server conversations | Server-side conversations visible in Foundry UI |
| Using function tools | Function tools |
| Function tools with approvals | Human-in-the-loop approval |
| Structured output | Structured output with JSON schema |
| Persisted conversations | Persisting and resuming conversations |
| Observability | OpenTelemetry observability |
| Dependency injection | DI with a hosted service |
| Using MCP client as tools | MCP client tools |
| Using images | Image multi-modality |
| Agent as function tool | Agent as a function tool for another |
| Middleware | Multiple middleware layers |
| Plugins | Plugins with dependency injection |
| Code interpreter | Code interpreter tool |
| Computer use | Computer use tool |
| File search | File search tool |
| OpenAPI tools | OpenAPI tools |
| Bing custom search | Bing Custom Search tool |
| SharePoint | SharePoint grounding tool |
| Microsoft Fabric | Microsoft Fabric tool |
| Web search | Web search tool |
| Memory search | Memory search tool |
| Local MCP | Local MCP client with HTTP transport |
| Code interpreter file download | Download container files generated by code interpreter |
| Foundry toolbox via MCP | Use a Foundry Toolbox from a non-hosted agent via its MCP endpoint |
| Foundry toolbox MCP skills | Use a Foundry Toolbox with MCP-based skills discovery (SEP-2640) via AIContextProviders |
Running the samples
Use the basics sample for a quick smoke test:
cd dotnet/samples/02-agents/AgentsWithFoundry
dotnet run --project .\Agent_Step01_Basics
If you want to exercise the full create-run-delete lifecycle, run Agent_Step00_FoundryAgentLifecycle.