Skip to content

TieredProviderSelector TQuery,TResult

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Providers

TieredProviderSelector<TQuery,TResult> Class

Default ITieredProviderSelector<TQuery,TResult> that iterates providers in ascending Priority order, gated by an IQuotaGate. On ProviderUnavailableException the selector falls through to the next provider.

public sealed class TieredProviderSelector<TQuery,TResult> : NexusLabs.Needlr.AgentFramework.Providers.ITieredProviderSelector<TQuery, TResult>

Type parameters

TQuery

TResult

Inheritance System.Object 🡒 TieredProviderSelector\<TQuery,TResult>

Implements NexusLabs.Needlr.AgentFramework.Providers.ITieredProviderSelector<TQuery,TResult>

Remarks

The quota partition key is resolved from the ambient IAgentExecutionContextAccessor using a QuotaPartitionSelector(IAgentExecutionContext). By default, UserId is used as the partition. Consumers that need a different partitioning strategy (e.g., tenant ID, API key) can provide a custom QuotaPartitionSelector(IAgentExecutionContext) via the constructor.

When no execution context is active (e.g., during integration tests that don't establish a scope), the partition is null and quota is global.

Constructors

TieredProviderSelector(IEnumerable<ITieredProvider<TQuery,TResult>>, IQuotaGate, IAgentExecutionContextAccessor, QuotaPartitionSelector) Constructor

public TieredProviderSelector(System.Collections.Generic.IEnumerable<NexusLabs.Needlr.AgentFramework.Providers.ITieredProvider<TQuery,TResult>> providers, NexusLabs.Needlr.AgentFramework.Providers.IQuotaGate quotaGate, NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContextAccessor contextAccessor, NexusLabs.Needlr.AgentFramework.Providers.QuotaPartitionSelector? partitionSelector=null);

Parameters

providers System.Collections.Generic.IEnumerable<NexusLabs.Needlr.AgentFramework.Providers.ITieredProvider<TQuery,TResult>>

All registered providers (filtering and ordering is handled internally).

quotaGate IQuotaGate

Quota gate for reservation/release. Use AlwaysGrantQuotaGate for no-op.

contextAccessor IAgentExecutionContextAccessor

Accessor for ambient execution context (provides partition identity).

partitionSelector QuotaPartitionSelector(IAgentExecutionContext)

Custom partition selector. Defaults to DefaultPartitionSelector (UserId).

Fields

TieredProviderSelector<TQuery,TResult>.DefaultPartitionSelector Field

The default partition selector: uses UserId from the ambient context.

public static readonly QuotaPartitionSelector DefaultPartitionSelector;

Field Value

QuotaPartitionSelector(IAgentExecutionContext)

Methods

TieredProviderSelector<TQuery,TResult>.ExecuteAsync(TQuery, CancellationToken) Method

Executes the query against providers in priority order until one succeeds.

public System.Threading.Tasks.Task<TResult> ExecuteAsync(TQuery query, System.Threading.CancellationToken cancellationToken);

Parameters

query TQuery

cancellationToken System.Threading.CancellationToken

Implements ExecuteAsync(TQuery, CancellationToken)

Returns

System.Threading.Tasks.Task<TResult>

Exceptions

NoProvidersRegisteredException
No enabled providers were registered, so there was nothing to attempt.

AllProvidersFailedException
At least one provider was registered, but every provider failed or was denied by the quota gate.

Remarks

Both exceptions inherit from NoProvidersAvailableException, so callers can catch that base type to handle both conditions uniformly.