MonadicSharp.Agents 1.0.0

dotnet add package MonadicSharp.Agents --version 1.0.0
                    
NuGet\Install-Package MonadicSharp.Agents -Version 1.0.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="MonadicSharp.Agents" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MonadicSharp.Agents" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MonadicSharp.Agents" />
                    
Project file
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 MonadicSharp.Agents --version 1.0.0
                    
#r "nuget: MonadicSharp.Agents, 1.0.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 MonadicSharp.Agents@1.0.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=MonadicSharp.Agents&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MonadicSharp.Agents&version=1.0.0
                    
Install as a Cake Tool

MonadicSharp.Agents

Typed, composable AI agent pipelines for .NET 8 — using Railway-Oriented Programming.

NuGet .NET


Overview

MonadicSharp.Agents is the core orchestration layer of the MonadicSharp.Framework. It provides:

  • IAgent<TInput, TOutput> — the typed contract every agent implements
  • AgentPipeline — sequential pipelines with short-circuit on failure
  • ParallelAgentPipeline — run multiple agents concurrently, collect all results
  • AgentOrchestrator — dispatch by name, manage a registry of agents
  • CircuitBreaker — prevent cascading failures in multi-agent systems
  • AgentContext — capability-based access control per invocation
  • PipelineResult<T> — full execution trace even on partial failure

Installation

dotnet add package MonadicSharp.Agents

Core Concepts

1. Define an Agent

public class SummaryAgent : IAgent<string, string>
{
    public string Name => "SummaryAgent";
    public AgentCapability RequiredCapabilities => AgentCapability.None;

    public async Task<Result<string>> ExecuteAsync(
        string input,
        AgentContext context,
        CancellationToken ct = default)
    {
        if (string.IsNullOrWhiteSpace(input))
            return Result<string>.Failure(AgentError.InvalidInput(Name, "Input cannot be empty"));

        var summary = await CallLlmAsync(input, ct);
        return Result<string>.Success(summary);
    }
}

2. Build a Pipeline

var result = await AgentPipeline
    .Start("DocumentProcessing", new ExtractorAgent())
    .Then(new CleanerAgent())
    .Then(new SummaryAgent())
    .Then(new ClassifierAgent())
    .RunAsync(rawDocument, context);

// result.IsSuccess, result.Steps, result.TotalDuration
Console.WriteLine(result); // Pipeline[DocumentProcessing] OK — 4 steps, 342ms

The pipeline short-circuits on the first failure — subsequent agents do not run. The Steps trace is always populated up to the point of failure.

3. AgentContext and Capabilities

var context = AgentContext.Create(
    sessionId: Guid.NewGuid().ToString(),
    grantedCapabilities: AgentCapability.ReadDatabase | AgentCapability.CallExternalApi);

// Agents declare what they need:
public AgentCapability RequiredCapabilities => AgentCapability.ReadDatabase;
// The pipeline checks this before calling ExecuteAsync.

4. Circuit Breaker

var breaker = new CircuitBreaker(
    name: "ExternalLlm",
    failureThreshold: 5,
    openDuration: TimeSpan.FromSeconds(30));

var result = await breaker.ExecuteAsync(
    ct => llmAgent.ExecuteAsync(input, context, ct));

// result is Failure with AgentError.CircuitOpen when the circuit is OPEN

States: CLOSED (normal) → OPEN (blocking after threshold) → HALF-OPEN (probing) → CLOSED.

5. Parallel Pipeline

var parallelResult = await ParallelAgentPipeline
    .Create<string>("MultiClassifier")
    .Add(sentimentAgent)
    .Add(topicAgent)
    .Add(languageAgent)
    .RunAsync(text, context);

// parallelResult.Results — IReadOnlyList<Result<string>> in order
// parallelResult.AllSucceeded, parallelResult.AnyFailed

6. AgentOrchestrator

var orchestrator = new AgentOrchestrator();
orchestrator.Register("summary", summaryAgent);
orchestrator.Register("classify", classifierAgent);

var result = await orchestrator.RunAsync("summary", input, context);

Error Codes

Code Meaning
AGENT_CAPABILITY_DENIED Required capability not granted in context
AGENT_PIPELINE_STEP_FAILED A pipeline step returned a failure
AGENT_CIRCUIT_OPEN CircuitBreaker is in OPEN state
AGENT_CIRCUIT_HALF_OPEN_REJECTED Only one probe allowed in HALF-OPEN
AGENT_TIMEOUT Operation exceeded the allowed duration
AGENT_CANCELLED CancellationToken was triggered
AGENT_UNHANDLED_EXCEPTION Unexpected exception caught by the pipeline
AGENT_INVALID_INPUT Agent-specific input validation failed
AGENT_NOT_FOUND Orchestrator: no agent registered with that name

DI Registration

services.AddMonadicSharpAgents();

License

MIT — part of MonadicSharp.Framework.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on MonadicSharp.Agents:

Package Downloads
MonadicSharp.Http

Result-aware HTTP client for MonadicSharp — HTTP errors, timeouts, and deserialization failures are first-class Result values. Includes typed retry policies with exponential backoff and integration with MonadicSharp.Agents CircuitBreaker.

MonadicSharp.Persistence

Result-aware persistence layer for MonadicSharp — NotFound, Conflict, and DatabaseError are first-class Result values, never null or exceptions. Provides IRepository, IReadRepository, IUnitOfWork abstractions and an EF Core 8 implementation.

MonadicSharp.Framework

Meta-package for the MonadicSharp Framework — install this single package to get Agents, Caching, Http, Persistence, Security, and Telemetry in one shot. For à-la-carte usage, reference individual MonadicSharp.* packages instead.

MonadicSharp.Telemetry

Observability layer for MonadicSharp.Agents — OpenTelemetry-compatible metrics and distributed tracing for agent executions, pipelines, and circuit breakers. Zero external dependencies: built on System.Diagnostics.Metrics and System.Diagnostics.ActivitySource.

MonadicSharp.Caching

Result-aware caching layer for MonadicSharp — cache misses and errors are first-class Result values, never null or exceptions. Supports IMemoryCache, IDistributedCache, and transparent agent output caching via CachingAgentWrapper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 39 3/3/2026

v1.0.0: Initial release — IAgent typed contract, AgentContext with capability sandboxing, AgentCapability flags, sequential and parallel pipelines, CircuitBreaker, AgentOrchestrator, AuditTrail.