From 2393351a03cfbdcaca916106c679eddf25032344 Mon Sep 17 00:00:00 2001 From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Date: Wed, 10 Sep 2025 19:34:08 +0100 Subject: [PATCH] .NET: Adding Image Multi Modality Sample (#688) * Adding Multi Modal Sample * Address typos * Update sample to Azure OpenAI * Update readme * Update readme * Update readme * Use thread --- dotnet/agent-framework-dotnet.slnx | 1 + .../Agent_Step11_UsingImages.csproj | 22 ++++++++ .../Agent_Step11_UsingImages/Program.cs | 30 +++++++++++ .../Agents/Agent_Step11_UsingImages/README.md | 52 +++++++++++++++++++ .../samples/GettingStarted/Agents/README.md | 1 + .../SemanticKernelToAgentFrameworkReport.md | 0 6 files changed, 106 insertions(+) create mode 100644 dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Agent_Step11_UsingImages.csproj create mode 100644 dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs create mode 100644 dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/README.md create mode 100644 dotnet/samples/SemanticKernelMigration/NotMigratedUseCases/SemanticKernelBasic/.github/SemanticKernelToAgentFrameworkReport.md diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index cd28a9e723..c26e25487e 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -48,6 +48,7 @@ + diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Agent_Step11_UsingImages.csproj b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Agent_Step11_UsingImages.csproj new file mode 100644 index 0000000000..a438862616 --- /dev/null +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Agent_Step11_UsingImages.csproj @@ -0,0 +1,22 @@ + + + + Exe + net9.0 + 12 + + enable + disable + + + + + + + + + + + + + diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs new file mode 100644 index 0000000000..318788f352 --- /dev/null +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft. All rights reserved. + +// This sample shows how to use Image Multi-Modality with an AI agent. + +using System; +using Azure.AI.OpenAI; +using Azure.Identity; +using Microsoft.Extensions.AI; +using OpenAI; + +var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); +var deploymentName = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o"; + +var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + .GetChatClient(deploymentName) + .CreateAIAgent( + name: "VisionAgent", + instructions: "You are a helpful agent that can analyze images"); + +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") +]); + +var thread = agent.GetNewThread(); + +await foreach (var update in agent.RunStreamingAsync(message, thread)) +{ + Console.WriteLine(update); +} diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/README.md b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/README.md new file mode 100644 index 0000000000..49d1bff4a2 --- /dev/null +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/README.md @@ -0,0 +1,52 @@ +# Using Images with AI Agents + +This sample demonstrates how to use image multi-modality with an AI agent. It shows how to create a vision-enabled agent that can analyze and describe images using Azure OpenAI. + +## What this sample demonstrates + +- Creating a persistent AI agent with vision capabilities +- Sending both text and image content to an agent in a single message +- Using `UriContent` to Uri referenced images +- Processing multimodal input (text + image) with an AI agent + +## Key features + +- **Vision Agent**: Creates an agent specifically instructed to analyze images +- **Multimodal Input**: Combines text questions with image uri in a single message +- **Azure OpenAI Integration**: Uses AzureOpenAI LLM agents + +## Prerequisites + +Before running this sample, ensure you have: + +1. An Azure OpenAI project set up +2. A compatible model deployment (e.g., gpt-4o) +3. Azure CLI installed and authenticated + +## Environment Variables + +Set the following environment variables: + +```powershell +$env:AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" # Replace with your Azure OpenAI endpoint +$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o" # Replace with your model deployment name (optional, defaults to gpt-4o) +``` + +## Run the sample + +Navigate to the sample directory and run: + +```powershell +cd Agent_Step11_UsingImages +dotnet run +``` + +## Expected behavior + +The sample will: + +1. Create a vision-enabled agent named "VisionAgent" +2. Send a message containing both text ("What do you see in this image?") and a Uri image of a green walk +3. The agent will analyze the image and provide a description +4. Clean up resources by deleting the thread and agent + diff --git a/dotnet/samples/GettingStarted/Agents/README.md b/dotnet/samples/GettingStarted/Agents/README.md index 03e9edc247..c6959aee65 100644 --- a/dotnet/samples/GettingStarted/Agents/README.md +++ b/dotnet/samples/GettingStarted/Agents/README.md @@ -36,6 +36,7 @@ Before you begin, ensure you have the following prerequisites: |[Telemetry with a simple agent](./Agent_Step08_Telemetry/)|This sample demonstrates how to add telemetry to a simple agent| |[Dependency injection with a simple agent](./Agent_Step09_DependencyInjection/)|This sample demonstrates how to add and resolve an agent with a dependency injection container| |[Exposing a simple agent as MCP tool](./Agent_Step10_AsMcpTool/)|This sample demonstrates how to expose an agent as an MCP tool| +|[Using images with a simple agent](./Agent_Step11_UsingImages/)|This sample demonstrates how to use image multi-modality with an AI agent| ## Running the samples from the console diff --git a/dotnet/samples/SemanticKernelMigration/NotMigratedUseCases/SemanticKernelBasic/.github/SemanticKernelToAgentFrameworkReport.md b/dotnet/samples/SemanticKernelMigration/NotMigratedUseCases/SemanticKernelBasic/.github/SemanticKernelToAgentFrameworkReport.md new file mode 100644 index 0000000000..e69de29bb2