Skip to content

IQuotaGate

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Providers

IQuotaGate Interface

Gates provider access based on quota. Before each provider attempt, the selector calls TryReserveAsync(string, string, CancellationToken). If denied, the provider is skipped. After the attempt, ReleaseAsync(string, string, bool, CancellationToken) reports success or failure.

public interface IQuotaGate

Derived
AlwaysGrantQuotaGate

Remarks

Quota can be global (pass null for quotaPartition) or scoped to a partition (e.g., a user, tenant, or API key). In multi-tenant environments, one partition exhausting its quota should not degrade service for other partitions. The partition identifier is opaque to the framework — consumers decide what it represents.

TieredProviderSelector<TQuery,TResult> reads the partition from the ambient IAgentExecutionContextAccessor by default, using UserId as the partition key. Consumers can override this by providing a custom QuotaPartitionSelector(IAgentExecutionContext) to the selector.

Methods

IQuotaGate.ReleaseAsync(string, string, bool, CancellationToken) Method

Releases a previously granted reservation, reporting whether the attempt succeeded.

System.Threading.Tasks.Task ReleaseAsync(string providerName, string? quotaPartition, bool succeeded, System.Threading.CancellationToken cancellationToken);

Parameters

providerName System.String

The provider that was attempted.

quotaPartition System.String

The same partition key that was passed to TryReserveAsync(string, string, CancellationToken).

succeeded System.Boolean

Whether the provider call succeeded.

cancellationToken System.Threading.CancellationToken

Cancellation token.

Returns

System.Threading.Tasks.Task

IQuotaGate.TryReserveAsync(string, string, CancellationToken) Method

Attempts to reserve quota for the given provider and partition. Returns true if the reservation was granted, false if denied.

System.Threading.Tasks.Task<bool> TryReserveAsync(string providerName, string? quotaPartition, System.Threading.CancellationToken cancellationToken);

Parameters

providerName System.String

The provider requesting quota.

quotaPartition System.String

Partition key that scopes the quota (e.g., user ID, tenant ID, API key). Pass null for global (unpartitioned) quota.

cancellationToken System.Threading.CancellationToken

Cancellation token.

Returns

System.Threading.Tasks.Task<System.Boolean>