mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
9a47620f64
* Bump HostedAgents samples to AgentFramework beta.11 and pass credential to UseFoundryTools Update all 8 HostedAgents samples: - Azure.AI.AgentServer.AgentFramework -> 1.0.0-beta.11 - Microsoft.Agents.AI.OpenAI -> 1.0.0-rc4 - Microsoft.Agents.AI/AzureAI/Workflows -> 1.0.0-rc4 - Azure.AI.Projects -> 2.0.0-beta.1 - Fix Workflow.AsAgent() -> AsAIAgent() in FoundryMultiAgent - Pass credential to UseFoundryTools in AgentWithTools (resolves #56802) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove AgentWithTools sample (UseFoundryTools no longer supported) Remove the AgentWithTools hosted agent sample as the UseFoundryTools backend is no longer supported. Updated HostedAgents README and solution file to remove all references. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix AgentWithHostedMCP: downgrade Azure.AI.OpenAI to 2.8.0-beta.1 for rc4 compatibility Azure.AI.OpenAI 2.9.0-beta.1 has breaking changes (GetResponsesClient no longer accepts deployment name, ResponsesClient.Model removed) that are incompatible with Microsoft.Agents.AI.OpenAI rc4. Pin to 2.8.0-beta.1 and use GetResponsesClient(deploymentName).AsAIAgent() pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
52 lines
2.3 KiB
C#
52 lines
2.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample demonstrates a multi-agent workflow with Writer and Reviewer agents
|
|
// using Azure AI Foundry AIProjectClient and the Agent Framework WorkflowBuilder.
|
|
|
|
#pragma warning disable CA2252 // AIProjectClient and Agents API require opting into preview features
|
|
|
|
using Azure.AI.AgentServer.AgentFramework.Extensions;
|
|
using Azure.AI.Projects;
|
|
using Azure.Identity;
|
|
using Microsoft.Agents.AI;
|
|
using Microsoft.Agents.AI.Workflows;
|
|
|
|
var endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT")
|
|
?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set.");
|
|
var deploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
|
|
|
|
Console.WriteLine($"Using Azure AI endpoint: {endpoint}");
|
|
Console.WriteLine($"Using model deployment: {deploymentName}");
|
|
|
|
// 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.
|
|
AIProjectClient aiProjectClient = new(new Uri(endpoint), new DefaultAzureCredential());
|
|
|
|
// Create Foundry agents
|
|
AIAgent writerAgent = await aiProjectClient.CreateAIAgentAsync(
|
|
name: "Writer",
|
|
model: deploymentName,
|
|
instructions: "You are an excellent content writer. You create new content and edit contents based on the feedback.");
|
|
|
|
AIAgent reviewerAgent = await aiProjectClient.CreateAIAgentAsync(
|
|
name: "Reviewer",
|
|
model: deploymentName,
|
|
instructions: "You are an excellent content reviewer. Provide actionable feedback to the writer about the provided content. Provide the feedback in the most concise manner possible.");
|
|
|
|
try
|
|
{
|
|
var workflow = new WorkflowBuilder(writerAgent)
|
|
.AddEdge(writerAgent, reviewerAgent)
|
|
.Build();
|
|
|
|
Console.WriteLine("Starting Writer-Reviewer Workflow Agent Server on http://localhost:8088");
|
|
await workflow.AsAIAgent().RunAIAgentAsync();
|
|
}
|
|
finally
|
|
{
|
|
// Cleanup server-side agents
|
|
await aiProjectClient.Agents.DeleteAgentAsync(writerAgent.Name);
|
|
await aiProjectClient.Agents.DeleteAgentAsync(reviewerAgent.Name);
|
|
}
|