Documentation
Table of Contents

Class ClientTrials

Namespace
IntentSharp.Trials
Assembly
IntentSharp.dll

The client's side-by-side runs of intent versions: while a trial runs, every SampleEveryth call of an intent defined in the trial's document also runs the candidate version's definition of that intent with the same input, and the two results are compared. Start a trial with StartAsync(IntentTrial, CancellationToken), read how it is going with GetReportAsync(DocumentId, CancellationToken), and when the candidate has earned it, promote it with the document store's ActivateAsync(DocumentId, long, CancellationToken): the library never promotes a version on its own.

[Experimental("INTENTSHARP002")]
public sealed class ClientTrials
Inheritance
object
ClientTrials
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Extension Methods

Remarks

The core reads no intent definitions. IntentSharp.Catalog's IntentRuntime runs the candidate for every definition it loaded from a document store: on a sampled call it reads the candidate version from the catalog's store, runs its definition of the intent after the running version's, under the guardrail sets of both versions so the candidate never runs under weaker enforcement, compares the two verified values as JSON, and returns the running version's result with the candidate's tokens added to its usage. The candidate's model calls count in the client's totals like any other. A runner of your own over a versioned document calls the same two members: TryBeginSample(DocumentId, out IntentTrial?) before each call, and Record(IntentTrial, TrialSample) after a sampled one.

With a document store (WithDocumentStore(IDocumentStore)), each trial's counts are also kept in the store's state at key trial/<document path>/<sequence> as { "calls": n, "checks": n, "agreed": n, "differing": n, "candidateFailed": n, "candidateUnavailable": n, "candidateInputTokens": n, "candidateOutputTokens": n, "since": time, "last": time }, where checks counts the samples and differing those that differed, as a rule version's side-by-side tally counts them. Each sample adds to those counts after the call, off the caller's path, with the etag it read them with; the first counts are created with TryCreateStateAsync(string, JsonNode, CancellationToken), so of two clients that write a trial's first counts at once one creates them and the other adds its own. The calls counted since the last sample go with the next one and with StopAsync(DocumentId, CancellationToken). A trial started again, in this process or after a restart, continues from the counts the store holds, and so do clients in other processes on the same store, each adding its own; a store of your own that keeps the default create-only write, which reads and then writes, can still let one client's first counts replace another's. The counts are advisory: a write that conflicts twice, or that the store refuses, is retried with the next sample and is lost when the trial stops first, with a Debug line either way; the counts not yet written when the client is disposed without StopAsync(DocumentId, CancellationToken) are lost too, and a read of the counts that fails starts the trial from zero. Without a store a report holds this client's counts only.

Thread-safe. One trial per document at a time.

Properties

Reports

The reports of the trials running now, in document path order. A snapshot: it does not change as calls are counted.

Methods

GetReportAsync(DocumentId, CancellationToken)

The report of the trial of document that is running now; null when none is. With a document store, the write of every sample recorded so far has finished when this returns.

Record(IntentTrial, TrialSample)

For a runner: records how a sampled call compared. trial is the one TryBeginSample(DocumentId, out IntentTrial?) returned; a sample of a trial that has stopped since, or was started again, is dropped. With a document store, the sample is added to the counts in its state after this returns.

StartAsync(IntentTrial, CancellationToken)

Starts running trial's candidate side by side with the running version of its document. With a document store, the trial continues from the counts its state holds for the same document and version.

StopAsync(DocumentId, CancellationToken)

Stops the trial of document: no later call runs its candidate, and a sample recorded for it afterwards is dropped. With a document store, the calls counted since the last sample are written to its state before this returns. Nothing happens when no trial of the document is running.

TryBeginSample(DocumentId, out IntentTrial?)

For a runner: counts one call of an intent defined in document, and returns true, with the trial, when that call is one the trial samples (every SampleEveryth since the trial started). Run the candidate on such a call, then pass the trial and the outcome to Record(IntentTrial, TrialSample). Returns false, and counts nothing, when no trial of the document is running.