Class FallbackAgentExecutor
- Namespace
- LMKit.Agents.Resilience
- Assembly
- LM-Kit.NET.dll
An executor that tries multiple agents in sequence until one succeeds.
Provides graceful degradation by falling back to alternative agents when the primary agent fails.
public sealed class FallbackAgentExecutor : IDisposable
- Inheritance
-
FallbackAgentExecutor
- Implements
- Inherited Members
Examples
var executor = new FallbackAgentExecutor()
.AddAgent(primaryAgent)
.AddAgent(backupAgent)
.AddAgent(simpleAgent)
.OnFallback((agent, ex) => Console.WriteLine($"Falling back from {agent.Identity?.Persona}: {ex.Message}"));
var result = await executor.ExecuteAsync("Hello");
Constructors
- FallbackAgentExecutor()
Initializes a new instance of the FallbackAgentExecutor class.
Properties
- AgentCount
Gets the number of configured agents.
Methods
- AddAgent(Agent)
Adds an agent to the fallback chain.
- AddAgent(Agent, Func<ResilienceContext, bool>)
Adds an agent with a condition for when it should be used.
- AddAgent(Func<Agent>)
Adds an agent factory for lazy creation.
- Dispose()
Disposes the executor.
- ExecuteAsync(string, AgentExecutionOptions, CancellationToken)
Executes with the configured agents.
- HandleException(Func<Exception, bool>)
Sets a predicate to determine which exceptions should trigger fallback.
- OnFallback(Action<Agent, Exception, int>)
Sets a callback for fallback events.