Nedo.AspNet.AgentOrchestration
1.2.0
dotnet add package Nedo.AspNet.AgentOrchestration --version 1.2.0
NuGet\Install-Package Nedo.AspNet.AgentOrchestration -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nedo.AspNet.AgentOrchestration" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nedo.AspNet.AgentOrchestration" Version="1.2.0" />
<PackageReference Include="Nedo.AspNet.AgentOrchestration" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nedo.AspNet.AgentOrchestration --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Nedo.AspNet.AgentOrchestration, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nedo.AspNet.AgentOrchestration@1.2.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nedo.AspNet.AgentOrchestration&version=1.2.0
#tool nuget:?package=Nedo.AspNet.AgentOrchestration&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Nedo.AspNet.AgentOrchestration
A provider-agnostic .NET library for orchestrating AI agents in ASP.NET applications. Seamlessly switch between OpenAI, Claude, and Gemini — or run all three side-by-side — with a unified API, middleware pipeline, tool loop engine, and streaming support.
Features
- Multi-Provider — Built-in support for OpenAI, Anthropic Claude, and Google Gemini
- Middleware Pipeline — ASP.NET-style middleware chain (Logging, Retry, Timeout, Rate Limit, Tracing)
- Tool Loop Engine — Automatic iterate-execute-append cycle with safety controls
- Streaming — SSE streaming with
IAsyncEnumerable<AgentStreamEvent> - Agent Definitions — Named agents with provider, model, system prompt, and tool bindings
- Testable — In-memory provider for unit testing without HTTP calls
- OpenTelemetry — Built-in tracing middleware with activity spans
Installation
dotnet add package Nedo.AspNet.AgentOrchestration
Quick Start
using Nedo.AspNet.AgentOrchestration.Configuration;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAgentOrchestration(options =>
{
// Register providers
options.UseOpenAI("your-openai-key");
options.UseClaude("your-claude-key");
options.UseGemini("your-gemini-key");
options.DefaultProvider = "openai";
// Define agents
options.AddAgent("assistant", agent =>
{
agent.UseProvider("openai");
agent.UseModel("gpt-4o-mini");
agent.UseTemperature(0.7f);
agent.UseMaxTokens(2048);
agent.UseSystemPrompt("You are a helpful AI assistant.");
});
options.AddAgent("code-generator", agent =>
{
agent.UseProvider("claude");
agent.UseModel("claude-sonnet-4-20250514");
agent.UseTemperature(0.2f);
agent.UseMaxTokens(4096);
agent.UseSystemPrompt("You are an expert code generation assistant.");
});
// Middleware pipeline
options.Pipeline(pipeline =>
{
pipeline.UseLogging();
pipeline.UseRetry();
pipeline.UseTimeout(TimeSpan.FromSeconds(30));
});
});
Invoke an Agent
public class ChatController : ControllerBase
{
private readonly IAgentOrchestrator _orchestrator;
public ChatController(IAgentOrchestrator orchestrator)
=> _orchestrator = orchestrator;
[HttpPost]
public async Task<IActionResult> Chat([FromBody] ChatRequest request, CancellationToken ct)
{
var messages = new[] { ChatMessage.User(request.Message) };
var response = await _orchestrator.InvokeAsync("assistant", messages, cancellationToken: ct);
return Ok(new { response.Message.Content, response.Usage, response.FinishReason });
}
}
Stream a Response
[HttpPost("stream")]
public async Task StreamChat([FromBody] ChatRequest request, CancellationToken ct)
{
Response.ContentType = "text/event-stream";
var messages = new[] { ChatMessage.User(request.Message) };
await foreach (var evt in _orchestrator.InvokeStreamingAsync("assistant", messages, cancellationToken: ct))
{
if (evt is TextDeltaEvent delta)
{
await Response.WriteAsync($"data: {delta.Delta}\n\n", ct);
await Response.Body.FlushAsync(ct);
}
}
}
Supported Providers
| Provider | Extension | Models |
|---|---|---|
| OpenAI | UseOpenAI(apiKey) |
gpt-4o, gpt-4o-mini, o1, etc. |
| Anthropic Claude | UseClaude(apiKey) |
claude-sonnet-4-20250514, claude-3-haiku, etc. |
| Google Gemini | UseGemini(apiKey) |
gemini-2.0-flash, gemini-pro, etc. |
| In-Memory (Testing) | UseInMemory() |
N/A |
Built-in Middleware
| Middleware | Method | Description |
|---|---|---|
| Logging | UseLogging() |
Structured logging with invocation IDs |
| Retry | UseRetry() |
Exponential backoff with jitter |
| Timeout | UseTimeout(duration) |
Hard timeout on invocations |
| Rate Limit | UseRateLimit(...) |
Token bucket rate limiting |
| Tracing | UseTracing() |
OpenTelemetry activity spans |
Tool Loop Engine
Register tools and the engine automatically handles the iterate-execute-append cycle:
options.AddTool<WeatherTool>();
options.AddTool<DatabaseTool>();
options.AddAgent("tool-agent", agent =>
{
agent.UseProvider("openai");
agent.UseModel("gpt-4o");
agent.UseTools("weather", "database");
});
// Safety controls
options.ToolLoop = new ToolLoopOptions
{
MaxIterations = 10,
EnableCycleDetection = true,
OverflowBehavior = OverflowBehavior.ReturnPartial
};
Testing
Use the in-memory provider for unit tests without HTTP calls:
services.AddAgentOrchestration(options =>
{
options.UseInMemory(provider =>
{
provider.OnInvoke(request => new AgentProviderResponse
{
Message = new ChatMessage("assistant", "Mock response"),
Usage = new AgentUsage(10, 20)
});
});
options.AddAgent("test-agent", agent =>
{
agent.UseProvider("in-memory");
agent.UseModel("test");
});
});
Project Structure
src/Nedo.AspNet.AgentOrchestration/
├── Abstractions/ # IAgentOrchestrator, IAgentProvider, IAgentTool, IAgentInvocationMiddleware
├── Agents/ # AgentDefinition, AgentBase, AgentAttribute, AgentRegistry
├── Configuration/ # AddAgentOrchestration(), AgentBuilder, PipelineBuilder
├── Middleware/ # Logging, Retry, Timeout, RateLimit, Tracing
├── Models/ # ChatMessage, AgentOptions, ToolCall, ToolResult, AgentResponse
├── Pipeline/ # AgentInvocationContext, InvocationPipeline
├── Providers/ # OpenAI, Claude, Gemini implementations
├── Streaming/ # AgentStreamEvent, TextDeltaEvent, CompletionEvent
├── Testing/ # InMemoryAgentProvider, InMemoryTool
├── ToolLoop/ # ToolLoopEngine, ToolLoopOptions, ToolLoopState
└── AgentOrchestrator.cs
test/Nedo.AspNet.AgentOrchestration.Tests/ # 24 unit tests
sample/Nedo.AspNet.AgentOrchestration.Sample/ # ASP.NET sample app
docs/ # Architecture & usage documentation
Documentation
| Document | Description |
|---|---|
| Overview | Architecture and design principles |
| Invocation Pipeline | Middleware chain design |
| Invocation Context | Request context and properties |
| Tool Loop Engine | Tool execution lifecycle |
| Streaming Engine | SSE streaming support |
| Provider Abstraction | Building custom providers |
| Agent Definition | Defining and registering agents |
| Observability | Logging and tracing |
| Reliability | Retry, timeout, rate limiting |
| Testability | In-memory testing patterns |
| Configuration Reference | All options and settings |
Examples
| Example | Description |
|---|---|
| Simple Chat | Basic chat agent |
| Code Generation | Code generation agent |
| Multi-Agent Pipeline | Chaining multiple agents |
| Tool Library | Building reusable tools |
| Testing | Unit testing patterns |
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- System.Threading.RateLimiting (>= 9.0.17)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.