Skip to content

AgentPrismTestHost

Namespace AgentPrism.Testing · Assembly AgentPrism.Testing.dll

In-memory AgentPrism host.

public sealed class AgentPrismTestHost : IAsyncDisposable

objectAgentPrismTestHost

IAsyncDisposable

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Built on WebApplication.CreateSlimBuilder + UseTestServer; Microsoft.AspNetCore.Mvc.Testing’s WebApplicationFactory<T> is not used, because it requires an entry-point assembly and locks the consumer into a hosting model. In-memory stores are a first-class implementation, so the host needs no database.

AIFunctionArguments.Services is empty in the MAF pipeline: a dependency your own tool needs is not resolved from DI. Take the dependency in the tool’s CONSTRUCTOR and register it through a factory with services.AddSingleton(provider => new AgentPrismToolRegistration(new MyTool(provider), ...)).

HTTP client bound to the host.

public HttpClient Client { get; }

HttpClient

The host’s service provider.

public IServiceProvider Services { get; }

IServiceProvider

public ValueTask DisposeAsync()

ValueTask

RunAsync(string, string, CancellationToken)

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

Runs an agent, drains the stream to completion, and returns its record.

public ValueTask<RunAssertions> RunAsync(string agentName, string message, CancellationToken cancellationToken = default)

agentName string

The name of the agent to run.

message string

The user message.

cancellationToken CancellationToken

Cancellation token.

ValueTask<RunAssertions>

An object for building assertions on the run.

AgentPrismAssertionException

The run was not accepted, or its record was not found in the store.

StartAsync(Action<AgentPrismTestHostOptions>?, CancellationToken)

Section titled “ StartAsync(Action<AgentPrismTestHostOptions>?, CancellationToken)”

Builds and starts a host.

public static ValueTask<AgentPrismTestHost> StartAsync(Action<AgentPrismTestHostOptions>? configure = null, CancellationToken cancellationToken = default)

configure Action<AgentPrismTestHostOptions>?

Changes the host settings.

cancellationToken CancellationToken

Cancellation token.

ValueTask<AgentPrismTestHost>

The running host.