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
  • Decisions
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • 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
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

Chat LangChain

What can I help with?

Enter to sendĀ·Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextDecisionsBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindexautoModeMiddleware
Functionā—Since v1.6

autoModeMiddleware

Allow low-risk tool calls and block risky calls using a decision model (beta).

The middleware intercepts explicitly configured tools immediately before execution and asks a Noul question for the probability that each call is risky or insufficiently authorized. Calls below 0.5 execute normally. Calls at or above it return an error ToolMessage without invoking the tool handler. Tool names not listed in tools bypass classification.

The classifier receives the proposed tool call, the tool description, and up to 30 recent messages. Classification failures propagate and the tool handler is not called. This middleware blocks calls; it does not request human approval.

Copy
autoModeMiddleware(
  config: AutoModeMiddlewareConfig
): AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>

Parameters

NameTypeDescription
config*AutoModeMiddlewareConfig

Example

Copy
import { createAgent, autoModeMiddleware } from "langchain";

const autoMode = autoModeMiddleware({
  tools: [deleteFile],
  criteria: {
    true: "The call writes, deletes, publishes, or changes access.",
    false: "The call only reads public or user-provided data.",
  },
  classifier,
});
const agent = createAgent({
  model,
  tools: [readFile, deleteFile],
  middleware: [autoMode],
});
View source on GitHub