Dapr

Dapr Conversation の構成要素は、Dapr サイドカーを介してモデル推論をルーティングし、Agent Framework .NET エージェントをバックできるIChatClientを公開します。 モデル プロバイダーと資格情報は、エージェント プロセスで直接ではなく、Dapr Conversation コンポーネントで構成されます。

前提条件

  • .NET 10 以降。
  • Docker と Dapr CLI。
  • 構成された Dapr Conversation コンポーネント (Ollama でサポートされるコンポーネントなど)。

パッケージをインストールする

dotnet add package Dapr.AI.Microsoft.Extensions
dotnet add package Microsoft.Agents.AI --prerelease

Configuration

DAPR_GRPC_ENDPOINT="http://localhost:3501"

DAPR_GRPC_ENDPOINT は省略可能であり、既定値は http://localhost:3501 です。 アプリケーション コードの ConversationComponentName を、 ollamaなどの Dapr Conversation コンポーネントの名前に設定します。

Dapr に基づくエージェントを作成する

依存関係の挿入を使用して Dapr サイドカー エンドポイントと Conversation コンポーネントを構成し、 IChatClientを解決して、エージェントに変換します。

// 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."));

プロバイダーの機能は、Dapr Conversation コンポーネントとその背後にあるモデルによって異なります。

Tools

ツールのサポートは、構成された Dapr Conversation コンポーネントとモデルから継承されます。

ツール 地位 Notes
関数ツール 場合により異なる 構成されたコンポーネントとモデルからの関数呼び出しのサポートが必要です。
ツールの承認 場合により異なる モデルが関数ツール呼び出しを生成するときに使用できます。
プロバイダーホスト型ツール Dapr では、個別の Agent Framework ホステッド ツール サーフェスは追加されません。
ローカル MCP ツール アプリケーション プロセスで実行されます。

次のステップ