ModelProviderHealthCache
AgentPrism.Core.dllCaches the health-check results of the registered model providers.
public sealed class ModelProviderHealthCacheInheritance
Section titled “Inheritance”object ← ModelProviderHealthCache
Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”The /api/models/health endpoint does not go to the provider on every
call; the result is returned from the cache for
AgentPrismHealthOptions.CacheTtl. refresh: true bypasses
the cache and goes to the provider again.
This class is not tied to IModelProviderRegistry — it reads
IModelProvider singletons directly through
IEnumerable<IModelProvider>. This lets it check whether each
provider implements IModelProviderHealthCheck without adding a
member to the IModelProvider interface; a provider that
does not implement it has a status of ModelProviderHealthStatus.Unknown.
A provider whose circuit breaker is open is reported as ModelProviderHealthStatus.Unhealthy regardless of the raw cached check result — if real chat calls are failing, that is a more reliable signal than a raw connectivity probe. This layer is read FRESH on every call and is not written to the cache.
Constructors
Section titled “Constructors”ModelProviderHealthCache(IEnumerable<IModelProvider>, IOptionsMonitor<AgentPrismOptions>, ModelProviderCircuitBreaker?, TimeProvider?)
Section titled “ ModelProviderHealthCache(IEnumerable<IModelProvider>, IOptionsMonitor<AgentPrismOptions>, ModelProviderCircuitBreaker?, TimeProvider?)”Creates a new health cache.
public ModelProviderHealthCache(IEnumerable<IModelProvider> providers, IOptionsMonitor<AgentPrismOptions> optionsMonitor, ModelProviderCircuitBreaker? circuitBreaker = null, TimeProvider? timeProvider = null)Parameters
Section titled “Parameters”providers IEnumerable<IModelProvider>
The registered model providers.
optionsMonitor IOptionsMonitor<AgentPrismOptions>
Settings used to read the cache TTL.
circuitBreaker ModelProviderCircuitBreaker?
The circuit breaker used to reflect circuit state into the result.
timeProvider TimeProvider?
The time source. If null, the system clock is used.
Exceptions
Section titled “Exceptions”providers
or
optionsMonitor
is null.
Methods
Section titled “Methods”GetAllAsync(bool, CancellationToken)
Section titled “ GetAllAsync(bool, CancellationToken)”Returns the health status of every registered provider (sorted by name).
public ValueTask<IReadOnlyList<ModelProviderHealth>> GetAllAsync(bool refresh, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”refresh bool
Whether to bypass the cache and go to the provider again.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<IReadOnlyList<ModelProviderHealth>>
One record per provider.
GetAsync(string, bool, CancellationToken)
Section titled “ GetAsync(string, bool, CancellationToken)”Returns the health status of a single provider.
public ValueTask<ModelProviderHealth?> GetAsync(string providerName, bool refresh, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”providerName string
The provider name.
refresh bool
Whether to bypass the cache and go to the provider again.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<ModelProviderHealth?>
The status if the provider is registered; otherwise null.
TryPeek(string, out ModelProviderHealth)
Section titled “ TryPeek(string, out ModelProviderHealth)”Returns the last known status from the cache without making a network
call. Intended for fast endpoints such as /api/models to fill in a status field.
public bool TryPeek(string providerName, out ModelProviderHealth health)Parameters
Section titled “Parameters”providerName string
The provider name.
health ModelProviderHealth
The health record, if found.
Returns
Section titled “Returns”true if a record exists in the cache.