langchain 1.5.17 → 1.5.19
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 +14 -0
- package/dist/agents/ReactAgent.cjs +8 -14
- 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 +8 -14
- package/dist/agents/ReactAgent.js.map +1 -1
- package/dist/agents/middleware/hitl.cjs +184 -14
- package/dist/agents/middleware/hitl.cjs.map +1 -1
- package/dist/agents/middleware/hitl.d.cts +113 -9
- package/dist/agents/middleware/hitl.d.cts.map +1 -1
- package/dist/agents/middleware/hitl.d.ts +145 -41
- package/dist/agents/middleware/hitl.d.ts.map +1 -1
- package/dist/agents/middleware/hitl.js +196 -27
- 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/middleware/todoListMiddleware.cjs +41 -183
- package/dist/agents/middleware/todoListMiddleware.cjs.map +1 -1
- package/dist/agents/middleware/todoListMiddleware.d.cts +1 -1
- package/dist/agents/middleware/todoListMiddleware.d.cts.map +1 -1
- package/dist/agents/middleware/todoListMiddleware.d.ts +1 -1
- package/dist/agents/middleware/todoListMiddleware.d.ts.map +1 -1
- package/dist/agents/middleware/todoListMiddleware.js +41 -183
- package/dist/agents/middleware/todoListMiddleware.js.map +1 -1
- package/dist/agents/nodes/ToolNode.cjs +14 -2
- package/dist/agents/nodes/ToolNode.cjs.map +1 -1
- package/dist/agents/nodes/ToolNode.js +14 -2
- package/dist/agents/nodes/ToolNode.js.map +1 -1
- 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", "respond"]>;
|
|
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", "respond"]>, "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,8 +136,8 @@ 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, {
|
|
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, {
|
|
129
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;
|
|
@@ -136,7 +148,7 @@ declare const InterruptOnConfigSchema: z.ZodObject<{
|
|
|
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
|
*/
|
|
@@ -264,20 +276,66 @@ export interface HITLResponse {
|
|
|
264
276
|
*/
|
|
265
277
|
decisions: Decision[];
|
|
266
278
|
}
|
|
267
|
-
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<{
|
|
268
326
|
/**
|
|
269
327
|
* Mapping of tool name to allowed reviewer responses.
|
|
270
328
|
* If a tool doesn't have an entry, it's auto-approved by default.
|
|
271
329
|
*
|
|
272
|
-
* - `true` -> pause for approval and allow approve/edit/reject
|
|
330
|
+
* - `true` -> pause for approval and allow every decision (approve/edit/reject/respond)
|
|
273
331
|
* - `false` -> auto-approve (no human review)
|
|
274
332
|
* - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool
|
|
275
333
|
*/
|
|
276
|
-
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<{
|
|
277
335
|
/**
|
|
278
336
|
* The decisions that are allowed for this action.
|
|
279
337
|
*/
|
|
280
|
-
allowedDecisions: z.ZodArray<z.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
338
|
+
allowedDecisions: z$1.ZodArray<z$1.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
281
339
|
/**
|
|
282
340
|
* The description attached to the request for human input.
|
|
283
341
|
* Can be either:
|
|
@@ -321,11 +379,14 @@ declare const contextSchema: z.ZodObject<{
|
|
|
321
379
|
* };
|
|
322
380
|
* ```
|
|
323
381
|
*/
|
|
324
|
-
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>]>>]>>;
|
|
325
383
|
/**
|
|
326
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.
|
|
327
388
|
*/
|
|
328
|
-
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
389
|
+
argsSchema: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
329
390
|
/**
|
|
330
391
|
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
331
392
|
*
|
|
@@ -333,7 +394,9 @@ declare const contextSchema: z.ZodObject<{
|
|
|
333
394
|
* `false` to auto-approve the tool call.
|
|
334
395
|
*
|
|
335
396
|
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
336
|
-
* 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.
|
|
337
400
|
*
|
|
338
401
|
* @example
|
|
339
402
|
* ```typescript
|
|
@@ -347,8 +410,8 @@ declare const contextSchema: z.ZodObject<{
|
|
|
347
410
|
* };
|
|
348
411
|
* ```
|
|
349
412
|
*/
|
|
350
|
-
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>]>>>;
|
|
351
|
-
}, "strip", z.ZodTypeAny, {
|
|
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, {
|
|
352
415
|
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
353
416
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
354
417
|
argsSchema?: Record<string, any> | undefined;
|
|
@@ -367,8 +430,8 @@ declare const contextSchema: z.ZodObject<{
|
|
|
367
430
|
* `description` via their {@link InterruptOnConfig}. If a tool specifies a custom
|
|
368
431
|
* `description`, that per-tool text is used and this prefix is ignored.
|
|
369
432
|
*/
|
|
370
|
-
descriptionPrefix: z.ZodDefault<z.ZodString>;
|
|
371
|
-
}, "strip", z.ZodTypeAny, {
|
|
433
|
+
descriptionPrefix: z$1.ZodDefault<z$1.ZodString>;
|
|
434
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
372
435
|
interruptOn?: Record<string, boolean | {
|
|
373
436
|
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
374
437
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
@@ -385,7 +448,42 @@ declare const contextSchema: z.ZodObject<{
|
|
|
385
448
|
}> | undefined;
|
|
386
449
|
descriptionPrefix?: string | undefined;
|
|
387
450
|
}>;
|
|
388
|
-
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
|
+
};
|
|
389
487
|
/**
|
|
390
488
|
* Creates a Human-in-the-Loop (HITL) middleware for tool approval and oversight.
|
|
391
489
|
*
|
|
@@ -588,28 +686,29 @@ export type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof context
|
|
|
588
686
|
* @remarks
|
|
589
687
|
* - Tool calls are processed in the order they appear in the AI message
|
|
590
688
|
* - Auto-approved tools execute immediately without interruption
|
|
591
|
-
* -
|
|
592
|
-
*
|
|
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`
|
|
593
692
|
* - Requires a checkpointer to maintain state across interruptions
|
|
594
693
|
*
|
|
595
694
|
* @see {@link createAgent} for agent creation
|
|
596
695
|
* @see {@link Command} for resuming interrupted execution
|
|
597
696
|
* @public
|
|
598
697
|
*/
|
|
599
|
-
export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMiddlewareConfig>): AgentMiddleware<undefined, z.ZodObject<{
|
|
698
|
+
export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMiddlewareConfig>): AgentMiddleware<undefined, z$1.ZodObject<{
|
|
600
699
|
/**
|
|
601
700
|
* Mapping of tool name to allowed reviewer responses.
|
|
602
701
|
* If a tool doesn't have an entry, it's auto-approved by default.
|
|
603
702
|
*
|
|
604
|
-
* - `true` -> pause for approval and allow approve/edit/reject
|
|
703
|
+
* - `true` -> pause for approval and allow every decision (approve/edit/reject/respond)
|
|
605
704
|
* - `false` -> auto-approve (no human review)
|
|
606
705
|
* - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool
|
|
607
706
|
*/
|
|
608
|
-
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<{
|
|
609
708
|
/**
|
|
610
709
|
* The decisions that are allowed for this action.
|
|
611
710
|
*/
|
|
612
|
-
allowedDecisions: z.ZodArray<z.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
711
|
+
allowedDecisions: z$1.ZodArray<z$1.ZodEnum<["approve", "edit", "reject", "respond"]>, "many">;
|
|
613
712
|
/**
|
|
614
713
|
* The description attached to the request for human input.
|
|
615
714
|
* Can be either:
|
|
@@ -653,11 +752,14 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
653
752
|
* };
|
|
654
753
|
* ```
|
|
655
754
|
*/
|
|
656
|
-
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>]>>]>>;
|
|
657
756
|
/**
|
|
658
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.
|
|
659
761
|
*/
|
|
660
|
-
argsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
762
|
+
argsSchema: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
661
763
|
/**
|
|
662
764
|
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
663
765
|
*
|
|
@@ -665,7 +767,9 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
665
767
|
* `false` to auto-approve the tool call.
|
|
666
768
|
*
|
|
667
769
|
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
668
|
-
* 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.
|
|
669
773
|
*
|
|
670
774
|
* @example
|
|
671
775
|
* ```typescript
|
|
@@ -679,8 +783,8 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
679
783
|
* };
|
|
680
784
|
* ```
|
|
681
785
|
*/
|
|
682
|
-
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>]>>>;
|
|
683
|
-
}, "strip", z.ZodTypeAny, {
|
|
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, {
|
|
684
788
|
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
685
789
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | undefined;
|
|
686
790
|
argsSchema?: Record<string, any> | undefined;
|
|
@@ -699,8 +803,8 @@ export declare function humanInTheLoopMiddleware(options: NonNullable<HumanInThe
|
|
|
699
803
|
* `description` via their {@link InterruptOnConfig}. If a tool specifies a custom
|
|
700
804
|
* `description`, that per-tool text is used and this prefix is ignored.
|
|
701
805
|
*/
|
|
702
|
-
descriptionPrefix: z.ZodDefault<z.ZodString>;
|
|
703
|
-
}, "strip", z.ZodTypeAny, {
|
|
806
|
+
descriptionPrefix: z$1.ZodDefault<z$1.ZodString>;
|
|
807
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
704
808
|
interruptOn?: Record<string, boolean | {
|
|
705
809
|
allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
|
|
706
810
|
description?: string | ((args_0: ToolCall<string, Record<string, any>>, args_1: AgentBuiltInState, args_2: Runtime<unknown>, ...args: unknown[]) => string | Promise<string>) | 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"}
|