Skip to content

TestModel

Deterministic mock model for testing. Implements LanguageModelV3.

Three modes:

  1. No config: Auto-calls all available tools on first call, returns defaultText on second.
  2. responses[]: Returns pre-configured responses in order. Throws when exhausted.
  3. defaultText: Always returns the specified text (no tool calls).

Zero cost, zero latency, no network calls.

const agent = new Agent({
name: "test",
model: new TestModel({ defaultText: "Hello!" }),
instructions: "test",
defaults: false,
})
const { text } = await agent.run("Hi").result // "Hello!"
  • LanguageModelV3

new TestModel(opts?): TestModel

TestModelOptions

TestModel

readonly modelId: "test-model" = "test-model"

Provider-specific model ID.

LanguageModelV3.modelId


readonly provider: "test" = "test"

Provider ID.

LanguageModelV3.provider


readonly specificationVersion: "v3"

The language model must specify which language model interface version it implements.

LanguageModelV3.specificationVersion


readonly supportedUrls: object = {}

Supported URL patterns by media type for the provider.

The keys are media type patterns or full media types (e.g. */* for everything, audio/*, video/*, or application/pdf). and the values are arrays of regular expressions that match the URL paths.

The matching should be against lower-case URLs.

Matched URLs are supported natively by the model and are not downloaded.

A map of supported URL patterns by media type (as a promise or a plain object).

LanguageModelV3.supportedUrls

doGenerate(options): Promise<LanguageModelV3GenerateResult>

Generates a language model output (non-streaming).

Naming: “do” prefix to prevent accidental direct usage of the method by the user.

LanguageModelV3CallOptions

Promise<LanguageModelV3GenerateResult>

LanguageModelV3.doGenerate


doStream(): Promise<never>

Generates a language model output (streaming).

Naming: “do” prefix to prevent accidental direct usage of the method by the user.

Promise<never>

A stream of higher-level language model output parts.

LanguageModelV3.doStream


reset(): void

Reset call index for reuse across tests.

void