LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Llms
  • Profile
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
UniversalHubNodeLoadSerializableEncoder BackedFile SystemIn Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindextoolEmulatorMiddleware
Functionā—Since v1.1

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.

Copy
toolEmulatorMiddleware(
  options: ToolEmulatorOptions = {}
): AgentMiddleware<StateDefinitionInit | undefined>

Used in Docs

  • Prebuilt middleware

Parameters

NameTypeDescription
optionsToolEmulatorOptions
Default:{}

Configuration options for the middleware

Example 1

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

Example 2

Copy
const middleware = toolEmulatorMiddleware({
  tools: ["get_weather", "get_user_location"]
});

Example 3

Copy
const middleware = toolEmulatorMiddleware({
  tools: ["get_weather"],
  model: "anthropic:claude-sonnet-4-5-20250929"
});

Example 4

Copy
const middleware = toolEmulatorMiddleware({
  tools: [getWeather, getUserLocation]
});
View source on GitHub