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.
autoModeMiddleware(
config: AutoModeMiddlewareConfig
): AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>| Name | Type | Description |
|---|---|---|
config* | AutoModeMiddlewareConfig |
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],
});