![]() |
VOOZH | about |
dotnet add package Diagrid.AI.Microsoft.AgentFramework --version 1.0.8
NuGet\Install-Package Diagrid.AI.Microsoft.AgentFramework -Version 1.0.8
<PackageReference Include="Diagrid.AI.Microsoft.AgentFramework" Version="1.0.8" />
<PackageVersion Include="Diagrid.AI.Microsoft.AgentFramework" Version="1.0.8" />Directory.Packages.props
<PackageReference Include="Diagrid.AI.Microsoft.AgentFramework" />Project file
paket add Diagrid.AI.Microsoft.AgentFramework --version 1.0.8
#r "nuget: Diagrid.AI.Microsoft.AgentFramework, 1.0.8"
#:package Diagrid.AI.Microsoft.AgentFramework@1.0.8
#addin nuget:?package=Diagrid.AI.Microsoft.AgentFramework&version=1.0.8Install as a Cake Addin
#tool nuget:?package=Diagrid.AI.Microsoft.AgentFramework&version=1.0.8Install as a Cake Tool
Diagrid.AI.Microsoft.AgentFramework is a library that facilitates building agents using Microsoft's Agent Framework atop Dapr's Durable Workflows.
The following shows the simple dependency injection registration of MAF agents:
var builder = WebApplication.CreateBuilder(args);
// Register Dapr conversation client
builder.Services.AddDaprConversationClient();
// Register agents to run within
builder.Services.AddDaprAgents()
.WithAgent(
agentName: "SampleAgent",
conversationComponentName: "converastion-ollama",
instructions: "You are a helpful assistant. Answer normally unless the prompt asks for JSON.",
serviceLifetime: ServiceLifetime.Singleton);
var app = builder.Build();
The following elaborates to show how agent responses can be coerced into typed and deserialized JSON responses:
// Register the record that the result will be deserialized into
public sealed record StructuredAnswer(string Answer, double Confidence);
// Register the context used to deserialize the result - additional types need only be added with more `JsonSerializable` attributes
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(StructuredAnswer))]
public partial class AgentInvokerJsonContext : JsonSerializerContext;
// Program startup
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDaprConversationClient();
builder.Services.AddDaprAgents(serializationOptions =>
{
serializationOptions.AddContext(() => AgentInvokerJsonContext.Default);
}).WithAgent(
agentName: "SampleAgent",
conversationComponentName: "conversation-ollama",
instructions: "You are a helpful assistant. Answer normally unless the prompt asks for JSON.",
serviceLifetime: ServiceLifetime.Singleton);
var app = builder.Build();
The following shows how Dapr Workflows can be registered alongside agent registrations:
// Register the record that the result will be deserialized into
public sealed record StructuredAnswer(string Answer, double Confidence);
// Register the context used to deserialize the result - additional types need only be added with more `JsonSerializable` attributes
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(StructuredAnswer))]
public partial class AgentInvokerJsonContext : JsonSerializerContext;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDaprConversationClient();
builder.Services.AddDaprAgents(serializationOptions =>
{
serializationOptions.AddContext(() => AgentInvokerJsonContext.Default); // Necessary to deserialize the workflow results to strongly typed values
}, workflowOptions =>
{
workflowOptions.RegisterWorkflow<SampleWorkflow>(); // Register workflow types normally here
}).WithAgent(
agentName: "SampleAgent",
conversationComponentName: "conversation-ollama",
instructions: "You are a helpful assistant. Answer normally unless the prompt asks for JSON.",
serviceLifetime: ServiceLifetime.Singleton);
var app = builder.Build();
Agents can be invoked in a variety of ways. The following examples show the most common approaches.
IDaprAgentInvoker injectionIn this example, the IDaprAgentInvoker is registered via any of the above approaches with dependency injection and is used to provision an instance of the named agent.
public sealed record AskRequest(string Prompt);
app.MapPost("/ask", async (IDaprAgentInvoker invoker, AskRequest request, CancellationToken ct = default) =>
{
var agent = invoker.GetAgent("SampleAgent"); // Retrieves the instance of the registered agent
var response = await invoker.RunAgentAsync(agent, request.Prompt, cancellationToken: ct);
return Results.Ok(new { response = response.Text });
});
In this example, we access an instance of a registered Agent from within a Dapr Workflow context.
public sealed partial class SampleWorkflow : Workflow<string, string>
{
public override async Task<string> RunAsync(WorkflowContext context, string input)
{
var logger = context.CreateReplaySafeLogger(nameof(SampleWorkflow));
var agent = context.GetAgent("SampleAgent"); // Retrieves the instance of the registered agent
var result = await context.RunAgentAndDeserializeAsync<StructuredAnswer>(
agent: agent,
message: $"Analyze and return JSON: {{\"answer\": string, \"confidence\": number}}\n{input}"),
logger: logger)
.ConfigureAwait(false); // Runs the agent invocation as a Dapr workflow and returns the strongly-typed result
// ...
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.