LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • 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
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainbrowserproviderToolSearchMiddleware
Functionā—Since v1.4

providerToolSearchMiddleware

Provider-side tool search middleware.

Leverages server-side tool search: the full client tool catalog is forwarded to the provider, with deferred tools marked defer_loading so the provider discloses them on demand via its own search. A tool is deferred when it is named in searchableTools or built with extras.defer_loading: true.

Requires a model with server-side tool search support: OpenAI gpt-5.4+ or Anthropic Claude Sonnet 4+/Opus 4+/Haiku 4.5+. Non-Anthropic/OpenAI providers throw; an in-family model that is too old surfaces the provider's own API error rather than being gated here.

Copy
providerToolSearchMiddleware(
  config: ProviderToolSearchMiddlewareConfig = {}
): AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>

Parameters

NameTypeDescription
configProviderToolSearchMiddlewareConfig
Default:{}

Configuration options for the middleware

Example 1

Copy
import { createAgent, providerToolSearchMiddleware } from "langchain";
import { ChatAnthropic } from "@langchain/anthropic";

const agent = createAgent({
  model: new ChatAnthropic({ model: "claude-sonnet-4-5" }),
  tools: [getWeather, ...nicheTools],
  middleware: [
    // Defer the niche tools behind the provider's tool search; the model
    // discovers them on demand instead of receiving every schema up front.
    providerToolSearchMiddleware({ searchableTools: nicheTools }),
  ],
});

Example 2

Copy
import { tool } from "@langchain/core/tools";
import { createAgent, providerToolSearchMiddleware } from "langchain";
import { ChatAnthropic } from "@langchain/anthropic";

// A tool marked `defer_loading` at construction is deferred on its own —
// no need to list it in `searchableTools`; the middleware honors the flag.
const sendEmail = tool(sendEmailFn, {
  name: "send_email",
  description: "Send an email",
  schema: sendEmailSchema,
  extras: { defer_loading: true },
});

const agent = createAgent({
  model: new ChatAnthropic({ model: "claude-sonnet-4-5" }),
  tools: [getWeather, sendEmail],
  middleware: [providerToolSearchMiddleware()],
});
View source on GitHub