langchain 1.4.4 → 1.4.5-dev-1781048185730
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/middleware/hitl.cjs +29 -3
- package/dist/agents/middleware/hitl.cjs.map +1 -1
- package/dist/agents/middleware/hitl.d.cts +105 -2
- package/dist/agents/middleware/hitl.d.cts.map +1 -1
- package/dist/agents/middleware/hitl.d.ts +105 -2
- package/dist/agents/middleware/hitl.d.ts.map +1 -1
- package/dist/agents/middleware/hitl.js +29 -3
- package/dist/agents/middleware/hitl.js.map +1 -1
- package/dist/agents/middleware/index.d.cts +1 -1
- package/dist/agents/middleware/index.d.ts +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +10 -10
- package/chat_models/universal.cjs +0 -1
- package/chat_models/universal.d.cts +0 -1
- package/chat_models/universal.d.ts +0 -1
- package/chat_models/universal.js +0 -1
- package/hub/node.cjs +0 -1
- package/hub/node.d.cts +0 -1
- package/hub/node.d.ts +0 -1
- package/hub/node.js +0 -1
- package/hub.cjs +0 -1
- package/hub.d.cts +0 -1
- package/hub.d.ts +0 -1
- package/hub.js +0 -1
- package/load/serializable.cjs +0 -1
- package/load/serializable.d.cts +0 -1
- package/load/serializable.d.ts +0 -1
- package/load/serializable.js +0 -1
- package/load.cjs +0 -1
- package/load.d.cts +0 -1
- package/load.d.ts +0 -1
- package/load.js +0 -1
- package/storage/encoder_backed.cjs +0 -1
- package/storage/encoder_backed.d.cts +0 -1
- package/storage/encoder_backed.d.ts +0 -1
- package/storage/encoder_backed.js +0 -1
- package/storage/file_system.cjs +0 -1
- package/storage/file_system.d.cts +0 -1
- package/storage/file_system.d.ts +0 -1
- package/storage/file_system.js +0 -1
- package/storage/in_memory.cjs +0 -1
- package/storage/in_memory.d.cts +0 -1
- package/storage/in_memory.d.ts +0 -1
- package/storage/in_memory.js +0 -1
|
@@ -5,6 +5,7 @@ let _langchain_langgraph = require("@langchain/langgraph");
|
|
|
5
5
|
let _langchain_core_utils_types = require("@langchain/core/utils/types");
|
|
6
6
|
let zod_v3 = require("zod/v3");
|
|
7
7
|
//#region src/agents/middleware/hitl.ts
|
|
8
|
+
const WhenFunctionSchema = zod_v3.z.function().args(zod_v3.z.custom()).returns(zod_v3.z.union([zod_v3.z.boolean(), zod_v3.z.promise(zod_v3.z.boolean())]));
|
|
8
9
|
const DescriptionFunctionSchema = zod_v3.z.function().args(zod_v3.z.custom(), zod_v3.z.custom(), zod_v3.z.custom()).returns(zod_v3.z.union([zod_v3.z.string(), zod_v3.z.promise(zod_v3.z.string())]));
|
|
9
10
|
/**
|
|
10
11
|
* The type of decision a human can make.
|
|
@@ -18,7 +19,8 @@ const DecisionType = zod_v3.z.enum(ALLOWED_DECISIONS);
|
|
|
18
19
|
const InterruptOnConfigSchema = zod_v3.z.object({
|
|
19
20
|
allowedDecisions: zod_v3.z.array(DecisionType),
|
|
20
21
|
description: zod_v3.z.union([zod_v3.z.string(), DescriptionFunctionSchema]).optional(),
|
|
21
|
-
argsSchema: zod_v3.z.record(zod_v3.z.any()).optional()
|
|
22
|
+
argsSchema: zod_v3.z.record(zod_v3.z.any()).optional(),
|
|
23
|
+
when: WhenFunctionSchema.optional()
|
|
22
24
|
});
|
|
23
25
|
const contextSchema = zod_v3.z.object({
|
|
24
26
|
interruptOn: zod_v3.z.record(zod_v3.z.union([zod_v3.z.boolean(), InterruptOnConfigSchema])).optional(),
|
|
@@ -83,6 +85,7 @@ const contextSchema = zod_v3.z.object({
|
|
|
83
85
|
* @param options.interruptOn[toolName].allowedDecisions - Array of decision types allowed for this tool (e.g., ["approve", "edit", "reject"])
|
|
84
86
|
* @param options.interruptOn[toolName].description - Custom approval message for the tool. Can be either a static string or a callable that dynamically generates the description based on agent state, runtime, and tool call information
|
|
85
87
|
* @param options.interruptOn[toolName].argsSchema - JSON schema for the arguments associated with the action, if edits are allowed
|
|
88
|
+
* @param options.interruptOn[toolName].when - Optional predicate that dynamically controls whether a tool call triggers an interrupt. Returns `true` to interrupt or `false` to auto-approve the tool call.
|
|
86
89
|
* @param options.descriptionPrefix - Default prefix for approval messages (default: "Tool execution requires approval"). Only used for tools that do not define a custom `description` in their InterruptOnConfig.
|
|
87
90
|
*
|
|
88
91
|
* @returns A middleware instance that can be passed to `createAgent`
|
|
@@ -263,6 +266,21 @@ function humanInTheLoopMiddleware(options) {
|
|
|
263
266
|
reviewConfig
|
|
264
267
|
};
|
|
265
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* Return `false` if the `when` predicate rejects this tool call, `true` otherwise.
|
|
271
|
+
*
|
|
272
|
+
* When no `when` predicate is configured the tool call always interrupts.
|
|
273
|
+
*/
|
|
274
|
+
const shouldInterrupt = async (toolCall, config, state, runtime) => {
|
|
275
|
+
const { when } = config;
|
|
276
|
+
if (when == null) return true;
|
|
277
|
+
return when({
|
|
278
|
+
toolCall,
|
|
279
|
+
tool: void 0,
|
|
280
|
+
state,
|
|
281
|
+
runtime
|
|
282
|
+
});
|
|
283
|
+
};
|
|
266
284
|
const processDecision = (decision, toolCall, config) => {
|
|
267
285
|
const allowedDecisions = config.allowedDecisions;
|
|
268
286
|
if (decision.type === "approve" && allowedDecisions.includes("approve")) return {
|
|
@@ -335,8 +353,16 @@ function humanInTheLoopMiddleware(options) {
|
|
|
335
353
|
} else if (toolConfig.allowedDecisions) resolvedConfigs[toolName] = toolConfig;
|
|
336
354
|
const interruptToolCalls = [];
|
|
337
355
|
const autoApprovedToolCalls = [];
|
|
338
|
-
for (const toolCall of lastMessage.tool_calls)
|
|
339
|
-
|
|
356
|
+
for (const toolCall of lastMessage.tool_calls) {
|
|
357
|
+
const interruptConfig = resolvedConfigs[toolCall.name];
|
|
358
|
+
/**
|
|
359
|
+
* A tool call is interrupted only when it has a resolved config and its
|
|
360
|
+
* optional `when` predicate doesn't opt it out. Otherwise it is
|
|
361
|
+
* auto-approved.
|
|
362
|
+
*/
|
|
363
|
+
if (interruptConfig && await shouldInterrupt(toolCall, interruptConfig, state, runtime)) interruptToolCalls.push(toolCall);
|
|
364
|
+
else autoApprovedToolCalls.push(toolCall);
|
|
365
|
+
}
|
|
340
366
|
/**
|
|
341
367
|
* No interrupt tool calls, so we can just return.
|
|
342
368
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl.cjs","names":["z","ToolMessage","createMiddleware","AIMessage"],"sources":["../../../src/agents/middleware/hitl.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v3\";\nimport { AIMessage, ToolMessage, ToolCall } from \"@langchain/core/messages\";\nimport {\n InferInteropZodInput,\n interopParse,\n} from \"@langchain/core/utils/types\";\nimport { interrupt } from \"@langchain/langgraph\";\n\nimport { createMiddleware } from \"../middleware.js\";\nimport type { AgentBuiltInState, Runtime } from \"../runtime.js\";\nimport type { JumpToTarget } from \"../constants.js\";\n\nconst DescriptionFunctionSchema = z\n .function()\n .args(\n z.custom<ToolCall>(), // toolCall\n z.custom<AgentBuiltInState>(), // state\n z.custom<Runtime<unknown>>() // runtime\n )\n .returns(z.union([z.string(), z.promise(z.string())]));\n\n/**\n * Function type that dynamically generates a description for a tool call approval request.\n *\n * @param toolCall - The tool call being reviewed\n * @param state - The current agent state\n * @param runtime - The agent runtime context\n * @returns A string description or Promise that resolves to a string description\n *\n * @example\n * ```typescript\n * import { type DescriptionFactory, type ToolCall } from \"langchain\";\n *\n * const descriptionFactory: DescriptionFactory = (toolCall, state, runtime) => {\n * return `Please review: ${toolCall.name}(${JSON.stringify(toolCall.args)})`;\n * };\n * ```\n */\nexport type DescriptionFactory = z.infer<typeof DescriptionFunctionSchema>;\n\n/**\n * The type of decision a human can make.\n */\nconst ALLOWED_DECISIONS = [\"approve\", \"edit\", \"reject\"] as const;\nconst DecisionType = z.enum(ALLOWED_DECISIONS);\nexport type DecisionType = z.infer<typeof DecisionType>;\n\nconst InterruptOnConfigSchema = z.object({\n /**\n * The decisions that are allowed for this action.\n */\n allowedDecisions: z.array(DecisionType),\n /**\n * The description attached to the request for human input.\n * Can be either:\n * - A static string describing the approval request\n * - A callable that dynamically generates the description based on agent state,\n * runtime, and tool call information\n *\n * @example\n * Static string description\n * ```typescript\n * import type { InterruptOnConfig } from \"langchain\";\n *\n * const config: InterruptOnConfig = {\n * allowedDecisions: [\"approve\", \"reject\"],\n * description: \"Please review this tool execution\"\n * };\n * ```\n *\n * @example\n * Dynamic callable description\n * ```typescript\n * import type {\n * AgentBuiltInState,\n * Runtime,\n * DescriptionFactory,\n * ToolCall,\n * InterruptOnConfig\n * } from \"langchain\";\n *\n * const formatToolDescription: DescriptionFactory = (\n * toolCall: ToolCall,\n * state: AgentBuiltInState,\n * runtime: Runtime<unknown>\n * ) => {\n * return `Tool: ${toolCall.name}\\nArguments:\\n${JSON.stringify(toolCall.args, null, 2)}`;\n * };\n *\n * const config: InterruptOnConfig = {\n * allowedDecisions: [\"approve\", \"edit\"],\n * description: formatToolDescription\n * };\n * ```\n */\n description: z.union([z.string(), DescriptionFunctionSchema]).optional(),\n /**\n * JSON schema for the arguments associated with the action, if edits are allowed.\n */\n argsSchema: z.record(z.any()).optional(),\n});\nexport type InterruptOnConfig = z.input<typeof InterruptOnConfigSchema>;\n\n/**\n * Represents an action with a name and arguments.\n */\nexport interface Action {\n /**\n * The type or name of action being requested (e.g., \"add_numbers\").\n */\n name: string;\n /**\n * Key-value pairs of arguments needed for the action (e.g., {\"a\": 1, \"b\": 2}).\n */\n args: Record<string, any>;\n}\n\n/**\n * Represents an action request with a name, arguments, and description.\n */\nexport interface ActionRequest {\n /**\n * The name of the action being requested.\n */\n name: string;\n /**\n * Key-value pairs of arguments needed for the action (e.g., {\"a\": 1, \"b\": 2}).\n */\n args: Record<string, any>;\n /**\n * The description of the action to be reviewed.\n */\n description?: string;\n}\n\n/**\n * Policy for reviewing a HITL request.\n */\nexport interface ReviewConfig {\n /**\n * Name of the action associated with this review configuration.\n */\n actionName: string;\n /**\n * The decisions that are allowed for this request.\n */\n allowedDecisions: DecisionType[];\n /**\n * JSON schema for the arguments associated with the action, if edits are allowed.\n */\n argsSchema?: Record<string, any>;\n}\n\n/**\n * Request for human feedback on a sequence of actions requested by a model.\n *\n * @example\n * ```ts\n * const hitlRequest: HITLRequest = {\n * actionRequests: [\n * { name: \"send_email\", args: { to: \"user@example.com\", subject: \"Hello\" } }\n * ],\n * reviewConfigs: [\n * {\n * actionName: \"send_email\",\n * allowedDecisions: [\"approve\", \"edit\", \"reject\"],\n * description: \"Please review the email before sending\"\n * }\n * ]\n * };\n * const response = interrupt(hitlRequest);\n * ```\n */\nexport interface HITLRequest {\n /**\n * A list of agent actions for human review.\n */\n actionRequests: ActionRequest[];\n /**\n * Review configuration for all possible actions.\n */\n reviewConfigs: ReviewConfig[];\n}\n\n/**\n * Response when a human approves the action.\n */\nexport interface ApproveDecision {\n type: \"approve\";\n}\n\n/**\n * Response when a human edits the action.\n */\nexport interface EditDecision {\n type: \"edit\";\n /**\n * Edited action for the agent to perform.\n * Ex: for a tool call, a human reviewer can edit the tool name and args.\n */\n editedAction: Action;\n}\n\n/**\n * Response when a human rejects the action.\n */\nexport interface RejectDecision {\n type: \"reject\";\n /**\n * The message sent to the model explaining why the action was rejected.\n */\n message?: string;\n}\n\n/**\n * Union of all possible decision types.\n */\nexport type Decision = ApproveDecision | EditDecision | RejectDecision;\n\n/**\n * Response payload for a HITLRequest.\n */\nexport interface HITLResponse {\n /**\n * The decisions made by the human.\n */\n decisions: Decision[];\n}\n\nconst contextSchema = z.object({\n /**\n * Mapping of tool name to allowed reviewer responses.\n * If a tool doesn't have an entry, it's auto-approved by default.\n *\n * - `true` -> pause for approval and allow approve/edit/reject decisions\n * - `false` -> auto-approve (no human review)\n * - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool\n */\n interruptOn: z\n .record(z.union([z.boolean(), InterruptOnConfigSchema]))\n .optional(),\n /**\n * Prefix used when constructing human-facing approval messages.\n * Provides context about the tool call being reviewed; does not change the underlying action.\n *\n * Note: This prefix is only applied for tools that do not provide a custom\n * `description` via their {@link InterruptOnConfig}. If a tool specifies a custom\n * `description`, that per-tool text is used and this prefix is ignored.\n */\n descriptionPrefix: z.string().default(\"Tool execution requires approval\"),\n});\nexport type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<\n typeof contextSchema\n>;\n\n/**\n * Creates a Human-in-the-Loop (HITL) middleware for tool approval and oversight.\n *\n * This middleware intercepts tool calls made by an AI agent and provides human oversight\n * capabilities before execution. It enables selective approval workflows where certain tools\n * require human intervention while others can execute automatically.\n *\n * A invocation result that has been interrupted by the middleware will have a `__interrupt__`\n * property that contains the interrupt request.\n *\n * ```ts\n * import { type HITLRequest, type HITLResponse } from \"langchain\";\n * import { type Interrupt } from \"langchain\";\n *\n * const result = await agent.invoke(request);\n * const interruptRequest = result.__interrupt__?.[0] as Interrupt<HITLRequest>;\n *\n * // Examine the action requests and review configs\n * const actionRequests = interruptRequest.value.actionRequests;\n * const reviewConfigs = interruptRequest.value.reviewConfigs;\n *\n * // Create decisions for each action\n * const resume: HITLResponse = {\n * decisions: actionRequests.map((action, i) => {\n * if (action.name === \"calculator\") {\n * return { type: \"approve\" };\n * } else if (action.name === \"write_file\") {\n * return {\n * type: \"edit\",\n * editedAction: { name: \"write_file\", args: { filename: \"safe.txt\", content: \"Safe content\" } }\n * };\n * }\n * return { type: \"reject\", message: \"Action not allowed\" };\n * })\n * };\n *\n * // Resume with decisions\n * await agent.invoke(new Command({ resume }), config);\n * ```\n *\n * ## Features\n *\n * - **Selective Tool Approval**: Configure which tools require human approval\n * - **Multiple Decision Types**: Approve, edit, or reject tool calls\n * - **Asynchronous Workflow**: Uses LangGraph's interrupt mechanism for non-blocking approval\n * - **Custom Approval Messages**: Provide context-specific descriptions for approval requests\n *\n * ## Decision Types\n *\n * When a tool requires approval, the human operator can respond with:\n * - `approve`: Execute the tool with original arguments\n * - `edit`: Modify the tool name and/or arguments before execution\n * - `reject`: Provide a manual response instead of executing the tool\n *\n * @param options - Configuration options for the middleware\n * @param options.interruptOn - Per-tool configuration mapping tool names to their settings\n * @param options.interruptOn[toolName].allowedDecisions - Array of decision types allowed for this tool (e.g., [\"approve\", \"edit\", \"reject\"])\n * @param options.interruptOn[toolName].description - Custom approval message for the tool. Can be either a static string or a callable that dynamically generates the description based on agent state, runtime, and tool call information\n * @param options.interruptOn[toolName].argsSchema - JSON schema for the arguments associated with the action, if edits are allowed\n * @param options.descriptionPrefix - Default prefix for approval messages (default: \"Tool execution requires approval\"). Only used for tools that do not define a custom `description` in their InterruptOnConfig.\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @example\n * Basic usage with selective tool approval\n * ```typescript\n * import { humanInTheLoopMiddleware } from \"langchain\";\n * import { createAgent } from \"langchain\";\n *\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * // Interrupt write_file tool and allow edits or approvals\n * \"write_file\": {\n * allowedDecisions: [\"approve\", \"edit\"],\n * description: \"⚠️ File write operation requires approval\"\n * },\n * // Auto-approve read_file tool\n * \"read_file\": false\n * }\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4\",\n * tools: [writeFileTool, readFileTool],\n * middleware: [hitlMiddleware]\n * });\n * ```\n *\n * @example\n * Handling approval requests\n * ```typescript\n * import { type HITLRequest, type HITLResponse, type Interrupt } from \"langchain\";\n * import { Command } from \"@langchain/langgraph\";\n *\n * // Initial agent invocation\n * const result = await agent.invoke({\n * messages: [new HumanMessage(\"Write 'Hello' to output.txt\")]\n * }, config);\n *\n * // Check if agent is paused for approval\n * if (result.__interrupt__) {\n * const interruptRequest = result.__interrupt__?.[0] as Interrupt<HITLRequest>;\n *\n * // Show tool call details to user\n * console.log(\"Actions:\", interruptRequest.value.actionRequests);\n * console.log(\"Review configs:\", interruptRequest.value.reviewConfigs);\n *\n * // Resume with approval\n * const resume: HITLResponse = {\n * decisions: [{ type: \"approve\" }]\n * };\n * await agent.invoke(\n * new Command({ resume }),\n * config\n * );\n * }\n * ```\n *\n * @example\n * Different decision types\n * ```typescript\n * import { type HITLResponse } from \"langchain\";\n *\n * // Approve the tool call as-is\n * const resume: HITLResponse = {\n * decisions: [{ type: \"approve\" }]\n * };\n *\n * // Edit the tool arguments\n * const resume: HITLResponse = {\n * decisions: [{\n * type: \"edit\",\n * editedAction: { name: \"write_file\", args: { filename: \"safe.txt\", content: \"Modified\" } }\n * }]\n * };\n *\n * // Reject with feedback\n * const resume: HITLResponse = {\n * decisions: [{\n * type: \"reject\",\n * message: \"File operation not allowed in demo mode\"\n * }]\n * };\n * ```\n *\n * @example\n * Production use case with database operations\n * ```typescript\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * \"execute_sql\": {\n * allowedDecisions: [\"approve\", \"edit\", \"reject\"],\n * description: \"🚨 SQL query requires DBA approval\\nPlease review for safety and performance\"\n * },\n * \"read_schema\": false, // Reading metadata is safe\n * \"delete_records\": {\n * allowedDecisions: [\"approve\", \"reject\"],\n * description: \"⛔ DESTRUCTIVE OPERATION - Requires manager approval\"\n * }\n * },\n * descriptionPrefix: \"Database operation pending approval\"\n * });\n * ```\n *\n * @example\n * Using dynamic callable descriptions\n * ```typescript\n * import { type DescriptionFactory, type ToolCall } from \"langchain\";\n * import type { AgentBuiltInState, Runtime } from \"langchain/agents\";\n *\n * // Define a dynamic description factory\n * const formatToolDescription: DescriptionFactory = (\n * toolCall: ToolCall,\n * state: AgentBuiltInState,\n * runtime: Runtime<unknown>\n * ) => {\n * return `Tool: ${toolCall.name}\\nArguments:\\n${JSON.stringify(toolCall.args, null, 2)}`;\n * };\n *\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * \"write_file\": {\n * allowedDecisions: [\"approve\", \"edit\"],\n * // Use dynamic description that can access tool call, state, and runtime\n * description: formatToolDescription\n * },\n * // Or use an inline function\n * \"send_email\": {\n * allowedDecisions: [\"approve\", \"reject\"],\n * description: (toolCall, state, runtime) => {\n * const { to, subject } = toolCall.args;\n * return `Email to ${to}\\nSubject: ${subject}\\n\\nRequires approval before sending`;\n * }\n * }\n * }\n * });\n * ```\n *\n * @remarks\n * - Tool calls are processed in the order they appear in the AI message\n * - Auto-approved tools execute immediately without interruption\n * - Multiple tools requiring approval are bundled into a single interrupt request\n * - The middleware operates in the `afterModel` phase, intercepting before tool execution\n * - Requires a checkpointer to maintain state across interruptions\n *\n * @see {@link createAgent} for agent creation\n * @see {@link Command} for resuming interrupted execution\n * @public\n */\nexport function humanInTheLoopMiddleware(\n options: NonNullable<HumanInTheLoopMiddlewareConfig>\n) {\n const createActionAndConfig = async (\n toolCall: ToolCall,\n config: InterruptOnConfig,\n state: AgentBuiltInState,\n runtime: Runtime<unknown>\n ): Promise<{\n actionRequest: ActionRequest;\n reviewConfig: ReviewConfig;\n }> => {\n const toolName = toolCall.name;\n const toolArgs = toolCall.args;\n\n // Generate description using the description field (str or callable)\n const descriptionValue = config.description;\n let description: string;\n if (typeof descriptionValue === \"function\") {\n description = await descriptionValue(toolCall, state, runtime);\n } else if (descriptionValue !== undefined) {\n description = descriptionValue;\n } else {\n description = `${\n options.descriptionPrefix ?? \"Tool execution requires approval\"\n }\\n\\nTool: ${toolName}\\nArgs: ${JSON.stringify(toolArgs, null, 2)}`;\n }\n\n /**\n * Create ActionRequest with description\n */\n const actionRequest: ActionRequest = {\n name: toolName,\n args: toolArgs,\n description,\n };\n\n /**\n * Create ReviewConfig\n */\n const reviewConfig: ReviewConfig = {\n actionName: toolName,\n allowedDecisions: config.allowedDecisions,\n };\n\n if (config.argsSchema) {\n reviewConfig.argsSchema = config.argsSchema;\n }\n\n return { actionRequest, reviewConfig };\n };\n\n const processDecision = (\n decision: Decision,\n toolCall: ToolCall,\n config: InterruptOnConfig\n ): { revisedToolCall: ToolCall | null; toolMessage: ToolMessage | null } => {\n const allowedDecisions = config.allowedDecisions;\n if (decision.type === \"approve\" && allowedDecisions.includes(\"approve\")) {\n return { revisedToolCall: toolCall, toolMessage: null };\n }\n\n if (decision.type === \"edit\" && allowedDecisions.includes(\"edit\")) {\n const editedAction = decision.editedAction;\n\n /**\n * Validate edited action structure\n */\n if (!editedAction || typeof editedAction.name !== \"string\") {\n throw new Error(\n `Invalid edited action for tool \"${toolCall.name}\": name must be a string`\n );\n }\n if (!editedAction.args || typeof editedAction.args !== \"object\") {\n throw new Error(\n `Invalid edited action for tool \"${toolCall.name}\": args must be an object`\n );\n }\n\n return {\n revisedToolCall: {\n type: \"tool_call\",\n name: editedAction.name,\n args: editedAction.args,\n id: toolCall.id,\n },\n toolMessage: null,\n };\n }\n\n if (decision.type === \"reject\" && allowedDecisions.includes(\"reject\")) {\n /**\n * Validate that message is a string if provided\n */\n if (\n decision.message !== undefined &&\n typeof decision.message !== \"string\"\n ) {\n throw new Error(\n `Tool call response for \"${\n toolCall.name\n }\" must be a string, got ${typeof decision.message}`\n );\n }\n\n // Create a tool message with the human's text response\n const content =\n decision.message ??\n `User rejected the tool call for \\`${toolCall.name}\\` with id ${toolCall.id}`;\n\n const toolMessage = new ToolMessage({\n content,\n name: toolCall.name,\n tool_call_id: toolCall.id!,\n status: \"error\",\n });\n\n return { revisedToolCall: toolCall, toolMessage };\n }\n\n const msg = `Unexpected human decision: ${JSON.stringify(\n decision\n )}. Decision type '${decision.type}' is not allowed for tool '${\n toolCall.name\n }'. Expected one of ${JSON.stringify(\n allowedDecisions\n )} based on the tool's configuration.`;\n throw new Error(msg);\n };\n\n return createMiddleware({\n name: \"HumanInTheLoopMiddleware\",\n contextSchema,\n afterModel: {\n canJumpTo: [\"model\"],\n hook: async (state, runtime) => {\n const config = interopParse(contextSchema, {\n ...options,\n ...(runtime.context || {}),\n });\n if (!config) {\n return;\n }\n\n const { messages } = state;\n if (!messages.length) {\n return;\n }\n\n /**\n * Don't do anything if the last message isn't an AI message with tool calls.\n */\n const lastMessage = [...messages]\n .reverse()\n .find((msg) => AIMessage.isInstance(msg)) as AIMessage;\n if (!lastMessage || !lastMessage.tool_calls?.length) {\n return;\n }\n\n /**\n * If the user omits the interruptOn config, we don't do anything.\n */\n if (!config.interruptOn) {\n return;\n }\n\n /**\n * Resolve per-tool configs (boolean true -> all decisions allowed; false -> auto-approve)\n */\n const resolvedConfigs: Record<string, InterruptOnConfig> = {};\n for (const [toolName, toolConfig] of Object.entries(\n config.interruptOn\n )) {\n if (typeof toolConfig === \"boolean\") {\n if (toolConfig === true) {\n resolvedConfigs[toolName] = {\n allowedDecisions: [...ALLOWED_DECISIONS],\n };\n }\n } else if (toolConfig.allowedDecisions) {\n resolvedConfigs[toolName] = toolConfig as InterruptOnConfig;\n }\n }\n\n const interruptToolCalls: ToolCall[] = [];\n const autoApprovedToolCalls: ToolCall[] = [];\n\n for (const toolCall of lastMessage.tool_calls) {\n if (toolCall.name in resolvedConfigs) {\n interruptToolCalls.push(toolCall);\n } else {\n autoApprovedToolCalls.push(toolCall);\n }\n }\n\n /**\n * No interrupt tool calls, so we can just return.\n */\n if (!interruptToolCalls.length) {\n return;\n }\n\n /**\n * Create action requests and review configs for all tools that need approval\n */\n const actionRequests: ActionRequest[] = [];\n const reviewConfigs: ReviewConfig[] = [];\n\n for (const toolCall of interruptToolCalls) {\n const interruptConfig = resolvedConfigs[toolCall.name]!;\n\n /**\n * Create ActionRequest and ReviewConfig using helper method\n */\n const { actionRequest, reviewConfig } = await createActionAndConfig(\n toolCall,\n interruptConfig,\n state,\n runtime\n );\n actionRequests.push(actionRequest);\n reviewConfigs.push(reviewConfig);\n }\n\n /**\n * Create single HITLRequest with all actions and configs\n */\n const hitlRequest: HITLRequest = {\n actionRequests,\n reviewConfigs,\n };\n\n /**\n * Send interrupt and get response\n */\n const hitlResponse = (await interrupt(hitlRequest)) as HITLResponse;\n const decisions = hitlResponse.decisions;\n\n /**\n * Validate that decisions is a valid array before checking length\n */\n if (!decisions || !Array.isArray(decisions)) {\n throw new Error(\n \"Invalid HITLResponse: decisions must be a non-empty array\"\n );\n }\n\n /**\n * Validate that the number of decisions matches the number of interrupt tool calls\n */\n if (decisions.length !== interruptToolCalls.length) {\n throw new Error(\n `Number of human decisions (${decisions.length}) does not match number of hanging tool calls (${interruptToolCalls.length}).`\n );\n }\n\n const revisedToolCalls: ToolCall[] = [...autoApprovedToolCalls];\n const artificialToolMessages: ToolMessage[] = [];\n const hasRejectedToolCalls = decisions.some(\n (decision) => decision.type === \"reject\"\n );\n\n /**\n * Process each decision using helper method\n */\n for (let i = 0; i < decisions.length; i++) {\n const decision = decisions[i]!;\n const toolCall = interruptToolCalls[i]!;\n const interruptConfig = resolvedConfigs[toolCall.name]!;\n\n const { revisedToolCall, toolMessage } = processDecision(\n decision,\n toolCall,\n interruptConfig\n );\n\n if (\n revisedToolCall &&\n /**\n * If any decision is a rejected, we are going back to the model\n * with only the tool calls that were rejected as we don't know\n * the results of the approved/updated tool calls at this point.\n */\n (!hasRejectedToolCalls || decision.type === \"reject\")\n ) {\n revisedToolCalls.push(revisedToolCall);\n }\n if (toolMessage) {\n artificialToolMessages.push(toolMessage);\n }\n }\n\n /**\n * Update the AI message to only include approved tool calls\n */\n if (AIMessage.isInstance(lastMessage)) {\n lastMessage.tool_calls = revisedToolCalls;\n }\n\n const jumpTo: JumpToTarget | undefined = hasRejectedToolCalls\n ? \"model\"\n : undefined;\n return {\n messages: [lastMessage, ...artificialToolMessages],\n jumpTo,\n };\n },\n },\n });\n}\n"],"mappings":";;;;;;;AAaA,MAAM,4BAA4BA,OAAAA,EAC/B,UAAU,CACV,KACCA,OAAAA,EAAE,QAAkB,EACpBA,OAAAA,EAAE,QAA2B,EAC7BA,OAAAA,EAAE,QAA0B,CAC7B,CACA,QAAQA,OAAAA,EAAE,MAAM,CAACA,OAAAA,EAAE,QAAQ,EAAEA,OAAAA,EAAE,QAAQA,OAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;;;;AAwBxD,MAAM,oBAAoB;CAAC;CAAW;CAAQ;CAAS;AACvD,MAAM,eAAeA,OAAAA,EAAE,KAAK,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AAU,WAAW,mBAAmB,OAC1C,OAAM,IAAI,MACR,8BAA8B,UAAU,OAAO,iDAAiD,mBAAmB,OAAO,IAC3H;IAGH,MAAM,mBAA+B,CAAC,GAAG,sBAAsB;IAC/D,MAAM,yBAAwC,EAAE;IAChD,MAAM,uBAAuB,UAAU,MACpC,aAAa,SAAS,SAAS,SACjC;;;;AAKD,SAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;KACzC,MAAM,WAAW,UAAU;KAC3B,MAAM,WAAW,mBAAmB;KACpC,MAAM,kBAAkB,gBAAgB,SAAS;KAEjD,MAAM,EAAE,iBAAiB,gBAAgB,gBACvC,UACA,UACA,gBACD;AAED,SACE,oBAMC,CAAC,wBAAwB,SAAS,SAAS,UAE5C,kBAAiB,KAAK,gBAAgB;AAExC,SAAI,YACF,wBAAuB,KAAK,YAAY;;;;;AAO5C,QAAIA,yBAAAA,UAAU,WAAW,YAAY,CACnC,aAAY,aAAa;IAG3B,MAAM,SAAmC,uBACrC,UACA,KAAA;AACJ,WAAO;KACL,UAAU,CAAC,aAAa,GAAG,uBAAuB;KAClD;KACD;;GAEJ;EACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"hitl.cjs","names":["z","ToolMessage","createMiddleware","AIMessage"],"sources":["../../../src/agents/middleware/hitl.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v3\";\nimport { AIMessage, ToolMessage, ToolCall } from \"@langchain/core/messages\";\nimport {\n InferInteropZodInput,\n interopParse,\n} from \"@langchain/core/utils/types\";\nimport { interrupt } from \"@langchain/langgraph\";\n\nimport { createMiddleware } from \"../middleware.js\";\nimport type { AgentBuiltInState, Runtime } from \"../runtime.js\";\nimport type { JumpToTarget } from \"../constants.js\";\nimport type { ToolCallRequest } from \"./types.js\";\n\nconst WhenFunctionSchema = z\n .function()\n .args(z.custom<ToolCallRequest<AgentBuiltInState>>()) // request\n .returns(z.union([z.boolean(), z.promise(z.boolean())]));\n\n/**\n * Predicate controlling whether a given tool call triggers an interrupt.\n *\n * Receives a {@link ToolCallRequest} and returns `true` to interrupt or `false`\n * to auto-approve the tool call.\n *\n * The request is constructed with `tool` set to `undefined` and `runtime` set to\n * the node-level {@link Runtime}, so it reflects the batch (`afterModel`) context\n * rather than a per-call tool execution.\n *\n * @param request - The tool call request being evaluated\n * @returns `true` to interrupt for the tool call, `false` to auto-approve it.\n * May also return a promise resolving to a boolean.\n *\n * @example\n * ```typescript\n * import { type WhenPredicate } from \"langchain\";\n *\n * // Only interrupt delete_file calls targeting /etc\n * const when: WhenPredicate = (request) =>\n * String(request.toolCall.args.path ?? \"\").startsWith(\"/etc\");\n * ```\n */\nexport type WhenPredicate = z.infer<typeof WhenFunctionSchema>;\n\nconst DescriptionFunctionSchema = z\n .function()\n .args(\n z.custom<ToolCall>(), // toolCall\n z.custom<AgentBuiltInState>(), // state\n z.custom<Runtime<unknown>>() // runtime\n )\n .returns(z.union([z.string(), z.promise(z.string())]));\n\n/**\n * Function type that dynamically generates a description for a tool call approval request.\n *\n * @param toolCall - The tool call being reviewed\n * @param state - The current agent state\n * @param runtime - The agent runtime context\n * @returns A string description or Promise that resolves to a string description\n *\n * @example\n * ```typescript\n * import { type DescriptionFactory, type ToolCall } from \"langchain\";\n *\n * const descriptionFactory: DescriptionFactory = (toolCall, state, runtime) => {\n * return `Please review: ${toolCall.name}(${JSON.stringify(toolCall.args)})`;\n * };\n * ```\n */\nexport type DescriptionFactory = z.infer<typeof DescriptionFunctionSchema>;\n\n/**\n * The type of decision a human can make.\n */\nconst ALLOWED_DECISIONS = [\"approve\", \"edit\", \"reject\"] as const;\nconst DecisionType = z.enum(ALLOWED_DECISIONS);\nexport type DecisionType = z.infer<typeof DecisionType>;\n\nconst InterruptOnConfigSchema = z.object({\n /**\n * The decisions that are allowed for this action.\n */\n allowedDecisions: z.array(DecisionType),\n /**\n * The description attached to the request for human input.\n * Can be either:\n * - A static string describing the approval request\n * - A callable that dynamically generates the description based on agent state,\n * runtime, and tool call information\n *\n * @example\n * Static string description\n * ```typescript\n * import type { InterruptOnConfig } from \"langchain\";\n *\n * const config: InterruptOnConfig = {\n * allowedDecisions: [\"approve\", \"reject\"],\n * description: \"Please review this tool execution\"\n * };\n * ```\n *\n * @example\n * Dynamic callable description\n * ```typescript\n * import type {\n * AgentBuiltInState,\n * Runtime,\n * DescriptionFactory,\n * ToolCall,\n * InterruptOnConfig\n * } from \"langchain\";\n *\n * const formatToolDescription: DescriptionFactory = (\n * toolCall: ToolCall,\n * state: AgentBuiltInState,\n * runtime: Runtime<unknown>\n * ) => {\n * return `Tool: ${toolCall.name}\\nArguments:\\n${JSON.stringify(toolCall.args, null, 2)}`;\n * };\n *\n * const config: InterruptOnConfig = {\n * allowedDecisions: [\"approve\", \"edit\"],\n * description: formatToolDescription\n * };\n * ```\n */\n description: z.union([z.string(), DescriptionFunctionSchema]).optional(),\n /**\n * JSON schema for the arguments associated with the action, if edits are allowed.\n */\n argsSchema: z.record(z.any()).optional(),\n /**\n * Optional predicate controlling whether to interrupt for a given tool call.\n *\n * Receives a {@link ToolCallRequest} and returns `true` to interrupt or\n * `false` to auto-approve the tool call.\n *\n * The request is constructed with `tool` set to `undefined` and `runtime` set\n * to the node-level {@link Runtime}, so `request.tool` is not available.\n *\n * @example\n * ```typescript\n * import type { InterruptOnConfig } from \"langchain\";\n *\n * // Only interrupt delete_file calls targeting /etc\n * const config: InterruptOnConfig = {\n * allowedDecisions: [\"approve\", \"reject\"],\n * when: (request) =>\n * String(request.toolCall.args.path ?? \"\").startsWith(\"/etc\"),\n * };\n * ```\n */\n when: WhenFunctionSchema.optional(),\n});\nexport type InterruptOnConfig = z.input<typeof InterruptOnConfigSchema>;\n\n/**\n * Represents an action with a name and arguments.\n */\nexport interface Action {\n /**\n * The type or name of action being requested (e.g., \"add_numbers\").\n */\n name: string;\n /**\n * Key-value pairs of arguments needed for the action (e.g., {\"a\": 1, \"b\": 2}).\n */\n args: Record<string, any>;\n}\n\n/**\n * Represents an action request with a name, arguments, and description.\n */\nexport interface ActionRequest {\n /**\n * The name of the action being requested.\n */\n name: string;\n /**\n * Key-value pairs of arguments needed for the action (e.g., {\"a\": 1, \"b\": 2}).\n */\n args: Record<string, any>;\n /**\n * The description of the action to be reviewed.\n */\n description?: string;\n}\n\n/**\n * Policy for reviewing a HITL request.\n */\nexport interface ReviewConfig {\n /**\n * Name of the action associated with this review configuration.\n */\n actionName: string;\n /**\n * The decisions that are allowed for this request.\n */\n allowedDecisions: DecisionType[];\n /**\n * JSON schema for the arguments associated with the action, if edits are allowed.\n */\n argsSchema?: Record<string, any>;\n}\n\n/**\n * Request for human feedback on a sequence of actions requested by a model.\n *\n * @example\n * ```ts\n * const hitlRequest: HITLRequest = {\n * actionRequests: [\n * { name: \"send_email\", args: { to: \"user@example.com\", subject: \"Hello\" } }\n * ],\n * reviewConfigs: [\n * {\n * actionName: \"send_email\",\n * allowedDecisions: [\"approve\", \"edit\", \"reject\"],\n * description: \"Please review the email before sending\"\n * }\n * ]\n * };\n * const response = interrupt(hitlRequest);\n * ```\n */\nexport interface HITLRequest {\n /**\n * A list of agent actions for human review.\n */\n actionRequests: ActionRequest[];\n /**\n * Review configuration for all possible actions.\n */\n reviewConfigs: ReviewConfig[];\n}\n\n/**\n * Response when a human approves the action.\n */\nexport interface ApproveDecision {\n type: \"approve\";\n}\n\n/**\n * Response when a human edits the action.\n */\nexport interface EditDecision {\n type: \"edit\";\n /**\n * Edited action for the agent to perform.\n * Ex: for a tool call, a human reviewer can edit the tool name and args.\n */\n editedAction: Action;\n}\n\n/**\n * Response when a human rejects the action.\n */\nexport interface RejectDecision {\n type: \"reject\";\n /**\n * The message sent to the model explaining why the action was rejected.\n */\n message?: string;\n}\n\n/**\n * Union of all possible decision types.\n */\nexport type Decision = ApproveDecision | EditDecision | RejectDecision;\n\n/**\n * Response payload for a HITLRequest.\n */\nexport interface HITLResponse {\n /**\n * The decisions made by the human.\n */\n decisions: Decision[];\n}\n\nconst contextSchema = z.object({\n /**\n * Mapping of tool name to allowed reviewer responses.\n * If a tool doesn't have an entry, it's auto-approved by default.\n *\n * - `true` -> pause for approval and allow approve/edit/reject decisions\n * - `false` -> auto-approve (no human review)\n * - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool\n */\n interruptOn: z\n .record(z.union([z.boolean(), InterruptOnConfigSchema]))\n .optional(),\n /**\n * Prefix used when constructing human-facing approval messages.\n * Provides context about the tool call being reviewed; does not change the underlying action.\n *\n * Note: This prefix is only applied for tools that do not provide a custom\n * `description` via their {@link InterruptOnConfig}. If a tool specifies a custom\n * `description`, that per-tool text is used and this prefix is ignored.\n */\n descriptionPrefix: z.string().default(\"Tool execution requires approval\"),\n});\nexport type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<\n typeof contextSchema\n>;\n\n/**\n * Creates a Human-in-the-Loop (HITL) middleware for tool approval and oversight.\n *\n * This middleware intercepts tool calls made by an AI agent and provides human oversight\n * capabilities before execution. It enables selective approval workflows where certain tools\n * require human intervention while others can execute automatically.\n *\n * A invocation result that has been interrupted by the middleware will have a `__interrupt__`\n * property that contains the interrupt request.\n *\n * ```ts\n * import { type HITLRequest, type HITLResponse } from \"langchain\";\n * import { type Interrupt } from \"langchain\";\n *\n * const result = await agent.invoke(request);\n * const interruptRequest = result.__interrupt__?.[0] as Interrupt<HITLRequest>;\n *\n * // Examine the action requests and review configs\n * const actionRequests = interruptRequest.value.actionRequests;\n * const reviewConfigs = interruptRequest.value.reviewConfigs;\n *\n * // Create decisions for each action\n * const resume: HITLResponse = {\n * decisions: actionRequests.map((action, i) => {\n * if (action.name === \"calculator\") {\n * return { type: \"approve\" };\n * } else if (action.name === \"write_file\") {\n * return {\n * type: \"edit\",\n * editedAction: { name: \"write_file\", args: { filename: \"safe.txt\", content: \"Safe content\" } }\n * };\n * }\n * return { type: \"reject\", message: \"Action not allowed\" };\n * })\n * };\n *\n * // Resume with decisions\n * await agent.invoke(new Command({ resume }), config);\n * ```\n *\n * ## Features\n *\n * - **Selective Tool Approval**: Configure which tools require human approval\n * - **Multiple Decision Types**: Approve, edit, or reject tool calls\n * - **Asynchronous Workflow**: Uses LangGraph's interrupt mechanism for non-blocking approval\n * - **Custom Approval Messages**: Provide context-specific descriptions for approval requests\n *\n * ## Decision Types\n *\n * When a tool requires approval, the human operator can respond with:\n * - `approve`: Execute the tool with original arguments\n * - `edit`: Modify the tool name and/or arguments before execution\n * - `reject`: Provide a manual response instead of executing the tool\n *\n * @param options - Configuration options for the middleware\n * @param options.interruptOn - Per-tool configuration mapping tool names to their settings\n * @param options.interruptOn[toolName].allowedDecisions - Array of decision types allowed for this tool (e.g., [\"approve\", \"edit\", \"reject\"])\n * @param options.interruptOn[toolName].description - Custom approval message for the tool. Can be either a static string or a callable that dynamically generates the description based on agent state, runtime, and tool call information\n * @param options.interruptOn[toolName].argsSchema - JSON schema for the arguments associated with the action, if edits are allowed\n * @param options.interruptOn[toolName].when - Optional predicate that dynamically controls whether a tool call triggers an interrupt. Returns `true` to interrupt or `false` to auto-approve the tool call.\n * @param options.descriptionPrefix - Default prefix for approval messages (default: \"Tool execution requires approval\"). Only used for tools that do not define a custom `description` in their InterruptOnConfig.\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @example\n * Basic usage with selective tool approval\n * ```typescript\n * import { humanInTheLoopMiddleware } from \"langchain\";\n * import { createAgent } from \"langchain\";\n *\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * // Interrupt write_file tool and allow edits or approvals\n * \"write_file\": {\n * allowedDecisions: [\"approve\", \"edit\"],\n * description: \"⚠️ File write operation requires approval\"\n * },\n * // Auto-approve read_file tool\n * \"read_file\": false\n * }\n * });\n *\n * const agent = createAgent({\n * model: \"openai:gpt-4\",\n * tools: [writeFileTool, readFileTool],\n * middleware: [hitlMiddleware]\n * });\n * ```\n *\n * @example\n * Handling approval requests\n * ```typescript\n * import { type HITLRequest, type HITLResponse, type Interrupt } from \"langchain\";\n * import { Command } from \"@langchain/langgraph\";\n *\n * // Initial agent invocation\n * const result = await agent.invoke({\n * messages: [new HumanMessage(\"Write 'Hello' to output.txt\")]\n * }, config);\n *\n * // Check if agent is paused for approval\n * if (result.__interrupt__) {\n * const interruptRequest = result.__interrupt__?.[0] as Interrupt<HITLRequest>;\n *\n * // Show tool call details to user\n * console.log(\"Actions:\", interruptRequest.value.actionRequests);\n * console.log(\"Review configs:\", interruptRequest.value.reviewConfigs);\n *\n * // Resume with approval\n * const resume: HITLResponse = {\n * decisions: [{ type: \"approve\" }]\n * };\n * await agent.invoke(\n * new Command({ resume }),\n * config\n * );\n * }\n * ```\n *\n * @example\n * Different decision types\n * ```typescript\n * import { type HITLResponse } from \"langchain\";\n *\n * // Approve the tool call as-is\n * const resume: HITLResponse = {\n * decisions: [{ type: \"approve\" }]\n * };\n *\n * // Edit the tool arguments\n * const resume: HITLResponse = {\n * decisions: [{\n * type: \"edit\",\n * editedAction: { name: \"write_file\", args: { filename: \"safe.txt\", content: \"Modified\" } }\n * }]\n * };\n *\n * // Reject with feedback\n * const resume: HITLResponse = {\n * decisions: [{\n * type: \"reject\",\n * message: \"File operation not allowed in demo mode\"\n * }]\n * };\n * ```\n *\n * @example\n * Production use case with database operations\n * ```typescript\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * \"execute_sql\": {\n * allowedDecisions: [\"approve\", \"edit\", \"reject\"],\n * description: \"🚨 SQL query requires DBA approval\\nPlease review for safety and performance\"\n * },\n * \"read_schema\": false, // Reading metadata is safe\n * \"delete_records\": {\n * allowedDecisions: [\"approve\", \"reject\"],\n * description: \"⛔ DESTRUCTIVE OPERATION - Requires manager approval\"\n * }\n * },\n * descriptionPrefix: \"Database operation pending approval\"\n * });\n * ```\n *\n * @example\n * Using dynamic callable descriptions\n * ```typescript\n * import { type DescriptionFactory, type ToolCall } from \"langchain\";\n * import type { AgentBuiltInState, Runtime } from \"langchain/agents\";\n *\n * // Define a dynamic description factory\n * const formatToolDescription: DescriptionFactory = (\n * toolCall: ToolCall,\n * state: AgentBuiltInState,\n * runtime: Runtime<unknown>\n * ) => {\n * return `Tool: ${toolCall.name}\\nArguments:\\n${JSON.stringify(toolCall.args, null, 2)}`;\n * };\n *\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * \"write_file\": {\n * allowedDecisions: [\"approve\", \"edit\"],\n * // Use dynamic description that can access tool call, state, and runtime\n * description: formatToolDescription\n * },\n * // Or use an inline function\n * \"send_email\": {\n * allowedDecisions: [\"approve\", \"reject\"],\n * description: (toolCall, state, runtime) => {\n * const { to, subject } = toolCall.args;\n * return `Email to ${to}\\nSubject: ${subject}\\n\\nRequires approval before sending`;\n * }\n * }\n * }\n * });\n * ```\n *\n * @remarks\n * - Tool calls are processed in the order they appear in the AI message\n * - Auto-approved tools execute immediately without interruption\n * - Multiple tools requiring approval are bundled into a single interrupt request\n * - The middleware operates in the `afterModel` phase, intercepting before tool execution\n * - Requires a checkpointer to maintain state across interruptions\n *\n * @see {@link createAgent} for agent creation\n * @see {@link Command} for resuming interrupted execution\n * @public\n */\nexport function humanInTheLoopMiddleware(\n options: NonNullable<HumanInTheLoopMiddlewareConfig>\n) {\n const createActionAndConfig = async (\n toolCall: ToolCall,\n config: InterruptOnConfig,\n state: AgentBuiltInState,\n runtime: Runtime<unknown>\n ): Promise<{\n actionRequest: ActionRequest;\n reviewConfig: ReviewConfig;\n }> => {\n const toolName = toolCall.name;\n const toolArgs = toolCall.args;\n\n // Generate description using the description field (str or callable)\n const descriptionValue = config.description;\n let description: string;\n if (typeof descriptionValue === \"function\") {\n description = await descriptionValue(toolCall, state, runtime);\n } else if (descriptionValue !== undefined) {\n description = descriptionValue;\n } else {\n description = `${\n options.descriptionPrefix ?? \"Tool execution requires approval\"\n }\\n\\nTool: ${toolName}\\nArgs: ${JSON.stringify(toolArgs, null, 2)}`;\n }\n\n /**\n * Create ActionRequest with description\n */\n const actionRequest: ActionRequest = {\n name: toolName,\n args: toolArgs,\n description,\n };\n\n /**\n * Create ReviewConfig\n */\n const reviewConfig: ReviewConfig = {\n actionName: toolName,\n allowedDecisions: config.allowedDecisions,\n };\n\n if (config.argsSchema) {\n reviewConfig.argsSchema = config.argsSchema;\n }\n\n return { actionRequest, reviewConfig };\n };\n\n /**\n * Return `false` if the `when` predicate rejects this tool call, `true` otherwise.\n *\n * When no `when` predicate is configured the tool call always interrupts.\n */\n const shouldInterrupt = async (\n toolCall: ToolCall,\n config: InterruptOnConfig,\n state: AgentBuiltInState,\n runtime: Runtime<unknown>\n ): Promise<boolean> => {\n const { when } = config;\n if (when == null) {\n return true;\n }\n const request: ToolCallRequest<AgentBuiltInState> = {\n toolCall,\n tool: undefined,\n state,\n runtime,\n };\n return when(request);\n };\n\n const processDecision = (\n decision: Decision,\n toolCall: ToolCall,\n config: InterruptOnConfig\n ): { revisedToolCall: ToolCall | null; toolMessage: ToolMessage | null } => {\n const allowedDecisions = config.allowedDecisions;\n if (decision.type === \"approve\" && allowedDecisions.includes(\"approve\")) {\n return { revisedToolCall: toolCall, toolMessage: null };\n }\n\n if (decision.type === \"edit\" && allowedDecisions.includes(\"edit\")) {\n const editedAction = decision.editedAction;\n\n /**\n * Validate edited action structure\n */\n if (!editedAction || typeof editedAction.name !== \"string\") {\n throw new Error(\n `Invalid edited action for tool \"${toolCall.name}\": name must be a string`\n );\n }\n if (!editedAction.args || typeof editedAction.args !== \"object\") {\n throw new Error(\n `Invalid edited action for tool \"${toolCall.name}\": args must be an object`\n );\n }\n\n return {\n revisedToolCall: {\n type: \"tool_call\",\n name: editedAction.name,\n args: editedAction.args,\n id: toolCall.id,\n },\n toolMessage: null,\n };\n }\n\n if (decision.type === \"reject\" && allowedDecisions.includes(\"reject\")) {\n /**\n * Validate that message is a string if provided\n */\n if (\n decision.message !== undefined &&\n typeof decision.message !== \"string\"\n ) {\n throw new Error(\n `Tool call response for \"${\n toolCall.name\n }\" must be a string, got ${typeof decision.message}`\n );\n }\n\n // Create a tool message with the human's text response\n const content =\n decision.message ??\n `User rejected the tool call for \\`${toolCall.name}\\` with id ${toolCall.id}`;\n\n const toolMessage = new ToolMessage({\n content,\n name: toolCall.name,\n tool_call_id: toolCall.id!,\n status: \"error\",\n });\n\n return { revisedToolCall: toolCall, toolMessage };\n }\n\n const msg = `Unexpected human decision: ${JSON.stringify(\n decision\n )}. Decision type '${decision.type}' is not allowed for tool '${\n toolCall.name\n }'. Expected one of ${JSON.stringify(\n allowedDecisions\n )} based on the tool's configuration.`;\n throw new Error(msg);\n };\n\n return createMiddleware({\n name: \"HumanInTheLoopMiddleware\",\n contextSchema,\n afterModel: {\n canJumpTo: [\"model\"],\n hook: async (state, runtime) => {\n const config = interopParse(contextSchema, {\n ...options,\n ...(runtime.context || {}),\n });\n if (!config) {\n return;\n }\n\n const { messages } = state;\n if (!messages.length) {\n return;\n }\n\n /**\n * Don't do anything if the last message isn't an AI message with tool calls.\n */\n const lastMessage = [...messages]\n .reverse()\n .find((msg) => AIMessage.isInstance(msg)) as AIMessage;\n if (!lastMessage || !lastMessage.tool_calls?.length) {\n return;\n }\n\n /**\n * If the user omits the interruptOn config, we don't do anything.\n */\n if (!config.interruptOn) {\n return;\n }\n\n /**\n * Resolve per-tool configs (boolean true -> all decisions allowed; false -> auto-approve)\n */\n const resolvedConfigs: Record<string, InterruptOnConfig> = {};\n for (const [toolName, toolConfig] of Object.entries(\n config.interruptOn\n )) {\n if (typeof toolConfig === \"boolean\") {\n if (toolConfig === true) {\n resolvedConfigs[toolName] = {\n allowedDecisions: [...ALLOWED_DECISIONS],\n };\n }\n } else if (toolConfig.allowedDecisions) {\n resolvedConfigs[toolName] = toolConfig as InterruptOnConfig;\n }\n }\n\n const interruptToolCalls: ToolCall[] = [];\n const autoApprovedToolCalls: ToolCall[] = [];\n\n for (const toolCall of lastMessage.tool_calls) {\n const interruptConfig = resolvedConfigs[toolCall.name];\n /**\n * A tool call is interrupted only when it has a resolved config and its\n * optional `when` predicate doesn't opt it out. Otherwise it is\n * auto-approved.\n */\n if (\n interruptConfig &&\n (await shouldInterrupt(toolCall, interruptConfig, state, runtime))\n ) {\n interruptToolCalls.push(toolCall);\n } else {\n autoApprovedToolCalls.push(toolCall);\n }\n }\n\n /**\n * No interrupt tool calls, so we can just return.\n */\n if (!interruptToolCalls.length) {\n return;\n }\n\n /**\n * Create action requests and review configs for all tools that need approval\n */\n const actionRequests: ActionRequest[] = [];\n const reviewConfigs: ReviewConfig[] = [];\n\n for (const toolCall of interruptToolCalls) {\n const interruptConfig = resolvedConfigs[toolCall.name]!;\n\n /**\n * Create ActionRequest and ReviewConfig using helper method\n */\n const { actionRequest, reviewConfig } = await createActionAndConfig(\n toolCall,\n interruptConfig,\n state,\n runtime\n );\n actionRequests.push(actionRequest);\n reviewConfigs.push(reviewConfig);\n }\n\n /**\n * Create single HITLRequest with all actions and configs\n */\n const hitlRequest: HITLRequest = {\n actionRequests,\n reviewConfigs,\n };\n\n /**\n * Send interrupt and get response\n */\n const hitlResponse = (await interrupt(hitlRequest)) as HITLResponse;\n const decisions = hitlResponse.decisions;\n\n /**\n * Validate that decisions is a valid array before checking length\n */\n if (!decisions || !Array.isArray(decisions)) {\n throw new Error(\n \"Invalid HITLResponse: decisions must be a non-empty array\"\n );\n }\n\n /**\n * Validate that the number of decisions matches the number of interrupt tool calls\n */\n if (decisions.length !== interruptToolCalls.length) {\n throw new Error(\n `Number of human decisions (${decisions.length}) does not match number of hanging tool calls (${interruptToolCalls.length}).`\n );\n }\n\n const revisedToolCalls: ToolCall[] = [...autoApprovedToolCalls];\n const artificialToolMessages: ToolMessage[] = [];\n const hasRejectedToolCalls = decisions.some(\n (decision) => decision.type === \"reject\"\n );\n\n /**\n * Process each decision using helper method\n */\n for (let i = 0; i < decisions.length; i++) {\n const decision = decisions[i]!;\n const toolCall = interruptToolCalls[i]!;\n const interruptConfig = resolvedConfigs[toolCall.name]!;\n\n const { revisedToolCall, toolMessage } = processDecision(\n decision,\n toolCall,\n interruptConfig\n );\n\n if (\n revisedToolCall &&\n /**\n * If any decision is a rejected, we are going back to the model\n * with only the tool calls that were rejected as we don't know\n * the results of the approved/updated tool calls at this point.\n */\n (!hasRejectedToolCalls || decision.type === \"reject\")\n ) {\n revisedToolCalls.push(revisedToolCall);\n }\n if (toolMessage) {\n artificialToolMessages.push(toolMessage);\n }\n }\n\n /**\n * Update the AI message to only include approved tool calls\n */\n if (AIMessage.isInstance(lastMessage)) {\n lastMessage.tool_calls = revisedToolCalls;\n }\n\n const jumpTo: JumpToTarget | undefined = hasRejectedToolCalls\n ? \"model\"\n : undefined;\n return {\n messages: [lastMessage, ...artificialToolMessages],\n jumpTo,\n };\n },\n },\n });\n}\n"],"mappings":";;;;;;;AAcA,MAAM,qBAAqBA,OAAAA,EACxB,UAAU,CACV,KAAKA,OAAAA,EAAE,QAA4C,CAAC,CACpD,QAAQA,OAAAA,EAAE,MAAM,CAACA,OAAAA,EAAE,SAAS,EAAEA,OAAAA,EAAE,QAAQA,OAAAA,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AA2B1D,MAAM,4BAA4BA,OAAAA,EAC/B,UAAU,CACV,KACCA,OAAAA,EAAE,QAAkB,EACpBA,OAAAA,EAAE,QAA2B,EAC7BA,OAAAA,EAAE,QAA0B,CAC7B,CACA,QAAQA,OAAAA,EAAE,MAAM,CAACA,OAAAA,EAAE,QAAQ,EAAEA,OAAAA,EAAE,QAAQA,OAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;;;;AAwBxD,MAAM,oBAAoB;CAAC;CAAW;CAAQ;CAAS;AACvD,MAAM,eAAeA,OAAAA,EAAE,KAAK,kBAAkB;AAG9C,MAAM,0BAA0BA,OAAAA,EAAE,OAAO;CAIvC,kBAAkBA,OAAAA,EAAE,MAAM,aAAa;CA4CvC,aAAaA,OAAAA,EAAE,MAAM,CAACA,OAAAA,EAAE,QAAQ,EAAE,0BAA0B,CAAC,CAAC,UAAU;CAIxE,YAAYA,OAAAA,EAAE,OAAOA,OAAAA,EAAE,KAAK,CAAC,C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AAM,IAAI,MACR,4DACD;;;;AAMH,QAAI,UAAU,WAAW,mBAAmB,OAC1C,OAAM,IAAI,MACR,8BAA8B,UAAU,OAAO,iDAAiD,mBAAmB,OAAO,IAC3H;IAGH,MAAM,mBAA+B,CAAC,GAAG,sBAAsB;IAC/D,MAAM,yBAAwC,EAAE;IAChD,MAAM,uBAAuB,UAAU,MACpC,aAAa,SAAS,SAAS,SACjC;;;;AAKD,SAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;KACzC,MAAM,WAAW,UAAU;KAC3B,MAAM,WAAW,mBAAmB;KACpC,MAAM,kBAAkB,gBAAgB,SAAS;KAEjD,MAAM,EAAE,iBAAiB,gBAAgB,gBACvC,UACA,UACA,gBACD;AAED,SACE,oBAMC,CAAC,wBAAwB,SAAS,SAAS,UAE5C,kBAAiB,KAAK,gBAAgB;AAExC,SAAI,YACF,wBAAuB,KAAK,YAAY;;;;;AAO5C,QAAIA,yBAAAA,UAAU,WAAW,YAAY,CACnC,aAAY,aAAa;IAG3B,MAAM,SAAmC,uBACrC,UACA,KAAA;AACJ,WAAO;KACL,UAAU,CAAC,aAAa,GAAG,uBAAuB;KAClD;KACD;;GAEJ;EACF,CAAC"}
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
import { AgentBuiltInState, Runtime } from "../runtime.cjs";
|
|
2
|
-
import { AgentMiddleware } from "./types.cjs";
|
|
2
|
+
import { AgentMiddleware, ToolCallRequest } from "./types.cjs";
|
|
3
3
|
import { ToolCall } from "@langchain/core/messages";
|
|
4
4
|
import * as _$_langchain_core_tools0 from "@langchain/core/tools";
|
|
5
5
|
import { InferInteropZodInput } from "@langchain/core/utils/types";
|
|
6
6
|
import { z } from "zod/v3";
|
|
7
7
|
|
|
8
8
|
//#region src/agents/middleware/hitl.d.ts
|
|
9
|
+
declare const WhenFunctionSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodPromise<z.ZodBoolean>]>>;
|
|
10
|
+
/**
|
|
11
|
+
* Predicate controlling whether a given tool call triggers an interrupt.
|
|
12
|
+
*
|
|
13
|
+
* Receives a {@link ToolCallRequest} and returns `true` to interrupt or `false`
|
|
14
|
+
* to auto-approve the tool call.
|
|
15
|
+
*
|
|
16
|
+
* The request is constructed with `tool` set to `undefined` and `runtime` set to
|
|
17
|
+
* the node-level {@link Runtime}, so it reflects the batch (`afterModel`) context
|
|
18
|
+
* rather than a per-call tool execution.
|
|
19
|
+
*
|
|
20
|
+
* @param request - The tool call request being evaluated
|
|
21
|
+
* @returns `true` to interrupt for the tool call, `false` to auto-approve it.
|
|
22
|
+
* May also return a promise resolving to a boolean.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { type WhenPredicate } from "langchain";
|
|
27
|
+
*
|
|
28
|
+
* // Only interrupt delete_file calls targeting /etc
|
|
29
|
+
* const when: WhenPredicate = (request) =>
|
|
30
|
+
* String(request.toolCall.args.path ?? "").startsWith("/etc");
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
type WhenPredicate = z.infer<typeof WhenFunctionSchema>;
|
|
9
34
|
declare const DescriptionFunctionSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCall<string, Record<string, any>>, z.ZodTypeDef, ToolCall<string, Record<string, any>>>, z.ZodType<AgentBuiltInState, z.ZodTypeDef, AgentBuiltInState>, z.ZodType<Runtime<unknown>, z.ZodTypeDef, Runtime<unknown>>], z.ZodUnknown>, z.ZodUnion<[z.ZodString, z.ZodPromise<z.ZodString>]>>;
|
|
10
35
|
/**
|
|
11
36
|
* Function type that dynamically generates a description for a tool call approval request.
|
|
@@ -80,14 +105,38 @@ declare const InterruptOnConfigSchema: z.ZodObject<{
|
|
|
80
105
|
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
81
106
|
*/
|
|
82
107
|
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
108
|
+
/**
|
|
109
|
+
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
110
|
+
*
|
|
111
|
+
* Receives a {@link ToolCallRequest} and returns `true` to interrupt or
|
|
112
|
+
* `false` to auto-approve the tool call.
|
|
113
|
+
*
|
|
114
|
+
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
115
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* import type { InterruptOnConfig } from "langchain";
|
|
120
|
+
*
|
|
121
|
+
* // Only interrupt delete_file calls targeting /etc
|
|
122
|
+
* const config: InterruptOnConfig = {
|
|
123
|
+
* allowedDecisions: ["approve", "reject"],
|
|
124
|
+
* when: (request) =>
|
|
125
|
+
* String(request.toolCall.args.path ?? "").startsWith("/etc"),
|
|
126
|
+
* };
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
when: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodPromise<z.ZodBoolean>]>>>;
|
|
83
130
|
}, "strip", z.ZodTypeAny, {
|
|
84
131
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
85
132
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
86
133
|
argsSchema?: Record<string, any> | undefined;
|
|
134
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
87
135
|
}, {
|
|
88
136
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
89
137
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
90
138
|
argsSchema?: Record<string, any> | undefined;
|
|
139
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
91
140
|
}>;
|
|
92
141
|
type InterruptOnConfig = z.input<typeof InterruptOnConfigSchema>;
|
|
93
142
|
/**
|
|
@@ -269,14 +318,38 @@ declare const contextSchema: z.ZodObject<{
|
|
|
269
318
|
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
270
319
|
*/
|
|
271
320
|
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
321
|
+
/**
|
|
322
|
+
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
323
|
+
*
|
|
324
|
+
* Receives a {@link ToolCallRequest} and returns `true` to interrupt or
|
|
325
|
+
* `false` to auto-approve the tool call.
|
|
326
|
+
*
|
|
327
|
+
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
328
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* import type { InterruptOnConfig } from "langchain";
|
|
333
|
+
*
|
|
334
|
+
* // Only interrupt delete_file calls targeting /etc
|
|
335
|
+
* const config: InterruptOnConfig = {
|
|
336
|
+
* allowedDecisions: ["approve", "reject"],
|
|
337
|
+
* when: (request) =>
|
|
338
|
+
* String(request.toolCall.args.path ?? "").startsWith("/etc"),
|
|
339
|
+
* };
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
when: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodPromise<z.ZodBoolean>]>>>;
|
|
272
343
|
}, "strip", z.ZodTypeAny, {
|
|
273
344
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
274
345
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
275
346
|
argsSchema?: Record<string, any> | undefined;
|
|
347
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
276
348
|
}, {
|
|
277
349
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
278
350
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
279
351
|
argsSchema?: Record<string, any> | undefined;
|
|
352
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
280
353
|
}>]>>>;
|
|
281
354
|
/**
|
|
282
355
|
* Prefix used when constructing human-facing approval messages.
|
|
@@ -292,6 +365,7 @@ declare const contextSchema: z.ZodObject<{
|
|
|
292
365
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
293
366
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
294
367
|
argsSchema?: Record<string, any> | undefined;
|
|
368
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
295
369
|
}> | undefined;
|
|
296
370
|
descriptionPrefix: string;
|
|
297
371
|
}, {
|
|
@@ -299,6 +373,7 @@ declare const contextSchema: z.ZodObject<{
|
|
|
299
373
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
300
374
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
301
375
|
argsSchema?: Record<string, any> | undefined;
|
|
376
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
302
377
|
}> | undefined;
|
|
303
378
|
descriptionPrefix?: string | undefined;
|
|
304
379
|
}>;
|
|
@@ -362,6 +437,7 @@ type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof contextSchema>
|
|
|
362
437
|
* @param options.interruptOn[toolName].allowedDecisions - Array of decision types allowed for this tool (e.g., ["approve", "edit", "reject"])
|
|
363
438
|
* @param options.interruptOn[toolName].description - Custom approval message for the tool. Can be either a static string or a callable that dynamically generates the description based on agent state, runtime, and tool call information
|
|
364
439
|
* @param options.interruptOn[toolName].argsSchema - JSON schema for the arguments associated with the action, if edits are allowed
|
|
440
|
+
* @param options.interruptOn[toolName].when - Optional predicate that dynamically controls whether a tool call triggers an interrupt. Returns `true` to interrupt or `false` to auto-approve the tool call.
|
|
365
441
|
* @param options.descriptionPrefix - Default prefix for approval messages (default: "Tool execution requires approval"). Only used for tools that do not define a custom `description` in their InterruptOnConfig.
|
|
366
442
|
*
|
|
367
443
|
* @returns A middleware instance that can be passed to `createAgent`
|
|
@@ -574,14 +650,38 @@ declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMid
|
|
|
574
650
|
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
575
651
|
*/
|
|
576
652
|
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
653
|
+
/**
|
|
654
|
+
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
655
|
+
*
|
|
656
|
+
* Receives a {@link ToolCallRequest} and returns `true` to interrupt or
|
|
657
|
+
* `false` to auto-approve the tool call.
|
|
658
|
+
*
|
|
659
|
+
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
660
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```typescript
|
|
664
|
+
* import type { InterruptOnConfig } from "langchain";
|
|
665
|
+
*
|
|
666
|
+
* // Only interrupt delete_file calls targeting /etc
|
|
667
|
+
* const config: InterruptOnConfig = {
|
|
668
|
+
* allowedDecisions: ["approve", "reject"],
|
|
669
|
+
* when: (request) =>
|
|
670
|
+
* String(request.toolCall.args.path ?? "").startsWith("/etc"),
|
|
671
|
+
* };
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
when: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodPromise<z.ZodBoolean>]>>>;
|
|
577
675
|
}, "strip", z.ZodTypeAny, {
|
|
578
676
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
579
677
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
580
678
|
argsSchema?: Record<string, any> | undefined;
|
|
679
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
581
680
|
}, {
|
|
582
681
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
583
682
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
584
683
|
argsSchema?: Record<string, any> | undefined;
|
|
684
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
585
685
|
}>]>>>;
|
|
586
686
|
/**
|
|
587
687
|
* Prefix used when constructing human-facing approval messages.
|
|
@@ -597,6 +697,7 @@ declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMid
|
|
|
597
697
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
598
698
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
599
699
|
argsSchema?: Record<string, any> | undefined;
|
|
700
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
600
701
|
}> | undefined;
|
|
601
702
|
descriptionPrefix: string;
|
|
602
703
|
}, {
|
|
@@ -604,6 +705,7 @@ declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMid
|
|
|
604
705
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
605
706
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
606
707
|
argsSchema?: Record<string, any> | undefined;
|
|
708
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
607
709
|
}> | undefined;
|
|
608
710
|
descriptionPrefix?: string | undefined;
|
|
609
711
|
}>, {
|
|
@@ -611,9 +713,10 @@ declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMid
|
|
|
611
713
|
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
612
714
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
613
715
|
argsSchema?: Record<string, any> | undefined;
|
|
716
|
+
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
614
717
|
}> | undefined;
|
|
615
718
|
descriptionPrefix: string;
|
|
616
719
|
}, readonly (_$_langchain_core_tools0.ServerTool | _$_langchain_core_tools0.ClientTool)[], readonly []>;
|
|
617
720
|
//#endregion
|
|
618
|
-
export { Action, ActionRequest, ApproveDecision, Decision, DecisionType, DescriptionFactory, EditDecision, HITLRequest, HITLResponse, HumanInTheLoopMiddlewareConfig, InterruptOnConfig, RejectDecision, ReviewConfig, humanInTheLoopMiddleware };
|
|
721
|
+
export { Action, ActionRequest, ApproveDecision, Decision, DecisionType, DescriptionFactory, EditDecision, HITLRequest, HITLResponse, HumanInTheLoopMiddlewareConfig, InterruptOnConfig, RejectDecision, ReviewConfig, WhenPredicate, humanInTheLoopMiddleware };
|
|
619
722
|
//# sourceMappingURL=hitl.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl.d.cts","names":[],"sources":["../../../src/agents/middleware/hitl.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"hitl.d.cts","names":[],"sources":["../../../src/agents/middleware/hitl.ts"],"mappings":";;;;;;;;cAcM,kBAAA,EAAkB,CAAA,CAAA,WAAA,CAAA,CAAA,CAAA,QAAA,EAAA,CAAA,CAAA,OAAA,CAAA,eAAA,CAAA,iBAAA,YAAA,CAAA,CAAA,UAAA,EAAA,eAAA,CAAA,iBAAA,cAAA,CAAA,CAAA,UAAA,GAAA,CAAA,CAAA,QAAA,EAAA,CAAA,CAAA,UAAA,EAAA,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,UAAA;;;AAF0B;;;;;;;;;;;;;;;;;;;;;KA8BtC,aAAA,GAAgB,CAAA,CAAE,KAAA,QAAa,kBAAA;AAAA,cAErC,yBAAA,EAAyB,CAAA,CAAA,WAAA,CAAA,CAAA,CAAA,QAAA,EAAA,CAAA,CAAA,OAAA,CAAA,QAAA,SAAA,MAAA,gBAAA,CAAA,CAAA,UAAA,EAAA,QAAA,SAAA,MAAA,iBAAA,CAAA,CAAA,OAAA,CAAA,iBAAA,EA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