Creates a new FakeBuiltModel for testing.
Returns a chainable builder — queue responses, then pass the model
anywhere a chat model is expected. Responses are consumed in FIFO
order, one per invoke() call.
| Method | Description |
|---|---|
fakeModel() |
Creates a new fake chat model. Returns a chainable builder. |
.respond(message) |
Queue an AIMessage (or any BaseMessage) to return on the next invocation. |
.respond(error) |
Queue an Error to throw on the next invocation. |
.respond(factory) |
Queue a function (messages) => BaseMessage \| Error for dynamic responses. |
.respondWithTools(toolCalls) |
Shorthand for .respond() with tool calls. Each entry needs name and args; id is optional. |
.alwaysThrow(error) |
Make every invocation throw this error, regardless of the queue. |
.structuredResponse(value) |
Set the value returned by .withStructuredOutput(). |
.bindTools(tools) |
Bind tools to the model. Returns a RunnableBinding that shares the response queue and call recording. |
.withStructuredOutput(schema) |
Returns a runnable that produces the .structuredResponse() value. |
.calls |
Array of { messages, options } for every invocation (read-only). |
.callCount |
Number of times the model has been invoked. |
fakeModel(): FakeBuiltModelconst model = fakeModel()
.respondWithTools([{ name: "search", args: { query: "weather" } }])
.respond(new AIMessage("Sunny and warm."));
const r1 = await model.invoke([new HumanMessage("What's the weather?")]);
// r1.tool_calls[0].name === "search"
const r2 = await model.invoke([new HumanMessage("Thanks")]);
// r2.content === "Sunny and warm."