89d19a2370
* Migrate 01-get-started samples to Foundry as canonical default Change canonical provider from Azure OpenAI to Microsoft Foundry Responses API: Code changes: - Updated all 01-get-started samples (01_hello_agent, 02_add_tools, 03_multi_turn, 04_memory, 06_host_your_agent) to use FoundryAgent or AIProjectClient.AsAIAgent() - Updated environment variables: AZURE_OPENAI_* → FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL - Updated .csproj files to reference Microsoft.Agents.AI.Foundry instead of Azure.AI.OpenAI - Added warning comments about DefaultAzureCredential production usage - 05_first_workflow unchanged (workflow pattern only, no AI model) Documentation changes: - Updated AGENTS.md Default provider section to reflect Foundry as canonical - Updated code example to use FoundryAgent constructor pattern - Updated env var documentation Note: 04_memory (AIContextProvider sample) extracts IChatClient from FoundryAgent to maintain the memory pattern while using Foundry backend. All samples verified to build successfully. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR 6555 review feedback and format failures - Add Microsoft.Agents.AI.Foundry using to AGENTS.md Foundry snippet - Update verify-samples GetStarted env vars to FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL - Remove unnecessary usings flagged by dotnet format in 01_get_started samples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Switch 01-get-started samples from FoundryAgent to AIProjectClient.AsAIAgent() Use AIProjectClient.AsAIAgent() as the canonical pattern for all 01-get-started samples. Reserve FoundryAgent only for samples that specifically demonstrate the Foundry-managed (prompt) agent — i.e. 02-agents/AgentsWithFoundry/. Changes: - 01_hello_agent, 02_add_tools, 03_multi_turn, 06_host_your_agent: swap FoundryAgent constructor for AIProjectClient.AsAIAgent(model, instructions) - 04_memory: get IChatClient via AIProjectClient.AsAIAgent(options).GetService() instead of extracting from a throwaway FoundryAgent - AGENTS.md: update default-provider snippet and note on when to use FoundryAgent Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
26 lines
1.2 KiB
C#
26 lines
1.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample shows how to create and use a simple AI agent with AIProjectClient as the backend.
|
|
|
|
using Azure.AI.Projects;
|
|
using Azure.Identity;
|
|
using Microsoft.Agents.AI;
|
|
|
|
var endpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT is not set.");
|
|
var model = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-5.4-mini";
|
|
|
|
// 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.
|
|
AIAgent agent = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())
|
|
.AsAIAgent(model: model, instructions: "You are good at telling jokes.", name: "Joker");
|
|
|
|
// Invoke the agent and output the text result.
|
|
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
|
|
|
|
// Invoke the agent with streaming support.
|
|
await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pirate."))
|
|
{
|
|
Console.WriteLine(update);
|
|
}
|