langchain 1.5.16 → 1.5.18
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/CHANGELOG.md +16 -0
- package/dist/agents/ReactAgent.cjs +1 -0
- package/dist/agents/ReactAgent.cjs.map +1 -1
- package/dist/agents/ReactAgent.d.cts.map +1 -1
- package/dist/agents/ReactAgent.d.ts.map +1 -1
- package/dist/agents/ReactAgent.js +1 -0
- package/dist/agents/ReactAgent.js.map +1 -1
- package/dist/agents/middleware/hitl.cjs +197 -11
- package/dist/agents/middleware/hitl.cjs.map +1 -1
- package/dist/agents/middleware/hitl.d.cts +139 -25
- package/dist/agents/middleware/hitl.d.cts.map +1 -1
- package/dist/agents/middleware/hitl.d.ts +167 -53
- package/dist/agents/middleware/hitl.d.ts.map +1 -1
- package/dist/agents/middleware/hitl.js +210 -25
- package/dist/agents/middleware/hitl.js.map +1 -1
- package/dist/agents/middleware/index.cjs +1 -0
- package/dist/agents/middleware/index.d.cts +2 -2
- package/dist/agents/middleware/index.d.ts +2 -2
- package/dist/agents/middleware/index.js +2 -2
- package/dist/agents/tests/utils.cjs.map +1 -1
- package/dist/agents/tests/utils.d.cts +1 -1
- package/dist/agents/tests/utils.d.ts +1 -1
- package/dist/agents/tests/utils.js.map +1 -1
- package/dist/agents/types.d.cts +6 -0
- package/dist/agents/types.d.cts.map +1 -1
- package/dist/agents/types.d.ts +6 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/browser.cjs +2 -0
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +3 -2
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/package.json +6 -6
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AgentBuiltInState, Runtime } from "../runtime.js";
|
|
2
2
|
import { AgentMiddleware, ToolCallRequest } from "./types.js";
|
|
3
|
+
import { Interrupt } from "../types.js";
|
|
3
4
|
import { ToolCall } from "@langchain/core/messages";
|
|
4
5
|
import { InferInteropZodInput } from "@langchain/core/utils/types";
|
|
5
|
-
import { z } from "zod/
|
|
6
|
+
import { z } from "zod/v4";
|
|
7
|
+
import { z as z$1 } from "zod/v3";
|
|
6
8
|
//#region src/agents/middleware/hitl.d.ts
|
|
7
|
-
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>]>>;
|
|
9
|
+
declare const WhenFunctionSchema: z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z$1.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodBoolean, z$1.ZodPromise<z$1.ZodBoolean>]>>;
|
|
8
10
|
/**
|
|
9
11
|
* Predicate controlling whether a given tool call triggers an interrupt.
|
|
10
12
|
*
|
|
@@ -13,7 +15,12 @@ declare const WhenFunctionSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCallRe
|
|
|
13
15
|
*
|
|
14
16
|
* The request is constructed with `tool` set to `undefined` and `runtime` set to
|
|
15
17
|
* the node-level {@link Runtime}, so it reflects the batch (`afterModel`) context
|
|
16
|
-
* rather than a per-call tool execution.
|
|
18
|
+
* rather than a per-call tool execution. In `"per_call"` mode the predicate runs
|
|
19
|
+
* in `wrapToolCall` and receives the real request, with `tool` set.
|
|
20
|
+
*
|
|
21
|
+
* In both modes the predicate runs again when the run resumes, so it must return
|
|
22
|
+
* the same answer for the same call. If it returns `false` on resume, the
|
|
23
|
+
* reviewer's answer is skipped and the tool runs, even if they rejected it.
|
|
17
24
|
*
|
|
18
25
|
* @param request - The tool call request being evaluated
|
|
19
26
|
* @returns `true` to interrupt for the tool call, `false` to auto-approve it.
|
|
@@ -28,8 +35,8 @@ declare const WhenFunctionSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<ToolCallRe
|
|
|
28
35
|
* String(request.toolCall.args.path ?? "").startsWith("/etc");
|
|
29
36
|
* ```
|
|
30
37
|
*/
|
|
31
|
-
export type WhenPredicate = z.infer<typeof WhenFunctionSchema>;
|
|
32
|
-
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>]>>;
|
|
38
|
+
export type WhenPredicate = z$1.infer<typeof WhenFunctionSchema>;
|
|
39
|
+
declare const DescriptionFunctionSchema: z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCall<string, Record<string, any>>, z$1.ZodTypeDef, ToolCall<string, Record<string, any>>>, z$1.ZodType<AgentBuiltInState, z$1.ZodTypeDef, AgentBuiltInState>, z$1.ZodType<Runtime<unknown>, z$1.ZodTypeDef, Runtime<unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodString, z$1.ZodPromise<z$1.ZodString>]>>;
|
|
33
40
|
/**
|
|
34
41
|
* Function type that dynamically generates a description for a tool call approval request.
|
|
35
42
|
*
|
|
@@ -47,14 +54,14 @@ declare const DescriptionFunctionSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<Too
|
|
|
47
54
|
* };
|
|
48
55
|
* ```
|
|
49
56
|
*/
|
|
50
|
-
export type DescriptionFactory = z.infer<typeof DescriptionFunctionSchema>;
|
|
51
|
-
declare const DecisionType: z.ZodEnum<["approve", "edit", "reject"]>;
|
|
52
|
-
type DecisionType = z.infer<typeof DecisionType>;
|
|
53
|
-
declare const InterruptOnConfigSchema: z.ZodObject<{
|
|
57
|
+
export type DescriptionFactory = z$1.infer<typeof DescriptionFunctionSchema>;
|
|
58
|
+
declare const DecisionType: z$1.ZodEnum<["approve", "edit", "reject", "respond"]>;
|
|
59
|
+
type DecisionType = z$1.infer<typeof DecisionType>;
|
|
60
|
+
declare const InterruptOnConfigSchema: z$1.ZodObject<{
|
|
54
61
|
/**
|
|
55
62
|
* The decisions that are allowed for this action.
|
|
56
63
|
*/
|
|
57
|
-
allowedDecisions: z.ZodArray<z.ZodEnum<["approve", "edit", "reject"]>, "many">;
|
|
64
|
+
allowedDecisions: z$1.ZodArray<z$1.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
58
65
|
/**
|
|
59
66
|
* The description attached to the request for human input.
|
|
60
67
|
* Can be either:
|
|
@@ -98,11 +105,14 @@ declare const InterruptOnConfigSchema: z.ZodObject<{
|
|
|
98
105
|
* };
|
|
99
106
|
* ```
|
|
100
107
|
*/
|
|
101
|
-
description: z.ZodOptional<z.ZodUnion<[z.ZodString, 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>]>>]>>;
|
|
108
|
+
description: z$1.ZodOptional<z$1.ZodUnion<[z$1.ZodString, z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCall<string, Record<string, any>>, z$1.ZodTypeDef, ToolCall<string, Record<string, any>>>, z$1.ZodType<AgentBuiltInState, z$1.ZodTypeDef, AgentBuiltInState>, z$1.ZodType<Runtime<unknown>, z$1.ZodTypeDef, Runtime<unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodString, z$1.ZodPromise<z$1.ZodString>]>>]>>;
|
|
102
109
|
/**
|
|
103
110
|
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
111
|
+
*
|
|
112
|
+
* Not used in `"per_call"` mode: an edit's `args` are checked against the tool's
|
|
113
|
+
* own schema there.
|
|
104
114
|
*/
|
|
105
|
-
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
115
|
+
argsSchema: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
106
116
|
/**
|
|
107
117
|
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
108
118
|
*
|
|
@@ -110,7 +120,9 @@ declare const InterruptOnConfigSchema: z.ZodObject<{
|
|
|
110
120
|
* `false` to auto-approve the tool call.
|
|
111
121
|
*
|
|
112
122
|
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
113
|
-
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
123
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available. In
|
|
124
|
+
* `"per_call"` mode the predicate runs in `wrapToolCall` and receives the real
|
|
125
|
+
* request, with `tool` set.
|
|
114
126
|
*
|
|
115
127
|
* @example
|
|
116
128
|
* ```typescript
|
|
@@ -124,19 +136,19 @@ declare const InterruptOnConfigSchema: z.ZodObject<{
|
|
|
124
136
|
* };
|
|
125
137
|
* ```
|
|
126
138
|
*/
|
|
127
|
-
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>]>>>;
|
|
128
|
-
}, "strip", z.ZodTypeAny, {
|
|
129
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
139
|
+
when: z$1.ZodOptional<z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z$1.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodBoolean, z$1.ZodPromise<z$1.ZodBoolean>]>>>;
|
|
140
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
141
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
130
142
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
131
143
|
argsSchema?: Record<string, any> | undefined;
|
|
132
144
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
133
145
|
}, {
|
|
134
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
146
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
135
147
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
136
148
|
argsSchema?: Record<string, any> | undefined;
|
|
137
149
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
138
150
|
}>;
|
|
139
|
-
export type InterruptOnConfig = z.input<typeof InterruptOnConfigSchema>;
|
|
151
|
+
export type InterruptOnConfig = z$1.input<typeof InterruptOnConfigSchema>;
|
|
140
152
|
/**
|
|
141
153
|
* Represents an action with a name and arguments.
|
|
142
154
|
*/
|
|
@@ -241,10 +253,20 @@ export interface RejectDecision {
|
|
|
241
253
|
*/
|
|
242
254
|
message?: string;
|
|
243
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Response when a human answers on behalf of the tool.
|
|
258
|
+
*/
|
|
259
|
+
export interface RespondDecision {
|
|
260
|
+
type: "respond";
|
|
261
|
+
/**
|
|
262
|
+
* The message sent to the model as the tool result.
|
|
263
|
+
*/
|
|
264
|
+
message: string;
|
|
265
|
+
}
|
|
244
266
|
/**
|
|
245
267
|
* Union of all possible decision types.
|
|
246
268
|
*/
|
|
247
|
-
export type Decision = ApproveDecision | EditDecision | RejectDecision;
|
|
269
|
+
export type Decision = ApproveDecision | EditDecision | RejectDecision | RespondDecision;
|
|
248
270
|
/**
|
|
249
271
|
* Response payload for a HITLRequest.
|
|
250
272
|
*/
|
|
@@ -254,20 +276,66 @@ export interface HITLResponse {
|
|
|
254
276
|
*/
|
|
255
277
|
decisions: Decision[];
|
|
256
278
|
}
|
|
257
|
-
declare const
|
|
279
|
+
declare const ToolApprovalRequestSchema: z.ZodObject<{
|
|
280
|
+
type: z.ZodLiteral<"tool_approval">;
|
|
281
|
+
tool_call_id: z.ZodString;
|
|
282
|
+
name: z.ZodString;
|
|
283
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
284
|
+
description: z.ZodString;
|
|
285
|
+
}, z.core.$strip>;
|
|
286
|
+
/**
|
|
287
|
+
* Interrupt value raised once per gated tool call in `"per_call"` mode. Keys are
|
|
288
|
+
* snake_case, as in Python.
|
|
289
|
+
*/
|
|
290
|
+
export type ToolApprovalRequest = z.infer<typeof ToolApprovalRequestSchema>;
|
|
291
|
+
/**
|
|
292
|
+
* The answers a reviewer can give to a `"per_call"` approval of tool `name`, by type.
|
|
293
|
+
*
|
|
294
|
+
* The edit can't switch tools: its `name` is pinned.
|
|
295
|
+
*/
|
|
296
|
+
declare const toolApprovalDecisions: (name: string, tool?: ToolCallRequest["tool"]) => {
|
|
297
|
+
approve: z.ZodObject<{
|
|
298
|
+
type: z.ZodLiteral<"approve">;
|
|
299
|
+
}, z.core.$strip>;
|
|
300
|
+
edit: z.ZodObject<{
|
|
301
|
+
type: z.ZodLiteral<"edit">;
|
|
302
|
+
edited_action: z.ZodObject<{
|
|
303
|
+
name: z.ZodLiteral<string>;
|
|
304
|
+
args: z.ZodType<Record<string, unknown>, unknown, z.core.$ZodTypeInternals<Record<string, unknown>, unknown>>;
|
|
305
|
+
}, z.core.$strip>;
|
|
306
|
+
}, z.core.$strip>;
|
|
307
|
+
reject: z.ZodObject<{
|
|
308
|
+
type: z.ZodLiteral<"reject">;
|
|
309
|
+
message: z.ZodOptional<z.ZodString>;
|
|
310
|
+
}, z.core.$strip>;
|
|
311
|
+
respond: z.ZodObject<{
|
|
312
|
+
type: z.ZodLiteral<"respond">;
|
|
313
|
+
message: z.ZodString;
|
|
314
|
+
}, z.core.$strip>;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* A reviewer's answer to a `"per_call"` tool approval.
|
|
318
|
+
*/
|
|
319
|
+
export type ToolApprovalDecision = z.infer<ReturnType<typeof toolApprovalDecisions>[DecisionType]>;
|
|
320
|
+
/**
|
|
321
|
+
* Whether an interrupt is a `"per_call"` tool approval, e.g.
|
|
322
|
+
* `result.__interrupt__?.filter(isToolApprovalInterrupt)`.
|
|
323
|
+
*/
|
|
324
|
+
export declare function isToolApprovalInterrupt(interrupt: Interrupt | undefined): interrupt is Interrupt<ToolApprovalRequest>;
|
|
325
|
+
declare const contextSchema: z$1.ZodObject<{
|
|
258
326
|
/**
|
|
259
327
|
* Mapping of tool name to allowed reviewer responses.
|
|
260
328
|
* If a tool doesn't have an entry, it's auto-approved by default.
|
|
261
329
|
*
|
|
262
|
-
* - `true` -> pause for approval and allow approve/edit/reject
|
|
330
|
+
* - `true` -> pause for approval and allow every decision (approve/edit/reject/respond)
|
|
263
331
|
* - `false` -> auto-approve (no human review)
|
|
264
332
|
* - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool
|
|
265
333
|
*/
|
|
266
|
-
interruptOn: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
|
|
334
|
+
interruptOn: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<[z$1.ZodBoolean, z$1.ZodObject<{
|
|
267
335
|
/**
|
|
268
336
|
* The decisions that are allowed for this action.
|
|
269
337
|
*/
|
|
270
|
-
allowedDecisions: z.ZodArray<z.ZodEnum<["approve", "edit", "reject"]>, "many">;
|
|
338
|
+
allowedDecisions: z$1.ZodArray<z$1.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
271
339
|
/**
|
|
272
340
|
* The description attached to the request for human input.
|
|
273
341
|
* Can be either:
|
|
@@ -311,11 +379,14 @@ declare const contextSchema: z.ZodObject<{
|
|
|
311
379
|
* };
|
|
312
380
|
* ```
|
|
313
381
|
*/
|
|
314
|
-
description: z.ZodOptional<z.ZodUnion<[z.ZodString, 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>]>>]>>;
|
|
382
|
+
description: z$1.ZodOptional<z$1.ZodUnion<[z$1.ZodString, z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCall<string, Record<string, any>>, z$1.ZodTypeDef, ToolCall<string, Record<string, any>>>, z$1.ZodType<AgentBuiltInState, z$1.ZodTypeDef, AgentBuiltInState>, z$1.ZodType<Runtime<unknown>, z$1.ZodTypeDef, Runtime<unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodString, z$1.ZodPromise<z$1.ZodString>]>>]>>;
|
|
315
383
|
/**
|
|
316
384
|
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
385
|
+
*
|
|
386
|
+
* Not used in `"per_call"` mode: an edit's `args` are checked against the tool's
|
|
387
|
+
* own schema there.
|
|
317
388
|
*/
|
|
318
|
-
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
389
|
+
argsSchema: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
319
390
|
/**
|
|
320
391
|
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
321
392
|
*
|
|
@@ -323,7 +394,9 @@ declare const contextSchema: z.ZodObject<{
|
|
|
323
394
|
* `false` to auto-approve the tool call.
|
|
324
395
|
*
|
|
325
396
|
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
326
|
-
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
397
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available. In
|
|
398
|
+
* `"per_call"` mode the predicate runs in `wrapToolCall` and receives the real
|
|
399
|
+
* request, with `tool` set.
|
|
327
400
|
*
|
|
328
401
|
* @example
|
|
329
402
|
* ```typescript
|
|
@@ -337,14 +410,14 @@ declare const contextSchema: z.ZodObject<{
|
|
|
337
410
|
* };
|
|
338
411
|
* ```
|
|
339
412
|
*/
|
|
340
|
-
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>]>>>;
|
|
341
|
-
}, "strip", z.ZodTypeAny, {
|
|
342
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
413
|
+
when: z$1.ZodOptional<z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z$1.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodBoolean, z$1.ZodPromise<z$1.ZodBoolean>]>>>;
|
|
414
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
415
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
343
416
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
344
417
|
argsSchema?: Record<string, any> | undefined;
|
|
345
418
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
346
419
|
}, {
|
|
347
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
420
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
348
421
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
349
422
|
argsSchema?: Record<string, any> | undefined;
|
|
350
423
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
@@ -357,10 +430,10 @@ declare const contextSchema: z.ZodObject<{
|
|
|
357
430
|
* `description` via their {@link InterruptOnConfig}. If a tool specifies a custom
|
|
358
431
|
* `description`, that per-tool text is used and this prefix is ignored.
|
|
359
432
|
*/
|
|
360
|
-
descriptionPrefix: z.ZodDefault<z.ZodString>;
|
|
361
|
-
}, "strip", z.ZodTypeAny, {
|
|
433
|
+
descriptionPrefix: z$1.ZodDefault<z$1.ZodString>;
|
|
434
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
362
435
|
interruptOn?: Record<string, boolean | {
|
|
363
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
436
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
364
437
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
365
438
|
argsSchema?: Record<string, any> | undefined;
|
|
366
439
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
@@ -368,14 +441,49 @@ declare const contextSchema: z.ZodObject<{
|
|
|
368
441
|
descriptionPrefix: string;
|
|
369
442
|
}, {
|
|
370
443
|
interruptOn?: Record<string, boolean | {
|
|
371
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
444
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
372
445
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
373
446
|
argsSchema?: Record<string, any> | undefined;
|
|
374
447
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
375
448
|
}> | undefined;
|
|
376
449
|
descriptionPrefix?: string | undefined;
|
|
377
450
|
}>;
|
|
378
|
-
export type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof contextSchema
|
|
451
|
+
export type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof contextSchema> & {
|
|
452
|
+
/**
|
|
453
|
+
* How the middleware pauses for review. Set at construction only.
|
|
454
|
+
*
|
|
455
|
+
* - `"batched"` (default): one interrupt per model turn for all gated tool calls.
|
|
456
|
+
* - `"per_call"`: one {@link ToolApprovalRequest} interrupt per gated call, with a
|
|
457
|
+
* typed `responseSchema`, answered with a single decision keyed by interrupt ID.
|
|
458
|
+
*
|
|
459
|
+
* In `"per_call"` mode, LangGraph checks each answer before saving it:
|
|
460
|
+
*
|
|
461
|
+
* - An edit can't switch tools, and its args must match the tool's argument
|
|
462
|
+
* types. Args the tool doesn't declare are handled as they are when the model
|
|
463
|
+
* sends them. For a tool without a Zod v4 object schema, any object is accepted
|
|
464
|
+
* and the tool checks it when it runs.
|
|
465
|
+
* - An invalid answer throws a `ZodError` and isn't saved, so the same interrupt
|
|
466
|
+
* can be answered again.
|
|
467
|
+
*
|
|
468
|
+
* If one of several answers sent together is invalid, the others' tools may
|
|
469
|
+
* already have run even if they still show as pending, and answering them again
|
|
470
|
+
* would run them twice. Check answers against `responseSchema` before sending them
|
|
471
|
+
* together, or send one at a time.
|
|
472
|
+
*
|
|
473
|
+
* The review happens as the tool call starts, inside the tool-call middleware
|
|
474
|
+
* chain. List this middleware before tool retry or error-handling middleware so it
|
|
475
|
+
* wraps them. On resume, each paused tool call runs the middleware listed before
|
|
476
|
+
* this one again up to the pause, so that middleware must not have side effects
|
|
477
|
+
* before calling `handler`. The tool itself runs only after the answer.
|
|
478
|
+
*/
|
|
479
|
+
interruptMode?: "batched" | "per_call";
|
|
480
|
+
/**
|
|
481
|
+
* `"per_call"` mode only: text prepended to the result of a tool call a reviewer
|
|
482
|
+
* edited, so the model knows the call it made isn't the one that ran. Pass `null`
|
|
483
|
+
* to add nothing.
|
|
484
|
+
*/
|
|
485
|
+
editNotice?: string | null;
|
|
486
|
+
};
|
|
379
487
|
/**
|
|
380
488
|
* Creates a Human-in-the-Loop (HITL) middleware for tool approval and oversight.
|
|
381
489
|
*
|
|
@@ -578,28 +686,29 @@ export type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof context
|
|
|
578
686
|
* @remarks
|
|
579
687
|
* - Tool calls are processed in the order they appear in the AI message
|
|
580
688
|
* - Auto-approved tools execute immediately without interruption
|
|
581
|
-
* -
|
|
582
|
-
*
|
|
689
|
+
* - In the default `"batched"` mode, multiple tools requiring approval are bundled into a
|
|
690
|
+
* single interrupt request, raised in the `afterModel` phase before any tool runs. In
|
|
691
|
+
* `"per_call"` mode, each gated call raises its own interrupt from `wrapToolCall`
|
|
583
692
|
* - Requires a checkpointer to maintain state across interruptions
|
|
584
693
|
*
|
|
585
694
|
* @see {@link createAgent} for agent creation
|
|
586
695
|
* @see {@link Command} for resuming interrupted execution
|
|
587
696
|
* @public
|
|
588
697
|
*/
|
|
589
|
-
export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMiddlewareConfig>): AgentMiddleware<undefined, z.ZodObject<{
|
|
698
|
+
export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMiddlewareConfig>): AgentMiddleware<undefined, z$1.ZodObject<{
|
|
590
699
|
/**
|
|
591
700
|
* Mapping of tool name to allowed reviewer responses.
|
|
592
701
|
* If a tool doesn't have an entry, it's auto-approved by default.
|
|
593
702
|
*
|
|
594
|
-
* - `true` -> pause for approval and allow approve/edit/reject
|
|
703
|
+
* - `true` -> pause for approval and allow every decision (approve/edit/reject/respond)
|
|
595
704
|
* - `false` -> auto-approve (no human review)
|
|
596
705
|
* - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool
|
|
597
706
|
*/
|
|
598
|
-
interruptOn: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
|
|
707
|
+
interruptOn: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<[z$1.ZodBoolean, z$1.ZodObject<{
|
|
599
708
|
/**
|
|
600
709
|
* The decisions that are allowed for this action.
|
|
601
710
|
*/
|
|
602
|
-
allowedDecisions: z.ZodArray<z.ZodEnum<["approve", "edit", "reject"]>, "many">;
|
|
711
|
+
allowedDecisions: z$1.ZodArray<z$1.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
603
712
|
/**
|
|
604
713
|
* The description attached to the request for human input.
|
|
605
714
|
* Can be either:
|
|
@@ -643,11 +752,14 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
643
752
|
* };
|
|
644
753
|
* ```
|
|
645
754
|
*/
|
|
646
|
-
description: z.ZodOptional<z.ZodUnion<[z.ZodString, 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>]>>]>>;
|
|
755
|
+
description: z$1.ZodOptional<z$1.ZodUnion<[z$1.ZodString, z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCall<string, Record<string, any>>, z$1.ZodTypeDef, ToolCall<string, Record<string, any>>>, z$1.ZodType<AgentBuiltInState, z$1.ZodTypeDef, AgentBuiltInState>, z$1.ZodType<Runtime<unknown>, z$1.ZodTypeDef, Runtime<unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodString, z$1.ZodPromise<z$1.ZodString>]>>]>>;
|
|
647
756
|
/**
|
|
648
757
|
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
758
|
+
*
|
|
759
|
+
* Not used in `"per_call"` mode: an edit's `args` are checked against the tool's
|
|
760
|
+
* own schema there.
|
|
649
761
|
*/
|
|
650
|
-
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
762
|
+
argsSchema: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
651
763
|
/**
|
|
652
764
|
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
653
765
|
*
|
|
@@ -655,7 +767,9 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
655
767
|
* `false` to auto-approve the tool call.
|
|
656
768
|
*
|
|
657
769
|
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
658
|
-
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
770
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available. In
|
|
771
|
+
* `"per_call"` mode the predicate runs in `wrapToolCall` and receives the real
|
|
772
|
+
* request, with `tool` set.
|
|
659
773
|
*
|
|
660
774
|
* @example
|
|
661
775
|
* ```typescript
|
|
@@ -669,14 +783,14 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
669
783
|
* };
|
|
670
784
|
* ```
|
|
671
785
|
*/
|
|
672
|
-
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>]>>>;
|
|
673
|
-
}, "strip", z.ZodTypeAny, {
|
|
674
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
786
|
+
when: z$1.ZodOptional<z$1.ZodFunction<z$1.ZodTuple<[z$1.ZodType<ToolCallRequest<AgentBuiltInState, unknown>, z$1.ZodTypeDef, ToolCallRequest<AgentBuiltInState, unknown>>], z$1.ZodUnknown>, z$1.ZodUnion<[z$1.ZodBoolean, z$1.ZodPromise<z$1.ZodBoolean>]>>>;
|
|
787
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
788
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
675
789
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
676
790
|
argsSchema?: Record<string, any> | undefined;
|
|
677
791
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
678
792
|
}, {
|
|
679
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
793
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
680
794
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
681
795
|
argsSchema?: Record<string, any> | undefined;
|
|
682
796
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
@@ -689,10 +803,10 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
689
803
|
* `description` via their {@link InterruptOnConfig}. If a tool specifies a custom
|
|
690
804
|
* `description`, that per-tool text is used and this prefix is ignored.
|
|
691
805
|
*/
|
|
692
|
-
descriptionPrefix: z.ZodDefault<z.ZodString>;
|
|
693
|
-
}, "strip", z.ZodTypeAny, {
|
|
806
|
+
descriptionPrefix: z$1.ZodDefault<z$1.ZodString>;
|
|
807
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
694
808
|
interruptOn?: Record<string, boolean | {
|
|
695
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
809
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
696
810
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
697
811
|
argsSchema?: Record<string, any> | undefined;
|
|
698
812
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
@@ -700,7 +814,7 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
700
814
|
descriptionPrefix: string;
|
|
701
815
|
}, {
|
|
702
816
|
interruptOn?: Record<string, boolean | {
|
|
703
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
817
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
704
818
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
705
819
|
argsSchema?: Record<string, any> | undefined;
|
|
706
820
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
@@ -708,7 +822,7 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
708
822
|
descriptionPrefix?: string | undefined;
|
|
709
823
|
}>, {
|
|
710
824
|
interruptOn?: Record<string, boolean | {
|
|
711
|
-
allowedDecisions: ("approve" | "edit" | "reject")[];
|
|
825
|
+
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
712
826
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
713
827
|
argsSchema?: Record<string, any> | undefined;
|
|
714
828
|
when?: ((args_0: ToolCallRequest<AgentBuiltInState, unknown>, ...args: unknown[]) => boolean | Promise<boolean>) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl.d.ts","names":["_$__types_js0.AgentMiddleware"],"sources":["../../../src/agents/middleware/hitl.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hitl.d.ts","names":["z","z4","_$__types_js0.AgentMiddleware"],"sources":["../../../src/agents/middleware/hitl.ts"],"mappings":";;;;;;;;cAkBM,oBAAkBA,IAAA,YAAAA,IAAA,UAAAA,IAAA,QAAA,gBAAA,6BAAAA,IAAA,YAAA,gBAAA,+BAAAA,IAAA,aAAAA,IAAA,UAAAA,IAAA,YAAAA,IAAA,WAAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAiCZ,gBAAgBA,IAAE,aAAa;cAErC,2BAAyBA,IAAA,YAAAA,IAAA,UAAAA,IAAA,QAAA,iBAAA,sBAAAA,IAAA,YAAA,iBAAA,uBAAAA,IAAA,QAAA,mBAAAA,IAAA,YAAA,oBAAAA,IAAA,QAAA,kBAAAA,IAAA,YAAA,oBAAAA,IAAA,aAAAA,IAAA,UAAAA,IAAA,WAAAA,IAAA,WAAAA,IAAA;;;;;;;;;;;;;;;;;;YA0BnB,qBAAqBA,IAAE,aAAa;cAM1C,cAAYA,IAAA;KACN,eAAeA,IAAE,aAAa;cAEpC,yBAAuBA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAiFjB,oBAAoBA,IAAE,aAAa;;;;iBAK9B;;;;EAIf;;;;EAIA,MAAM;;;;;iBAMS;;;;EAIf;;;;EAIA,MAAM;;;;EAIN;;;;;iBAMe;;;;EAIf;;;;EAIA,kBAAkB;;;;EAIlB,aAAa;;;;;;;;;;;;;;;;;;;;;;iBAuBE;;;;EAIf,gBAAgB;;;;EAIhB,eAAe;;;;;iBAMA;EACf;;;;;iBAMe;EACf;;;;;EAKA,cAAc;;;;;iBAMC;EACf;;;;EAIA;;;;;iBAMe;EACf;;;;EAIA;;;;;YAMU,WACR,kBACA,eACA,iBACA;;;;iBAKa;;;;EAIf,WAAW;;cAGP,2BAAyBC,EAAA;;;;;;GAW7BA,EAAA,KAAA;;;;;YAMU,sBAAsBA,EAAG,aAAa;;;;;;cAyB5C,wBAAqB,cACb,OACL;EAEP,SAAOA,EAAA;;;EACP,MAAIA,EAAA;;;;;;;EAOJ,QAAMA,EAAA;;;;EAIN,SAAOA,EAAA;;;;;;;;YASG,uBAAuBA,EAAG,MACpC,kBAAkB,uBAAuB;;;;;wBAO3B,wBACd,WAAW,wBACV,aAAa,UAAU;cAwBpB,eAAaD,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAsBP,iCAAiC,4BACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BP;;;;;;EAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkTc,yBACd,SAAS,YAAY,6DAA+BA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6CAkdrD,6CAAA"}
|