Skip to content

IExperimentStore

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

Defines the store for A/B experiments.

public interface IExperimentStore

AdvanceCanaryRampAsync(string, string, IReadOnlyList<ExperimentVariant>, CancellationToken)

Section titled “ AdvanceCanaryRampAsync(string, string, IReadOnlyList<ExperimentVariant>, CancellationToken)”

Applies a gradual-increase decision from the canary evaluator. The experiment remains ExperimentStatus.Running and only variant weights change. Only the canary evaluation service calls this method.

ValueTask<Experiment> AdvanceCanaryRampAsync(string tenantId, string name, IReadOnlyList<ExperimentVariant> variants, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

variants IReadOnlyList<ExperimentVariant>

The new variant weights. They must total 100.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment>

The updated experiment.

DeleteAsync(string, string, CancellationToken)

Section titled “ DeleteAsync(string, string, CancellationToken)”

Deletes an experiment. A running experiment must be stopped before deletion.

ValueTask<bool> DeleteAsync(string tenantId, string name, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when deletion occurs.

GetAsync(string, string, CancellationToken)

Section titled “ GetAsync(string, string, CancellationToken)”

Gets the experiment with the specified name.

ValueTask<Experiment?> GetAsync(string tenantId, string name, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment?>

The experiment, or null when it does not exist.

GetRunningAsync(string, string, CancellationToken)

Section titled “ GetRunningAsync(string, string, CancellationToken)”

Gets the ExperimentStatus.Running experiment for an agent. Returns null when none exists. An agent can have at most one running experiment at a time.

ValueTask<Experiment?> GetRunningAsync(string tenantId, string agentName, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

agentName string

The agent name.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment?>

The running experiment, or null when none exists.

Lists all experiments for a tenant by name.

ValueTask<IReadOnlyList<Experiment>> ListAsync(string tenantId, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<Experiment>>

The experiments.

ListRunningWithCanaryAsync(CancellationToken)

Section titled “ ListRunningWithCanaryAsync(CancellationToken)”

Lists experiments across all tenants that are ExperimentStatus.Running and define Experiment.Canary.

ValueTask<IReadOnlyList<Experiment>> ListRunningWithCanaryAsync(CancellationToken cancellationToken = default)

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<Experiment>>

The running experiments that define a canary policy.

This is a maintenance operation for the canary evaluator. It scans all tenants for the same reason as IPendingApprovalStore.ExpireAsync.

RollbackCanaryAsync(string, string, IReadOnlyList<ExperimentVariant>, string, CancellationToken)

Section titled “ RollbackCanaryAsync(string, string, IReadOnlyList<ExperimentVariant>, string, CancellationToken)”

Applies an automatic rollback decision from the canary evaluator. It moves the experiment to ExperimentStatus.Stopped, restores weights to the control variant, and writes Experiment.RollbackReason.

ValueTask<Experiment> RollbackCanaryAsync(string tenantId, string name, IReadOnlyList<ExperimentVariant> variants, string reason, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

variants IReadOnlyList<ExperimentVariant>

The weights restored to the control variant. They must total 100.

reason string

The rollback reason.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment>

The updated experiment.

The caller, the canary evaluation service, must write the audit trail before calling this method. If that write fails, it must not call this method: a rollback that cannot be audited is not applied.

Creates or updates an experiment. Only an ExperimentStatus.Draft experiment can be updated. Updating a started experiment throws an AgentPrismException.

ValueTask<Experiment> SaveAsync(Experiment experiment, CancellationToken cancellationToken = default)

experiment Experiment

The experiment to save.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment>

The saved experiment.

SetCanaryPolicyAsync(string, string, CanaryPolicy?, CancellationToken)

Section titled “ SetCanaryPolicyAsync(string, string, CanaryPolicy?, CancellationToken)”

Defines or removes an experiment canary policy. Pass null for policy to remove it.

ValueTask<Experiment> SetCanaryPolicyAsync(string tenantId, string name, CanaryPolicy? policy, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

policy CanaryPolicy?

The new policy, or null to remove it.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment>

The updated experiment.

Unlike IExperimentStore.SaveAsync, this method works regardless of experiment status, Draft or Running. A canary policy can be defined while an experiment already receives traffic.

StartAsync(string, string, CancellationToken)

Section titled “ StartAsync(string, string, CancellationToken)”

Moves the experiment to ExperimentStatus.Running. Throws an AgentPrismException when another experiment runs for the same agent.

ValueTask<Experiment> StartAsync(string tenantId, string name, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment>

The updated experiment.

StopAsync(string, string, CancellationToken)

Section titled “ StopAsync(string, string, CancellationToken)”

Moves the experiment to ExperimentStatus.Stopped.

ValueTask<Experiment> StopAsync(string tenantId, string name, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

name string

The experiment name.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Experiment>

The updated experiment.