langchain
Version:
Typescript bindings for langchain
53 lines • 2.15 kB
TypeScript
import { AgentMiddleware } from "./types.js";
import { ClientTool } from "@langchain/core/tools";
import { BaseDecisionModel, NoulCriteria } from "@langchain/core/decisions";
export interface AutoModeMiddlewareConfig {
/**
* Tool names or tool instances to classify before execution. Unlisted tools
* are passed to the handler without classification.
*/
tools: (string | ClientTool)[];
/** Decision model used to classify tool calls. */
classifier: BaseDecisionModel;
/** Classification instructions sent to the decision model. */
instructions?: string;
/** Optional descriptions of the blocked and allowed outcomes. */
criteria?: NoulCriteria | null;
}
/**
* 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.
*
* @example
* ```ts
* 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],
* });
* ```
*
* @throws Error if `tools` is empty.
*/
export declare function autoModeMiddleware(config: AutoModeMiddlewareConfig): AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ServerTool | ClientTool)[], readonly []>;
//# sourceMappingURL=autoMode.d.ts.map