Class SpecialistRuntime
- Namespace
- IntentSharp.Specialist
- Assembly
- IntentSharp.Specialist.dll
Runs catalog intents on specialists: models defined per intent, which an ISpecialistService provides, so an application can use several models easily, in one context or across several. The runtime obtains and uses the model for an intent; it never changes a model. It sits beside the Catalog's IntentRuntime. For each intent it sends a request built from the intent's current definition, waits until the service offers a specialist, judges whether the offer fits, and from then on runs the intent with the definition the service returned, on that specialist, through the normal pipeline. When the requested definition changes, the next ensure or run requests again and waits again, unless a KeepPreviousPolicy lets the specialist in use keep serving while the new one is handled in the background.
public sealed class SpecialistRuntime
- Inheritance
-
objectSpecialistRuntime
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Remarks
A call that finds a specialist in use for the same definition (the same object, or a definition with the same content) runs at once: it neither gathers context nor builds a request. So a change to the definition is picked up by the next call, and a change to the context alone is picked up by RefreshAsync(string, CancellationToken).
A specialist is kept per intent name and request hash. Concurrent calls for one intent share one request and one wait. The wait happens before the pipeline starts, so nothing else answers the call meanwhile, and every failure before the run (the waits ran out, the offer did not fit, the hourly request limit, no specialist under Explicit, an offer the runtime cannot use) is an exception derived from IntentSharpException. Everything the specialist gets wrong is an issue in an ordinary result.
A request that ran out of waits stays open: the next call waits on it again without sending a new request. An offer that did not fit is remembered too, so a later call for the same definition throws again without a new request, unless a not-fit handler requests another definition; RetireAsync(string, CancellationToken) forgets both. Thread-safe; register one per application and service.
Constructors
Properties
- Catalog
The catalog of the requested definitions.
- Options
The settings, read on every call.
- Router
The router for offers that bring a provider of their own, or null.
- Service
The specialist service.
- Store
Where requests, offers and fit reports are kept.
Methods
- EnsureAsync(string, CancellationToken)
Makes sure a fitting specialist is in use for the intent's current definition: reuses the one in use, or the request already recorded for this definition, or sends a new request; then waits, judges the offer and, when it fits, puts it in use. Returns where the intent stands. When a specialist is in use for an earlier definition and the intent's KeepPreviousPolicy allows it, the new request is handled in the background instead, and this returns at once with the specialist in use and the change in Pending.
- FindHeldAsync(string, CancellationToken)
The held specialist whose name, as the service gave it, is
specialistName(compared exactly); the one held last when several intents hold specialists of that name; null when none is. A record whose service gave no name is not found this way, and stays reachable by its intent through GetHeldAsync(string, CancellationToken).
- GetHeldAsync(string, CancellationToken)
The specialist held for the intent, or null when none is held.
- GetStatus(string)
Where the intent stands with its specialist. An intent this runtime has not handled yet is None.
- ListHeldAsync(CancellationToken)
Every specialist held in Store, one per intent: the specialist's name as the service gave it, the definition it returned, how it is reached, and the verdict. Empty when HoldSpecialists is off or the store keeps no held records.
- RefreshAsync(string, CancellationToken)
Gathers the intent's context again now and, when the request it builds differs from the one the specialist in use answers, requests and waits as EnsureAsync(string, CancellationToken) does. Runs and ensures do not gather context while a specialist is in use for the same definition, so call this when the context alone has changed, for example after the documents a context source reads were updated. A change to the definition is picked up by the next call without it. Returns where the intent stands.
- RetireAsync(string, CancellationToken)
Retires the intent's specialist: tells the service, stops using it, and forgets the request, the offer, the fit report and the held record kept for it. The next ensure or run requests again. An intent this runtime has not handled, but whose specialist the store holds (for example from before a restart), is retired from the held record. Returns false when there was nothing to retire.
- RunAsync(string, object?, CancellationToken)
Runs the intent on its specialist and returns the verified result as JSON, whatever its shape. Waits and fails before the run as RunAsync<T>(string, object?, CancellationToken) does.
- RunAsync<T>(string, object?, CancellationToken)
Runs the intent on its specialist and returns a verified
T. Under IntentCall it first ensures a specialist as EnsureAsync(string, CancellationToken) does, and the call waits for it; under Explicit it needs one already in use for the current definition. Then the definition the service returned runs through the normal pipeline, as RunAsync<T>(string, object?, CancellationToken) runs a catalog definition.
- RunManyAsync(string, IEnumerable<object?>, int, CancellationToken)
Runs the intent on its specialist once for each input and returns one verified result as JSON per input, in the order of the inputs, as RunManyAsync<T>(string, IEnumerable<object?>, int, CancellationToken) does.
- RunManyAsync<T>(string, IEnumerable<object?>, int, CancellationToken)
Runs the intent on its specialist once for each input, with at most
maxConcurrencyruns at a time, and returns one verified result per input, in the order of the inputs. The specialist is ensured once, as RunAsync<T>(string, object?, CancellationToken) ensures it, before the first run; a failure before the runs throws and runs nothing. Each run is its own call through the normal pipeline, with its own AIResult<T>, so one input that fails does not stop the others.