Skip to content

FakeModelProvider

Namespace AgentPrism.Testing · Assembly AgentPrism.Testing.dll

Configurable, non-networked fake model provider.

public sealed class FakeModelProvider : IModelProvider, IDisposable

objectFakeModelProvider

IModelProvider, IDisposable

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

var provider = new FakeModelProvider().
CallsTool("get_order_status", new { orderId = "ORD-7" }).
EchoesUserMessage();

Five fluent methods (FakeModelProvider.RespondsWith, FakeModelProvider.EchoesUserMessage, FakeModelProvider.CallsTool, FakeModelProvider.ForModel, FakeModelProvider.WithModel) cover all the fake provider behavior that is today duplicated across five separate files in AgentPrism’s test suites.

Each model has its own ordered response queue (selected with FakeModelProvider.ForModel; the default queue is used when none is selected). A call pops the next step in the queue; once the queue is drained, every subsequent call returns either the echo set with FakeModelProvider.EchoesUserMessage or a fixed response. This behavior is lasting for the provider’s lifetime — it does not infer “which tool was already called” by scanning message history.

Creates a new fake provider.

public FakeModelProvider(string name = "fake")

name string

Provider name.

The models this provider offers.

public IReadOnlyList<ModelDescriptor> Models { get; }

IReadOnlyList<ModelDescriptor>

The provider name. ModelBinding.Provider matches this value. Comparison is case-insensitive.

public string Name { get; }

string

Requests that reached this provider; the newest is last.

public IReadOnlyList<FakeModelRequest> Requests { get; }

IReadOnlyList<FakeModelRequest>

Enqueues a tool call.

public FakeModelProvider CallsTool(string toolName, object? arguments = null)

toolName string

Name of the tool to call.

arguments object?

Call arguments. If not an IDictionary, its properties are read through reflection (works for anonymous types).

FakeModelProvider

The chain, for continued configuration.

CreateChatClient(ModelBinding, ModelProviderCredential?)

Section titled “ CreateChatClient(ModelBinding, ModelProviderCredential?)”

Produces a raw chat client for the given binding.

public IChatClient CreateChatClient(ModelBinding binding, ModelProviderCredential? credential = null)

binding ModelBinding

The model binding.

credential ModelProviderCredential?

A resolved per-tenant credential (BYOK). When null, the provider’s own setup-time credential is used and behavior is identical to a setup without per-tenant credentials. When given, the provider builds (or reuses a cached) client using ModelProviderCredential.ApiKey and, if present, ModelProviderCredential.Endpoint, instead of its setup-time credential.

IChatClient

The provider-specific client. Decorators specific to the provider (example: Anthropic’s settings decorator) may be added here.

Do not build the common pipeline here. UseFunctionInvocation, UseOpenTelemetry, the content guard, the circuit breaker, and extra resolution are added by ModelProviderRegistry.CreateChatClient. Before that shared pipeline, every provider package built the tool-call loop inside itself; the result was that no ring the registry wraps around could see the loop’s turns — a tool result entered the model uninspected.

If the loop is also built here, two nested FunctionInvokingChatClient instances form: the inner one resolves tools, the outer one never sees any call. The damage is not functional but measurable (double wrapping, a misleading span tree).

public void Dispose()

Starts echoing the LAST tool result in history once the queue is drained.

public FakeModelProvider EchoesLastToolResult(string prefix = "", int? inputTokens = null, int? outputTokens = null)

prefix string

Text prepended to the result.

inputTokens int?

If given, the input token count reported with every response.

outputTokens int?

If given, the output token count reported with every response.

FakeModelProvider

The chain, for continued configuration.

For the last step of a tool chain (set up with FakeModelProvider.CallsTool), where the final response must genuinely depend on the result the tool returned — e.g. a hand-off result to a sub-agent.

Starts echoing the last incoming user message once the queue is drained.

public FakeModelProvider EchoesUserMessage()

FakeModelProvider

The chain, for continued configuration.

ForModel(string, Action<FakeModelProvider>)

Section titled “ ForModel(string, Action<FakeModelProvider>)”

Defines a separate response queue for a specific model name. Calls to FakeModelProvider.RespondsWith/FakeModelProvider.EchoesUserMessage/FakeModelProvider.CallsTool inside the configure body affect only that model’s queue.

public FakeModelProvider ForModel(string modelId, Action<FakeModelProvider> configure)

modelId string

Model name.

configure Action<FakeModelProvider>

Configuration that fills this model’s queue.

FakeModelProvider

The chain, for continued configuration.

Enqueues responses to return in order. Once the queue is drained, a fixed response is returned unless FakeModelProvider.EchoesUserMessage was set.

public FakeModelProvider RespondsWith(params string[] responses)

responses string[]

Texts to return in order.

FakeModelProvider

The chain, for continued configuration.

Enqueues a single text response that reports a specific token usage.

public FakeModelProvider RespondsWith(string response, int inputTokens, int outputTokens)

response string

Text to return.

inputTokens int

Input token count to report.

outputTokens int

Output token count to report.

FakeModelProvider

The chain, for continued configuration.

For scenarios that test cost/usage metrics end to end.

Registers a model on this provider.

public FakeModelProvider WithModel(ModelDescriptor descriptor)

descriptor ModelDescriptor

Model descriptor.

FakeModelProvider

The chain, for continued configuration.