langchain.js
    Preparing search index...

    Function toolEmulatorMiddleware

    • 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.

      Parameters

      • options: ToolEmulatorOptions = {}

        Configuration options for the middleware

        Options for configuring the Tool Emulator middleware.

        • Optionalmodel?: any

          Model to use for emulation.

          • Can be a model identifier string (e.g., "anthropic:claude-sonnet-4-5-20250929")
          • Can be a BaseChatModel instance
          • Defaults to agent model
        • Optionaltools?: any[]

          List of tool names (string) or tool instances to emulate.

          • If undefined (default), ALL tools will be emulated.
          • If empty array, no tools will be emulated.
          • If array with tool names/instances, only those tools will be emulated.

      Returns AgentMiddleware<any>

      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]
      });