The name of the middleware instance.
Logic to run before the agent execution starts.
Async logic to run before the agent execution starts.
Logic to run before the model is called.
Async logic to run before the model is called.
Logic to run after the model is called.
Async logic to run after the model is called.
Intercept and control model execution via handler callback.
Intercept and control async model execution via handler callback.
Logic to run after the agent execution completes.
Async logic to run after the agent execution completes.
| Name | Type | Description |
|---|---|---|
tools* | Sequence[str | BaseTool] | Tool names or |
instructions | str | Default: _DEFAULT_INSTRUCTIONSClassification instructions sent to the decision model. |
criteria | NoulCriteria | None | Default: None |
classifier* | BaseDecisionModel |
| Name | Type |
|---|---|
| tools | Sequence[str | BaseTool] |
| instructions | str |
| criteria | NoulCriteria | None |
| classifier | BaseDecisionModel |
Allow low-risk tool calls and block risky calls using a decision model.
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.
This middleware is in beta. Its API may change without notice.
from langchain.agents import create_agent
from langchain.agents.middleware import AutoModeMiddleware
from langchain_core.decisions import NoulCriteria
auto_mode = AutoModeMiddleware(
tools=[delete_file],
criteria=NoulCriteria(
true="The call writes, deletes, publishes, or changes access.",
false="The call only reads public or user-provided data.",
),
classifier=classifier,
)
agent = create_agent(
model,
tools=[read_file, delete_file],
middleware=[auto_mode],
)Optional descriptions of the blocked and allowed outcomes.
Decision model used to classify tool calls.