From 55993d78d33bebb2710952daef62605c7eec4cf2 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Tue, 21 Oct 2025 19:30:02 -0500 Subject: [PATCH 1/5] Added example demonstrating creating an AIAgent using the Microsoft.AI.Extensions implementation of IChatClient using Dapr as the inference backend provider - in this example, using Ollama Signed-off-by: Whit Waldo --- dotnet/Directory.Packages.props | 1 + dotnet/agent-framework-dotnet.slnx | 2 ++ .../Agent_With_Dapr/Agent_With_Dapr.csproj | 21 ++++++++++++ .../Components/conversation-ollama.yaml | 11 ++++++ .../AgentProviders/Agent_With_Dapr/Program.cs | 28 +++++++++++++++ .../AgentProviders/Agent_With_Dapr/README.md | 34 +++++++++++++++++++ .../GettingStarted/AgentProviders/README.md | 1 + 7 files changed, 98 insertions(+) create mode 100644 dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Agent_With_Dapr.csproj create mode 100644 dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Components/conversation-ollama.yaml create mode 100644 dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs create mode 100644 dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md diff --git a/dotnet/Directory.Packages.props b/dotnet/Directory.Packages.props index f01315c2145..94633d3cf1e 100644 --- a/dotnet/Directory.Packages.props +++ b/dotnet/Directory.Packages.props @@ -82,6 +82,7 @@ + diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index eb731462029..a528a0a7705 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -38,6 +38,8 @@ + + diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Agent_With_Dapr.csproj b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Agent_With_Dapr.csproj new file mode 100644 index 00000000000..f6bf566ede0 --- /dev/null +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Agent_With_Dapr.csproj @@ -0,0 +1,21 @@ + + + + Exe + net9.0 + enable + enable + $(NoWarn);DAPR_CONVERSATION + + + + + + + + + + + + + diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Components/conversation-ollama.yaml b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Components/conversation-ollama.yaml new file mode 100644 index 00000000000..accb248c0da --- /dev/null +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Components/conversation-ollama.yaml @@ -0,0 +1,11 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: ollama +spec: + type: conversation.ollama + metadata: + - name : model + value: llama3.2 + - name: cacheTTL + value: 10m \ No newline at end of file diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs new file mode 100644 index 00000000000..5ced0ad8133 --- /dev/null +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs @@ -0,0 +1,28 @@ +// This sample shows how to create and use a simple AI agent with Dapr as the backend. + +using Dapr.AI.Conversation.Extensions; +using Dapr.AI.Microsoft.Extensions; +using Microsoft.Agents.AI; +using Microsoft.Extensions.AI; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +// Register the Dapr Conversation client with dependency injection +var app = Host.CreateDefaultBuilder() + .ConfigureServices(services => + { + // Configure the gRPC port for the Dapr sidecar + services.AddDaprConversationClient((_, builder) => builder.UseGrpcEndpoint("http://localhost:3501")); + // Provide the name of the Conversation component loaded in the sidecar to use + services.AddDaprChatClient(opt => opt.ConversationComponentName = "ollama"); + }).Build(); + +// Get an instance of the Dapr chat client from the dependency injection container +using var scope = app.Services.CreateScope(); +var daprChatClient = scope.ServiceProvider.GetRequiredService(); + +// Use this chat client to construct an AIAgent +AIAgent agent = daprChatClient.CreateAIAgent(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.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md new file mode 100644 index 00000000000..230f2e22729 --- /dev/null +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md @@ -0,0 +1,34 @@ +# Prerequisites + +Before you begin, ensure you have the following prerequisites: + +- .NET 8.0 SDK or later +- Docker installed and running on your machine +- Ollama installed +- Dapr CLI installed ([instructions](https://docs.dapr.io/getting-started/install-dapr-cli/)) + +You'll need to download a model from [Ollama's library](https://ollama.com/library) to get started. Open +a terminal and run the following, replacing '' with the name of the model you want to use from +Ollama's library (e.g., `llama3.2`). + +```powershell +ollama run +``` + +Once it has downloaded and started running, update the component bundled with this example +in `./Components/conversation-ollama.yaml` to reflect the name of the model you just installed, modifying the value of +the `name` metadata property, then save your changes and close the file. + +Next, start your Dapr sidecar and tell it where it can look for your components. If launching from this project's directory, +run the following; otherwise, replace `./Components` with the path to your components directory. + +```powershell +dapr run --app-id agents --resources-path ./Components --dapr-grpc-port 3501 +``` + +Because the Dapr sidecar needs to continue running while your application is running, please open another terminal +window and run the following command from this project's directory to start the demo. + +```poweshell +dotnet run +``` diff --git a/dotnet/samples/GettingStarted/AgentProviders/README.md b/dotnet/samples/GettingStarted/AgentProviders/README.md index 4e84cd4f080..22fb6e87249 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/README.md +++ b/dotnet/samples/GettingStarted/AgentProviders/README.md @@ -25,6 +25,7 @@ See the README.md for each sample for the prerequisites for that sample. |[Creating an AIAgent with OpenAI Assistants](./Agent_With_OpenAIAssistants/)|This sample demonstrates how to create an AIAgent using OpenAI Assistants as the underlying inference service.
WARNING: The Assistants API is deprecated and will be shut down. For more information see the OpenAI documentation: https://platform.openai.com/docs/assistants/migration| |[Creating an AIAgent with OpenAI ChatCompletion](./Agent_With_OpenAIChatCompletion/)|This sample demonstrates how to create an AIAgent using OpenAI ChatCompletion as the underlying inference service| |[Creating an AIAgent with OpenAI Responses](./Agent_With_OpenAIResponses/)|This sample demonstrates how to create an AIAgent using OpenAI Responses as the underlying inference service| +|[Creating an AIAgent with Dapr](./Agent_With_Dapr/)|This sample demonstrates how to create an AIAgent using Dapr and Ollama| ## Running the samples from the console From 543e20f2c846b6b94c1e56d60f1948a2fd12d1b2 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Tue, 21 Oct 2025 19:41:31 -0500 Subject: [PATCH 2/5] Update dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../GettingStarted/AgentProviders/Agent_With_Dapr/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md index 230f2e22729..080bd2bde34 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/README.md @@ -29,6 +29,6 @@ dapr run --app-id agents --resources-path ./Components --dapr-grpc-port 3501 Because the Dapr sidecar needs to continue running while your application is running, please open another terminal window and run the following command from this project's directory to start the demo. -```poweshell +```powershell dotnet run ``` From 4eef401e094343aab875f503b846d5dde9515c96 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Tue, 21 Oct 2025 19:42:25 -0500 Subject: [PATCH 3/5] Added copyright statement at top of file Signed-off-by: Whit Waldo --- .../GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs index 5ced0ad8133..e312fa1a2a2 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Dapr/Program.cs @@ -1,4 +1,6 @@ -// This sample shows how to create and use a simple AI agent with Dapr as the backend. +// Copyright (c) Microsoft. All rights reserved. + +// This sample shows how to create and use a simple AI agent with Dapr as the backend. using Dapr.AI.Conversation.Extensions; using Dapr.AI.Microsoft.Extensions; From 1139b64ccb2d38e4af9a6126a9bb8dd73e5e184a Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Tue, 30 Dec 2025 10:58:09 -0600 Subject: [PATCH 4/5] Update dotnet/agent-framework-dotnet.slnx That's odd the IDE added it a second time. Co-authored-by: westey <164392973+westey-m@users.noreply.github.com> --- dotnet/agent-framework-dotnet.slnx | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index 5b72fecc92f..c8a5e965e10 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -60,7 +60,6 @@ -
From 9a7ff433d2283a2eedbca0b7d899f09381868847 Mon Sep 17 00:00:00 2001 From: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com> Date: Wed, 22 Jul 2026 18:48:59 +0100 Subject: [PATCH 5/5] Address review nits: configurable Dapr gRPC endpoint and document VersionOverride Make the Dapr sidecar gRPC endpoint configurable via the DAPR_GRPC_ENDPOINT environment variable (defaulting to http://localhost:3501) and document it in the README. Add a comment explaining why the Microsoft.Extensions.* VersionOverride entries are needed and when they can be removed. --- .../dapr/Agent_With_Dapr/Agent_With_Dapr.csproj | 6 ++++++ .../AgentProviders/dapr/Agent_With_Dapr/Program.cs | 7 ++++++- .../AgentProviders/dapr/Agent_With_Dapr/README.md | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Agent_With_Dapr.csproj b/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Agent_With_Dapr.csproj index 4446861c1cd..1e1fa945e7d 100644 --- a/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Agent_With_Dapr.csproj +++ b/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Agent_With_Dapr.csproj @@ -12,6 +12,12 @@ + diff --git a/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Program.cs b/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Program.cs index 9266fa838e0..bd607c5decf 100644 --- a/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Program.cs +++ b/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Program.cs @@ -10,12 +10,17 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +// The Dapr sidecar's gRPC endpoint. This must match the --dapr-grpc-port used when starting +// the sidecar (see this sample's README). Override it with the DAPR_GRPC_ENDPOINT environment +// variable if you run the sidecar on a different port. +var daprGrpcEndpoint = Environment.GetEnvironmentVariable("DAPR_GRPC_ENDPOINT") ?? "http://localhost:3501"; + // Register the Dapr Conversation client with dependency injection. var app = Host.CreateDefaultBuilder() .ConfigureServices(services => { // Configure the gRPC endpoint for the Dapr sidecar. - services.AddDaprConversationClient((_, builder) => builder.UseGrpcEndpoint("http://localhost:3501")); + services.AddDaprConversationClient((_, builder) => builder.UseGrpcEndpoint(daprGrpcEndpoint)); // Provide the name of the Conversation component loaded in the sidecar to use. services.AddDaprChatClient(opt => opt.ConversationComponentName = "ollama"); }).Build(); diff --git a/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/README.md b/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/README.md index 653c852c043..eb21ab25e50 100644 --- a/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/README.md +++ b/dotnet/samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/README.md @@ -26,6 +26,9 @@ run the following; otherwise, replace `./Components` with the path to your compo dapr run --app-id agents --resources-path ./Components --dapr-grpc-port 3501 ``` +The sample connects to the sidecar at `http://localhost:3501` by default. If you start the sidecar on a +different gRPC port, set the `DAPR_GRPC_ENDPOINT` environment variable to match before running the sample. + Because the Dapr sidecar needs to continue running while your application is running, please open another terminal window and run the following command from this project's directory to start the demo.