mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
0009e330af
Add #pragma warning disable directives to suppress experimental API diagnostics that cause build errors in Docker isolation (where repo-level Directory.Build.props is not inherited): - AgentWithHostedMCP: suppress MEAI001 (HostedMcpServerTool) and OPENAI001 (GetResponsesClient) - FoundrySingleAgent: suppress CA2252 (AIProjectClient preview features) - FoundryMultiAgent: suppress CA2252 (AIProjectClient preview features) Fixes #4365
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.AsAgent().RunAIAgentAsync();
|
|
}
|
|
finally
|
|
{
|
|
// Cleanup server-side agents
|
|
await aiProjectClient.Agents.DeleteAgentAsync(writerAgent.Name);
|
|
await aiProjectClient.Agents.DeleteAgentAsync(reviewerAgent.Name);
|
|
}
|