LanguageModelV3 implementation that maps user messages through a transform function — no API key, no network calls, fully deterministic.
fake(transform)
Creates a fake language model conforming to the Vercel AI SDK LanguageModelV3 specification. The returned model can be passed directly to ToolLoopAgent or any AI SDK function that accepts a LanguageModel.
Parameters
| Parameter | Type | Description |
|---|---|---|
transform | (lastMessage: string, prompt: Prompt) => string | Function that receives the last user message text and the full prompt, and returns the model output string |
transform function receives two arguments:
lastMessage— the text content of the most recent user message (empty string if none)prompt— the fullLanguageModelV3Promptconversation history, useful for tracking turn count or prior context
Return value
ALanguageModelV3 object with:
specificationVersion: "v3"provider: "aixyz/fake"modelId: "aixyz/fake"doGenerate()anddoStream()that call your transform and report zero token usage
Examples
Simple echo:Prompt
Type alias for LanguageModelV3Prompt from @ai-sdk/provider. This is an array of messages where each message has a role and content:
Testing with fake()
The fake model makes every test deterministic and CI-safe. Export the model from your agent file so tests can call doGenerate() directly: