mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
eb2d573f03
* Add gettingstarted samples for Foundry Agents * Address structured outputs * Net 10 -> Net 9 Temporary * Net 10 -> Net 9 Temporary * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Address missing docs + old * Drop var for samples * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Address copilot feedback --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
36 lines
1.5 KiB
C#
36 lines
1.5 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample shows how to use Image Multi-Modality with an AI agent.
|
|
|
|
using Azure.AI.Agents;
|
|
using Azure.Identity;
|
|
using Microsoft.Agents.AI;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
string endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
|
|
string deploymentName = System.Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME") ?? "gpt-4o";
|
|
|
|
const string VisionInstructions = "You are a helpful agent that can analyze images";
|
|
const string VisionName = "VisionAgent";
|
|
|
|
// Get a client to create/retrieve/delete server side agents with Azure Foundry Agents.
|
|
AgentClient agentClient = new(new Uri(endpoint), new AzureCliCredential());
|
|
|
|
// Define the agent you want to create. (Prompt Agent in this case)
|
|
AIAgent agent = agentClient.CreateAIAgent(name: VisionName, model: deploymentName, instructions: VisionInstructions);
|
|
|
|
ChatMessage message = new(ChatRole.User, [
|
|
new TextContent("What do you see in this image?"),
|
|
new UriContent("https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", "image/jpeg")
|
|
]);
|
|
|
|
AgentThread thread = agent.GetNewThread();
|
|
|
|
await foreach (AgentRunResponseUpdate update in agent.RunStreamingAsync(message, thread))
|
|
{
|
|
Console.WriteLine(update);
|
|
}
|
|
|
|
// Cleanup by agent name removes the agent version created.
|
|
await agentClient.DeleteAgentAsync(agent.Name);
|