Middleware that emulates specified tools using an LLM instead of executing them.
This middleware allows selective emulation of tools for testing purposes.
By default (when tools is undefined), all tools are emulated. You can specify
which tools to emulate by passing a list of tool names or tool instances.
toolEmulatorMiddleware(
options: ToolEmulatorOptions = {}
): AgentMiddleware<StateDefinitionInit | undefined>| Name | Type | Description |
|---|---|---|
options | ToolEmulatorOptions | Default: {}Configuration options for the middleware |
import { toolEmulatorMiddleware } from "@langchain/langchain/agents/middleware";
import { createAgent } from "@langchain/langchain/agents";
const middleware = toolEmulatorMiddleware();
const agent = createAgent({
model: "openai:gpt-4o",
tools: [getWeather, getUserLocation, calculator],
middleware: [middleware],
});const middleware = toolEmulatorMiddleware({
tools: ["get_weather", "get_user_location"]
});const middleware = toolEmulatorMiddleware({
tools: ["get_weather"],
model: "anthropic:claude-sonnet-4-5-20250929"
});const middleware = toolEmulatorMiddleware({
tools: [getWeather, getUserLocation]
});