Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
O bloco de construção do Dapr Conversation encaminha a inferência do modelo através de um sidecar Dapr e expõe um IChatClient que pode apoiar um agente .NET do Agent Framework. O fornecedor do modelo e as credenciais são configurados no componente Dapr Conversation, em vez de diretamente no processo do agente.
Pré-requisitos
- .NET 10 ou posterior.
- Docker e a CLI Dapr.
- Um componente Dapr Conversation configurado, como um componente suportado por Ollama.
Instale os pacotes
dotnet add package Dapr.AI.Microsoft.Extensions
dotnet add package Microsoft.Agents.AI --prerelease
Configuration
DAPR_GRPC_ENDPOINT="http://localhost:3501"
DAPR_GRPC_ENDPOINT é opcional e o padrão é http://localhost:3501. Definir ConversationComponentName no código da aplicação o nome do componente Dapr Conversation, como ollama.
Criar um agente apoiado pela Dapr
Configure o endpoint sidecar Dapr e o componente Conversation através de injeção de dependências, resolva o IChatClient, e converta-o para agente.
// 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."));
As capacidades dos fornecedores dependem do componente Dapr Conversation e do modelo por trás dele.
Tools
O suporte à ferramenta é herdado do componente e modelo Dapr Conversation configurado.
| Tool | Situação | Notes |
|---|---|---|
| Ferramentas Funcionais | Varia | Requer suporte para chamadas de funções a partir do componente e modelo configurados. |
| Aprovação de Ferramentas | Varia | Disponível quando o modelo produz chamadas de ferramenta funcional. |
| Ferramentas alojadas pelo fornecedor | ❌ | O Dapr não adiciona uma superfície separada de ferramenta hospedada no Agent Framework. |
| Ferramentas MCP Locais | ✅ | Corre no processo de candidatura. |