Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<PackageVersion Include="Hyperlight.HyperlightSandbox.Api" Version="0.4.0" />
<PackageVersion Include="Hyperlight.HyperlightSandbox.Guest.Python" Version="0.4.0" />
<!-- Inference SDKs -->
<PackageVersion Include="Dapr.AI.Microsoft.Extensions" Version="1.18.4" />
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.10.0" />
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="2.0.0" />
<PackageVersion Include="OllamaSharp" Version="5.4.8" />
Expand Down
1 change: 1 addition & 0 deletions dotnet/agent-framework-dotnet.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Project Path="samples/02-agents/AgentProviders/azure/Agent_With_AzureOpenAIChatCompletion/Agent_With_AzureOpenAIChatCompletion.csproj" />
<Project Path="samples/02-agents/AgentProviders/azure/Agent_With_AzureOpenAIResponses/Agent_With_AzureOpenAIResponses.csproj" />
<Project Path="samples/02-agents/AgentProviders/custom/Agent_With_CustomImplementation/Agent_With_CustomImplementation.csproj" />
<Project Path="samples/02-agents/AgentProviders/dapr/Agent_With_Dapr/Agent_With_Dapr.csproj" />
<Project Path="samples/02-agents/AgentProviders/github-copilot/Agent_With_GitHubCopilot/Agent_With_GitHubCopilot.csproj" />
<Project Path="samples/02-agents/AgentProviders/google-gemini/Agent_With_GoogleGemini/Agent_With_GoogleGemini.csproj" />
<Project Path="samples/02-agents/AgentProviders/ollama/Agent_With_Ollama/Agent_With_Ollama.csproj" />
Expand Down
6 changes: 6 additions & 0 deletions dotnet/samples/02-agents/AgentProviders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ See the README.md for each sample for the prerequisites for that sample.
| --- | --- |
| [Custom Implementation](./custom/Agent_With_CustomImplementation/) | Create an AIAgent with a custom implementation |

### [Dapr](./dapr/)

| Sample | Description |
| --- | --- |
| [Agent with Dapr](./dapr/Agent_With_Dapr/) | Create an AIAgent using Dapr's Conversation building block as the inference backend |

### [Foundry](./foundry/)

See [foundry/README.md](./foundry/README.md) for the full list of Foundry agent samples,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net10.0</TargetFrameworks>

<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
<NoWarn>$(NoWarn);DAPR_CONVERSATION</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AI.Microsoft.Extensions" />
<!--
Dapr.AI.Microsoft.Extensions depends on Microsoft.Extensions.* 10.0.8, which is higher than the
versions pinned centrally in Directory.Packages.props. Central transitive pinning is disabled above
for this sample and these two direct references are overridden to that minimum. Remove the overrides
(and the CentralPackageTransitivePinningEnabled setting) once the central versions are >= 10.0.8.
-->
<PackageReference Include="Microsoft.Extensions.DependencyInjection" VersionOverride="10.0.8" />
Comment thread
rogerbarreto marked this conversation as resolved.
<PackageReference Include="Microsoft.Extensions.Hosting" VersionOverride="10.0.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI\Microsoft.Agents.AI.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft. All rights reserved.

// This sample shows how to create and use a simple AI agent with Dapr as the backend.
// Dapr's Conversation building block is used here to route inference to Ollama.

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;

// 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(daprGrpcEndpoint));
// 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<IChatClient>();

// Use this chat client to construct an AIAgent.
AIAgent agent = daprChatClient.AsAIAgent(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."));
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Prerequisites

Before you begin, ensure you have the following prerequisites:

- .NET 10 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 `<model_name>` with the name of the model you want to use from
Ollama's library (e.g., `llama3.2`).

```powershell
ollama run <model_name>
```

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 `model` 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
```

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.

```powershell
dotnet run
```
Loading