langchain 1.0.0-alpha.6 → 1.0.0-alpha.7

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.
Files changed (185) hide show
  1. package/dist/agents/ReactAgent.cjs.map +1 -1
  2. package/dist/agents/ReactAgent.d.cts +1 -2
  3. package/dist/agents/ReactAgent.d.cts.map +1 -1
  4. package/dist/agents/ReactAgent.d.ts +1 -2
  5. package/dist/agents/ReactAgent.d.ts.map +1 -1
  6. package/dist/agents/ReactAgent.js.map +1 -1
  7. package/dist/agents/annotation.cjs.map +1 -1
  8. package/dist/agents/annotation.d.cts +12 -5
  9. package/dist/agents/annotation.d.cts.map +1 -1
  10. package/dist/agents/annotation.d.ts +12 -5
  11. package/dist/agents/annotation.d.ts.map +1 -1
  12. package/dist/agents/annotation.js.map +1 -1
  13. package/dist/agents/createAgent.cjs.map +1 -1
  14. package/dist/agents/createAgent.js.map +1 -1
  15. package/dist/agents/index.cjs.map +1 -1
  16. package/dist/agents/index.d.cts +3 -3
  17. package/dist/agents/index.d.cts.map +1 -1
  18. package/dist/agents/index.d.ts +3 -3
  19. package/dist/agents/index.d.ts.map +1 -1
  20. package/dist/agents/index.js.map +1 -1
  21. package/dist/agents/interrupt.d.cts +14 -1
  22. package/dist/agents/interrupt.d.cts.map +1 -1
  23. package/dist/agents/interrupt.d.ts +14 -1
  24. package/dist/agents/interrupt.d.ts.map +1 -1
  25. package/dist/agents/middlewareAgent/ReactAgent.cjs +262 -55
  26. package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -1
  27. package/dist/agents/middlewareAgent/ReactAgent.d.cts +97 -10
  28. package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -1
  29. package/dist/agents/middlewareAgent/ReactAgent.d.ts +97 -10
  30. package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -1
  31. package/dist/agents/middlewareAgent/ReactAgent.js +264 -57
  32. package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -1
  33. package/dist/agents/middlewareAgent/annotation.cjs +10 -4
  34. package/dist/agents/middlewareAgent/annotation.cjs.map +1 -1
  35. package/dist/agents/middlewareAgent/annotation.js +10 -4
  36. package/dist/agents/middlewareAgent/annotation.js.map +1 -1
  37. package/dist/agents/middlewareAgent/constants.d.cts +5 -0
  38. package/dist/agents/middlewareAgent/constants.d.cts.map +1 -0
  39. package/dist/agents/middlewareAgent/constants.d.ts +5 -0
  40. package/dist/agents/middlewareAgent/constants.d.ts.map +1 -0
  41. package/dist/agents/middlewareAgent/index.cjs.map +1 -1
  42. package/dist/agents/middlewareAgent/index.js.map +1 -1
  43. package/dist/agents/middlewareAgent/middleware/bigTool.cjs +162 -0
  44. package/dist/agents/middlewareAgent/middleware/bigTool.cjs.map +1 -0
  45. package/dist/agents/middlewareAgent/middleware/bigTool.d.cts +113 -0
  46. package/dist/agents/middlewareAgent/middleware/bigTool.d.cts.map +1 -0
  47. package/dist/agents/middlewareAgent/middleware/bigTool.d.ts +113 -0
  48. package/dist/agents/middlewareAgent/middleware/bigTool.d.ts.map +1 -0
  49. package/dist/agents/middlewareAgent/middleware/bigTool.js +161 -0
  50. package/dist/agents/middlewareAgent/middleware/bigTool.js.map +1 -0
  51. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.cjs +58 -0
  52. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.cjs.map +1 -0
  53. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.cts +46 -0
  54. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.cts.map +1 -0
  55. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.ts +46 -0
  56. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.ts.map +1 -0
  57. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.js +58 -0
  58. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.js.map +1 -0
  59. package/dist/agents/middlewareAgent/middleware/hitl.cjs +160 -84
  60. package/dist/agents/middlewareAgent/middleware/hitl.cjs.map +1 -1
  61. package/dist/agents/middlewareAgent/middleware/hitl.d.cts +271 -51
  62. package/dist/agents/middlewareAgent/middleware/hitl.d.cts.map +1 -1
  63. package/dist/agents/middlewareAgent/middleware/hitl.d.ts +271 -51
  64. package/dist/agents/middlewareAgent/middleware/hitl.d.ts.map +1 -1
  65. package/dist/agents/middlewareAgent/middleware/hitl.js +161 -85
  66. package/dist/agents/middlewareAgent/middleware/hitl.js.map +1 -1
  67. package/dist/agents/middlewareAgent/middleware/index.cjs +6 -0
  68. package/dist/agents/middlewareAgent/middleware/index.cjs.map +1 -1
  69. package/dist/agents/middlewareAgent/middleware/index.d.cts +6 -4
  70. package/dist/agents/middlewareAgent/middleware/index.d.ts +6 -4
  71. package/dist/agents/middlewareAgent/middleware/index.js +5 -1
  72. package/dist/agents/middlewareAgent/middleware/index.js.map +1 -1
  73. package/dist/agents/middlewareAgent/middleware/promptCaching.cjs +24 -8
  74. package/dist/agents/middlewareAgent/middleware/promptCaching.cjs.map +1 -1
  75. package/dist/agents/middlewareAgent/middleware/promptCaching.d.cts +51 -6
  76. package/dist/agents/middlewareAgent/middleware/promptCaching.d.cts.map +1 -1
  77. package/dist/agents/middlewareAgent/middleware/promptCaching.d.ts +51 -6
  78. package/dist/agents/middlewareAgent/middleware/promptCaching.d.ts.map +1 -1
  79. package/dist/agents/middlewareAgent/middleware/promptCaching.js +24 -8
  80. package/dist/agents/middlewareAgent/middleware/promptCaching.js.map +1 -1
  81. package/dist/agents/middlewareAgent/middleware/summarization.cjs +24 -12
  82. package/dist/agents/middlewareAgent/middleware/summarization.cjs.map +1 -1
  83. package/dist/agents/middlewareAgent/middleware/summarization.d.cts +5 -3
  84. package/dist/agents/middlewareAgent/middleware/summarization.d.cts.map +1 -1
  85. package/dist/agents/middlewareAgent/middleware/summarization.d.ts +11 -9
  86. package/dist/agents/middlewareAgent/middleware/summarization.d.ts.map +1 -1
  87. package/dist/agents/middlewareAgent/middleware/summarization.js +25 -13
  88. package/dist/agents/middlewareAgent/middleware/summarization.js.map +1 -1
  89. package/dist/agents/middlewareAgent/middleware.cjs +8 -5
  90. package/dist/agents/middlewareAgent/middleware.cjs.map +1 -1
  91. package/dist/agents/middlewareAgent/middleware.d.cts +67 -7
  92. package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -1
  93. package/dist/agents/middlewareAgent/middleware.d.ts +67 -7
  94. package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -1
  95. package/dist/agents/middlewareAgent/middleware.js +8 -5
  96. package/dist/agents/middlewareAgent/middleware.js.map +1 -1
  97. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs +2 -2
  98. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -1
  99. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js +2 -2
  100. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -1
  101. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +117 -68
  102. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -1
  103. package/dist/agents/middlewareAgent/nodes/AgentNode.js +121 -72
  104. package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -1
  105. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs +2 -2
  106. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -1
  107. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js +2 -2
  108. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -1
  109. package/dist/agents/middlewareAgent/nodes/middleware.cjs +42 -17
  110. package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -1
  111. package/dist/agents/middlewareAgent/nodes/middleware.js +42 -18
  112. package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -1
  113. package/dist/agents/middlewareAgent/nodes/utils.cjs +25 -11
  114. package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -1
  115. package/dist/agents/middlewareAgent/nodes/utils.js +26 -12
  116. package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -1
  117. package/dist/agents/middlewareAgent/types.d.cts +153 -66
  118. package/dist/agents/middlewareAgent/types.d.cts.map +1 -1
  119. package/dist/agents/middlewareAgent/types.d.ts +153 -66
  120. package/dist/agents/middlewareAgent/types.d.ts.map +1 -1
  121. package/dist/agents/model.cjs +13 -0
  122. package/dist/agents/model.cjs.map +1 -0
  123. package/dist/agents/model.js +11 -0
  124. package/dist/agents/model.js.map +1 -0
  125. package/dist/agents/nodes/AgentNode.cjs +56 -28
  126. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  127. package/dist/agents/nodes/AgentNode.js +57 -29
  128. package/dist/agents/nodes/AgentNode.js.map +1 -1
  129. package/dist/agents/nodes/ToolNode.cjs +1 -1
  130. package/dist/agents/nodes/ToolNode.cjs.map +1 -1
  131. package/dist/agents/nodes/ToolNode.d.cts +1 -1
  132. package/dist/agents/nodes/ToolNode.js +1 -1
  133. package/dist/agents/nodes/ToolNode.js.map +1 -1
  134. package/dist/agents/responses.cjs +52 -10
  135. package/dist/agents/responses.cjs.map +1 -1
  136. package/dist/agents/responses.d.cts +12 -20
  137. package/dist/agents/responses.d.cts.map +1 -1
  138. package/dist/agents/responses.d.ts +12 -20
  139. package/dist/agents/responses.d.ts.map +1 -1
  140. package/dist/agents/responses.js +52 -11
  141. package/dist/agents/responses.js.map +1 -1
  142. package/dist/agents/types.d.cts +2 -3
  143. package/dist/agents/types.d.cts.map +1 -1
  144. package/dist/agents/types.d.ts +2 -3
  145. package/dist/agents/types.d.ts.map +1 -1
  146. package/dist/agents/utils.cjs +5 -23
  147. package/dist/agents/utils.cjs.map +1 -1
  148. package/dist/agents/utils.js +2 -19
  149. package/dist/agents/utils.js.map +1 -1
  150. package/dist/chains/query_constructor/index.d.cts +1 -1
  151. package/dist/chains/summarization/load.d.ts +2 -2
  152. package/dist/chains/summarization/load.d.ts.map +1 -1
  153. package/dist/embeddings/cache_backed.d.ts +1 -1
  154. package/dist/evaluation/comparison/pairwise.d.cts.map +1 -1
  155. package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
  156. package/dist/evaluation/criteria/criteria.d.cts.map +1 -1
  157. package/dist/evaluation/criteria/criteria.d.ts.map +1 -1
  158. package/dist/index.cjs +38 -6
  159. package/dist/index.cjs.map +1 -1
  160. package/dist/index.d.cts +11 -4
  161. package/dist/index.d.ts +11 -4
  162. package/dist/index.js +18 -4
  163. package/dist/index.js.map +1 -1
  164. package/dist/langchain-core/dist/messages/base.d.cts.map +1 -1
  165. package/dist/langchain-core/dist/messages/content/index.d.cts +20 -1
  166. package/dist/langchain-core/dist/messages/content/index.d.cts.map +1 -1
  167. package/dist/langchain-core/dist/messages/content/tools.d.cts +67 -6
  168. package/dist/langchain-core/dist/messages/content/tools.d.cts.map +1 -1
  169. package/dist/langchain-core/dist/messages/message.d.cts +6 -6
  170. package/dist/langchain-core/dist/messages/message.d.cts.map +1 -1
  171. package/dist/langchain-core/dist/utils/types/index.d.cts.map +1 -1
  172. package/dist/libs/langchain-core/dist/messages/base.d.ts.map +1 -1
  173. package/dist/libs/langchain-core/dist/messages/content/index.d.ts +20 -1
  174. package/dist/libs/langchain-core/dist/messages/content/index.d.ts.map +1 -1
  175. package/dist/libs/langchain-core/dist/messages/content/tools.d.ts +67 -6
  176. package/dist/libs/langchain-core/dist/messages/content/tools.d.ts.map +1 -1
  177. package/dist/libs/langchain-core/dist/messages/message.d.ts +6 -6
  178. package/dist/libs/langchain-core/dist/messages/message.d.ts.map +1 -1
  179. package/dist/libs/langchain-core/dist/utils/types/index.d.ts.map +1 -1
  180. package/dist/load/import_map.cjs +1 -1
  181. package/dist/load/import_map.js +1 -1
  182. package/dist/output_parsers/structured.d.cts +1 -1
  183. package/dist/tools/fs.d.cts +1 -1
  184. package/dist/tools/retriever.d.cts +1 -1
  185. package/package.json +7 -7
@@ -1,32 +1,179 @@
1
1
  import { AgentMiddleware } from "../types.cjs";
2
+ import { InferInteropZodInput } from "@langchain/core/utils/types";
2
3
  import { z } from "zod/v3";
3
4
 
4
5
  //#region src/agents/middlewareAgent/middleware/hitl.d.ts
6
+ declare const ToolConfigSchema: z.ZodObject<{
7
+ /**
8
+ * Whether the human can approve the current action without changes
9
+ */
10
+ allowAccept: z.ZodOptional<z.ZodBoolean>;
11
+ /**
12
+ * Whether the human can reject the current action with feedback
13
+ */
14
+ allowEdit: z.ZodOptional<z.ZodBoolean>;
15
+ /**
16
+ * Whether the human can approve the current action with edited content
17
+ */
18
+ allowRespond: z.ZodOptional<z.ZodBoolean>;
19
+ /**
20
+ * The description attached to the request for human input
21
+ */
22
+ description: z.ZodOptional<z.ZodString>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ allowAccept?: boolean | undefined;
25
+ allowEdit?: boolean | undefined;
26
+ allowRespond?: boolean | undefined;
27
+ description?: string | undefined;
28
+ }, {
29
+ allowAccept?: boolean | undefined;
30
+ allowEdit?: boolean | undefined;
31
+ allowRespond?: boolean | undefined;
32
+ description?: string | undefined;
33
+ }>;
34
+ type ToolConfigSchema = z.input<typeof ToolConfigSchema>;
35
+ /**
36
+ * Represents information about an interrupt.
37
+ */
38
+
39
+ /**
40
+ * Configuration that defines which reviewer response types are permitted during a human interrupt.
41
+ * These flags control what the human reviewer may do (e.g., accept/edit/respond),
42
+ * not the tool action the agent has requested.
43
+ */
44
+ interface HumanInTheLoopConfig extends Omit<ToolConfigSchema, "description"> {}
45
+ /**
46
+ * Describes the agent-requested tool action (name and arguments).
47
+ * This is what the AI intends to execute, subject to human review.
48
+ */
49
+ interface ActionRequest {
50
+ /**
51
+ * The tool/action name requested by the agent (e.g., "send_email").
52
+ */
53
+ action: string;
54
+ /**
55
+ * Arguments for the requested tool call (e.g., {"a": 1, "b": 2}).
56
+ */
57
+ args: Record<string, any>;
58
+ }
59
+ /**
60
+ * Represents an interrupt triggered by the graph that requires human intervention
61
+ * to approve, edit, or respond to an agent-requested tool action.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const hitlRequest: HumanInTheLoopRequest = {
66
+ * actionRequest: { action: "Approve XYZ action", args: { ... } },
67
+ * config: { allowAccept: true, allowEdit: true, allowRespond: true },
68
+ * description: "Please review the command before execution"
69
+ * };
70
+ * response = interrupt([request])[0]
71
+ * ```
72
+ */
73
+ interface HumanInTheLoopRequest {
74
+ /**
75
+ * The agent-requested tool action to be reviewed.
76
+ */
77
+ actionRequest: ActionRequest;
78
+ /**
79
+ * Which reviewer responses are allowed (accept/edit/respond).
80
+ */
81
+ config: HumanInTheLoopConfig;
82
+ /**
83
+ * Optional human-facing description shown in the approval prompt.
84
+ */
85
+ description?: string;
86
+ }
87
+ /**
88
+ * Response when a human approves the agent-requested action.
89
+ */
90
+ interface AcceptPayload {
91
+ type: "accept";
92
+ }
93
+ /**
94
+ * Response when a human provides a manual response instead of executing
95
+ * the agent-requested action.
96
+ */
97
+ interface ResponsePayload {
98
+ type: "response";
99
+ args?: string;
100
+ }
101
+ /**
102
+ * Response when a human edits the agent-requested action (tool name and/or args).
103
+ */
104
+ interface EditPayload {
105
+ type: "edit";
106
+ args: ActionRequest;
107
+ }
108
+ type HumanInTheLoopMiddlewareHumanResponse = AcceptPayload | ResponsePayload | EditPayload;
109
+ /**
110
+ * Configuration for a tool requiring human in the loop.
111
+ */
112
+
5
113
  declare const contextSchema: z.ZodObject<{
6
- toolConfigs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
7
- requireApproval: z.ZodOptional<z.ZodBoolean>;
114
+ /**
115
+ * Mapping of tool name to allowed reviewer responses.
116
+ * If a tool doesn't have an entry, it's auto-approved by default.
117
+ *
118
+ * - `true` -> pause for approval and allow accept/edit/respond
119
+ * - `false` -> auto-approve (no human review)
120
+ * - `ToolConfig` -> explicitly specify which reviewer responses are allowed for this tool
121
+ */
122
+ interruptOn: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
123
+ /**
124
+ * Whether the human can approve the current action without changes
125
+ */
126
+ allowAccept: z.ZodOptional<z.ZodBoolean>;
127
+ /**
128
+ * Whether the human can reject the current action with feedback
129
+ */
130
+ allowEdit: z.ZodOptional<z.ZodBoolean>;
131
+ /**
132
+ * Whether the human can approve the current action with edited content
133
+ */
134
+ allowRespond: z.ZodOptional<z.ZodBoolean>;
135
+ /**
136
+ * The description attached to the request for human input
137
+ */
8
138
  description: z.ZodOptional<z.ZodString>;
9
139
  }, "strip", z.ZodTypeAny, {
10
- requireApproval?: boolean | undefined;
140
+ allowAccept?: boolean | undefined;
141
+ allowEdit?: boolean | undefined;
142
+ allowRespond?: boolean | undefined;
11
143
  description?: string | undefined;
12
144
  }, {
13
- requireApproval?: boolean | undefined;
145
+ allowAccept?: boolean | undefined;
146
+ allowEdit?: boolean | undefined;
147
+ allowRespond?: boolean | undefined;
14
148
  description?: string | undefined;
15
- }>>>;
16
- messagePrefix: z.ZodDefault<z.ZodString>;
149
+ }>]>>>;
150
+ /**
151
+ * Prefix used when constructing human-facing approval messages.
152
+ * Provides context about the tool call being reviewed; does not change the underlying action.
153
+ *
154
+ * Note: This prefix is only applied for tools that do not provide a custom
155
+ * `description` via their {@link ToolConfig}. If a tool specifies a custom
156
+ * `description`, that per-tool text is used and this prefix is ignored.
157
+ */
158
+ descriptionPrefix: z.ZodDefault<z.ZodString>;
17
159
  }, "strip", z.ZodTypeAny, {
18
- toolConfigs: Record<string, {
19
- requireApproval?: boolean | undefined;
160
+ interruptOn?: Record<string, boolean | {
161
+ allowAccept?: boolean | undefined;
162
+ allowEdit?: boolean | undefined;
163
+ allowRespond?: boolean | undefined;
20
164
  description?: string | undefined;
21
- }>;
22
- messagePrefix: string;
165
+ }> | undefined;
166
+ descriptionPrefix: string;
23
167
  }, {
24
- toolConfigs?: Record<string, {
25
- requireApproval?: boolean | undefined;
168
+ interruptOn?: Record<string, boolean | {
169
+ allowAccept?: boolean | undefined;
170
+ allowEdit?: boolean | undefined;
171
+ allowRespond?: boolean | undefined;
26
172
  description?: string | undefined;
27
173
  }> | undefined;
28
- messagePrefix?: string | undefined;
174
+ descriptionPrefix?: string | undefined;
29
175
  }>;
176
+ type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof contextSchema>;
30
177
  /**
31
178
  * Creates a Human-in-the-Loop (HITL) middleware for tool approval and oversight.
32
179
  *
@@ -34,6 +181,37 @@ declare const contextSchema: z.ZodObject<{
34
181
  * capabilities before execution. It enables selective approval workflows where certain tools
35
182
  * require human intervention while others can execute automatically.
36
183
  *
184
+ * A invocation result that has been interrupted by the middleware will have a `__interrupt__`
185
+ * property that contains the interrupt request. You can loop over the request to determine
186
+ * which tools were interrupted, and how to handle them separately.
187
+ *
188
+ * ```ts
189
+ * import { type ToolApprovalRequest, type HumanInTheLoopMiddlewareHumanResponse } from "langchain/middleware";
190
+ * import { type Interrupt } from "langchain";
191
+ *
192
+ * const result = await agent.invoke(request);
193
+ * const interruptRequest = initialResult.__interrupt__?.[0] as Interrupt<
194
+ * ToolApprovalRequest[]
195
+ * >;
196
+ * const resume: HumanInTheLoopMiddlewareHumanResponse[] =
197
+ * interruptRequest.value.map((request) => {
198
+ * if (request.action === "calculator") {
199
+ * return { id: request.toolCallId, type: "accept" };
200
+ * } else if (request.action === "write_file") {
201
+ * return {
202
+ * id: request.toolCallId,
203
+ * type: "edit",
204
+ * args: { filename: "safe.txt", content: "Safe content" },
205
+ * };
206
+ * }
207
+ *
208
+ * throw new Error(`Unknown action: ${request.action}`);
209
+ * });
210
+ *
211
+ * // Resume with approval
212
+ * await agent.invoke(new Command({ resume }), config);
213
+ * ```
214
+ *
37
215
  * ## Features
38
216
  *
39
217
  * - **Selective Tool Approval**: Configure which tools require human approval
@@ -50,10 +228,12 @@ declare const contextSchema: z.ZodObject<{
50
228
  * - `response`: Provide a manual response instead of executing the tool
51
229
  *
52
230
  * @param options - Configuration options for the middleware
53
- * @param options.toolConfigs - Per-tool configuration mapping tool names to their settings
54
- * @param options.toolConfigs[toolName].requireApproval - Whether the tool requires human approval
55
- * @param options.toolConfigs[toolName].description - Custom approval message for the tool
56
- * @param options.messagePrefix - Default prefix for approval messages (default: "Tool execution requires approval")
231
+ * @param options.interruptOn - Per-tool configuration mapping tool names to their settings
232
+ * @param options.interruptOn[toolName].allowAccept - Whether the human can approve the current action without changes
233
+ * @param options.interruptOn[toolName].allowEdit - Whether the human can reject the current action with feedback
234
+ * @param options.interruptOn[toolName].allowRespond - Whether the human can approve the current action with edited content
235
+ * @param options.interruptOn[toolName].description - Custom approval message for the tool
236
+ * @param options.messagePrefix - Default prefix for approval messages (default: "Tool execution requires approval"). Only used for tools that do not define a custom `description` in their ToolConfig.
57
237
  *
58
238
  * @returns A middleware instance that can be passed to `createAgent`
59
239
  *
@@ -64,14 +244,15 @@ declare const contextSchema: z.ZodObject<{
64
244
  * import { createAgent } from "langchain";
65
245
  *
66
246
  * const hitlMiddleware = humanInTheLoopMiddleware({
67
- * toolConfigs: {
247
+ * interruptOn: {
248
+ * // Interrupt write_file tool and allow edits or accepts
68
249
  * "write_file": {
69
- * requireApproval: true,
250
+ * allowEdit: true,
251
+ * allowAccept: true,
70
252
  * description: "⚠️ File write operation requires approval"
71
253
  * },
72
- * "read_file": {
73
- * requireApproval: false // Safe operation, no approval needed
74
- * }
254
+ * // Auto-approve read_file tool
255
+ * "read_file": false
75
256
  * }
76
257
  * });
77
258
  *
@@ -85,6 +266,7 @@ declare const contextSchema: z.ZodObject<{
85
266
  * @example
86
267
  * Handling approval requests
87
268
  * ```typescript
269
+ * import { type HumanInTheLoopRequest, type Interrupt } from "langchain/middleware";
88
270
  * import { Command } from "@langchain/langgraph";
89
271
  *
90
272
  * // Initial agent invocation
@@ -93,15 +275,14 @@ declare const contextSchema: z.ZodObject<{
93
275
  * }, config);
94
276
  *
95
277
  * // Check if agent is paused for approval
96
- * const state = await agent.graph.getState(config);
97
- * if (state.next?.length > 0) {
98
- * // Get interrupt details
99
- * const task = state.tasks?.[0];
100
- * const requests = task?.interrupts?.[0]?.value;
278
+ * if (result.__interrupt__) {
279
+ * const interruptRequest = initialResult.__interrupt__?.[0] as Interrupt<
280
+ * HumanInTheLoopRequest[]
281
+ * >;
101
282
  *
102
283
  * // Show tool call details to user
103
- * console.log("Tool:", requests[0].action);
104
- * console.log("Args:", requests[0].args);
284
+ * console.log("Tool:", interruptRequest.value[0].actionRequest);
285
+ * console.log("Allowed actions:", interruptRequest.value[0].config);
105
286
  *
106
287
  * // Resume with approval
107
288
  * await agent.invoke(
@@ -126,12 +307,13 @@ declare const contextSchema: z.ZodObject<{
126
307
  * })
127
308
  *
128
309
  * // Skip tool and terminate agent
129
- * new Command({ resume: [{ type: "ignore" }] })
310
+ * new Command({ resume: [{ type: "response" }] })
130
311
  *
131
312
  * // Provide manual response
132
313
  * new Command({
133
314
  * resume: [{
134
315
  * type: "response",
316
+ * // this must be a string
135
317
  * args: "File operation not allowed in demo mode"
136
318
  * }]
137
319
  * })
@@ -141,16 +323,16 @@ declare const contextSchema: z.ZodObject<{
141
323
  * Production use case with database operations
142
324
  * ```typescript
143
325
  * const hitlMiddleware = humanInTheLoopMiddleware({
144
- * toolConfigs: {
326
+ * interruptOn: {
145
327
  * "execute_sql": {
146
- * requireApproval: true,
328
+ * allowAccept: true,
329
+ * allowEdit: true,
330
+ * allowRespond: true,
147
331
  * description: "🚨 SQL query requires DBA approval\nPlease review for safety and performance"
148
332
  * },
149
- * "read_schema": {
150
- * requireApproval: false // Reading metadata is safe
151
- * },
333
+ * "read_schema": false // Reading metadata is safe
152
334
  * "delete_records": {
153
- * requireApproval: true,
335
+ * allowAccept: true,
154
336
  * description: "⛔ DESTRUCTIVE OPERATION - Requires manager approval"
155
337
  * }
156
338
  * },
@@ -169,31 +351,69 @@ declare const contextSchema: z.ZodObject<{
169
351
  * @see {@link Command} for resuming interrupted execution
170
352
  * @public
171
353
  */
172
- declare function humanInTheLoopMiddleware(options?: z.input<typeof contextSchema>): AgentMiddleware<undefined, z.ZodObject<{
173
- toolConfigs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
174
- requireApproval: z.ZodOptional<z.ZodBoolean>;
354
+ declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMiddlewareConfig>): AgentMiddleware<undefined, z.ZodObject<{
355
+ /**
356
+ * Mapping of tool name to allowed reviewer responses.
357
+ * If a tool doesn't have an entry, it's auto-approved by default.
358
+ *
359
+ * - `true` -> pause for approval and allow accept/edit/respond
360
+ * - `false` -> auto-approve (no human review)
361
+ * - `ToolConfig` -> explicitly specify which reviewer responses are allowed for this tool
362
+ */
363
+ interruptOn: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
364
+ /**
365
+ * Whether the human can approve the current action without changes
366
+ */
367
+ allowAccept: z.ZodOptional<z.ZodBoolean>;
368
+ /**
369
+ * Whether the human can reject the current action with feedback
370
+ */
371
+ allowEdit: z.ZodOptional<z.ZodBoolean>;
372
+ /**
373
+ * Whether the human can approve the current action with edited content
374
+ */
375
+ allowRespond: z.ZodOptional<z.ZodBoolean>;
376
+ /**
377
+ * The description attached to the request for human input
378
+ */
175
379
  description: z.ZodOptional<z.ZodString>;
176
380
  }, "strip", z.ZodTypeAny, {
177
- requireApproval?: boolean | undefined;
381
+ allowAccept?: boolean | undefined;
382
+ allowEdit?: boolean | undefined;
383
+ allowRespond?: boolean | undefined;
178
384
  description?: string | undefined;
179
385
  }, {
180
- requireApproval?: boolean | undefined;
386
+ allowAccept?: boolean | undefined;
387
+ allowEdit?: boolean | undefined;
388
+ allowRespond?: boolean | undefined;
181
389
  description?: string | undefined;
182
- }>>>;
183
- messagePrefix: z.ZodDefault<z.ZodString>;
390
+ }>]>>>;
391
+ /**
392
+ * Prefix used when constructing human-facing approval messages.
393
+ * Provides context about the tool call being reviewed; does not change the underlying action.
394
+ *
395
+ * Note: This prefix is only applied for tools that do not provide a custom
396
+ * `description` via their {@link ToolConfig}. If a tool specifies a custom
397
+ * `description`, that per-tool text is used and this prefix is ignored.
398
+ */
399
+ descriptionPrefix: z.ZodDefault<z.ZodString>;
184
400
  }, "strip", z.ZodTypeAny, {
185
- toolConfigs: Record<string, {
186
- requireApproval?: boolean | undefined;
401
+ interruptOn?: Record<string, boolean | {
402
+ allowAccept?: boolean | undefined;
403
+ allowEdit?: boolean | undefined;
404
+ allowRespond?: boolean | undefined;
187
405
  description?: string | undefined;
188
- }>;
189
- messagePrefix: string;
406
+ }> | undefined;
407
+ descriptionPrefix: string;
190
408
  }, {
191
- toolConfigs?: Record<string, {
192
- requireApproval?: boolean | undefined;
409
+ interruptOn?: Record<string, boolean | {
410
+ allowAccept?: boolean | undefined;
411
+ allowEdit?: boolean | undefined;
412
+ allowRespond?: boolean | undefined;
193
413
  description?: string | undefined;
194
414
  }> | undefined;
195
- messagePrefix?: string | undefined;
415
+ descriptionPrefix?: string | undefined;
196
416
  }>, any>;
197
417
  //#endregion
198
- export { humanInTheLoopMiddleware };
418
+ export { ActionRequest, HumanInTheLoopMiddlewareConfig, HumanInTheLoopMiddlewareHumanResponse, HumanInTheLoopRequest, humanInTheLoopMiddleware };
199
419
  //# sourceMappingURL=hitl.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hitl.d.cts","names":["z","contextSchema","ZodString","ZodBoolean","ZodOptional","ZodTypeAny","ZodObject","ZodRecord","ZodDefault","Record","humanInTheLoopMiddleware","input","___types_js0","AgentMiddleware"],"sources":["../../../../src/agents/middlewareAgent/middleware/hitl.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v3\";\ndeclare const contextSchema: z.ZodObject<{\n toolConfigs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{\n requireApproval: z.ZodOptional<z.ZodBoolean>;\n description: z.ZodOptional<z.ZodString>;\n }, \"strip\", z.ZodTypeAny, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }>>>;\n messagePrefix: z.ZodDefault<z.ZodString>;\n}, \"strip\", z.ZodTypeAny, {\n toolConfigs: Record<string, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }>;\n messagePrefix: string;\n}, {\n toolConfigs?: Record<string, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }> | undefined;\n messagePrefix?: string | undefined;\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 * ## Features\n *\n * - **Selective Tool Approval**: Configure which tools require human approval\n * - **Multiple Response Types**: Accept, edit, ignore, or manually respond to 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 * ## Response Types\n *\n * When a tool requires approval, the human operator can respond with:\n * - `accept`: Execute the tool with original arguments\n * - `edit`: Modify the tool arguments before execution\n * - `ignore`: Skip the tool and terminate the agent\n * - `response`: Provide a manual response instead of executing the tool\n *\n * @param options - Configuration options for the middleware\n * @param options.toolConfigs - Per-tool configuration mapping tool names to their settings\n * @param options.toolConfigs[toolName].requireApproval - Whether the tool requires human approval\n * @param options.toolConfigs[toolName].description - Custom approval message for the tool\n * @param options.messagePrefix - Default prefix for approval messages (default: \"Tool execution requires approval\")\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/middleware\";\n * import { createAgent } from \"langchain\";\n *\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * toolConfigs: {\n * \"write_file\": {\n * requireApproval: true,\n * description: \"⚠️ File write operation requires approval\"\n * },\n * \"read_file\": {\n * requireApproval: false // Safe operation, no approval needed\n * }\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 { 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 * const state = await agent.graph.getState(config);\n * if (state.next?.length > 0) {\n * // Get interrupt details\n * const task = state.tasks?.[0];\n * const requests = task?.interrupts?.[0]?.value;\n *\n * // Show tool call details to user\n * console.log(\"Tool:\", requests[0].action);\n * console.log(\"Args:\", requests[0].args);\n *\n * // Resume with approval\n * await agent.invoke(\n * new Command({ resume: [{ type: \"accept\" }] }),\n * config\n * );\n * }\n * ```\n *\n * @example\n * Different response types\n * ```typescript\n * // Accept the tool call as-is\n * new Command({ resume: [{ type: \"accept\" }] })\n *\n * // Edit the tool arguments\n * new Command({\n * resume: [{\n * type: \"edit\",\n * args: { action: \"write_file\", args: { filename: \"safe.txt\", content: \"Modified\" } }\n * }]\n * })\n *\n * // Skip tool and terminate agent\n * new Command({ resume: [{ type: \"ignore\" }] })\n *\n * // Provide manual response\n * new Command({\n * resume: [{\n * type: \"response\",\n * args: \"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 * toolConfigs: {\n * \"execute_sql\": {\n * requireApproval: true,\n * description: \"🚨 SQL query requires DBA approval\\nPlease review for safety and performance\"\n * },\n * \"read_schema\": {\n * requireApproval: false // Reading metadata is safe\n * },\n * \"delete_records\": {\n * requireApproval: true,\n * description: \"⛔ DESTRUCTIVE OPERATION - Requires manager approval\"\n * }\n * },\n * messagePrefix: \"Database operation pending approval\"\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\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 declare function humanInTheLoopMiddleware(options?: z.input<typeof contextSchema>): import(\"../types.js\").AgentMiddleware<undefined, z.ZodObject<{\n toolConfigs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{\n requireApproval: z.ZodOptional<z.ZodBoolean>;\n description: z.ZodOptional<z.ZodString>;\n }, \"strip\", z.ZodTypeAny, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }>>>;\n messagePrefix: z.ZodDefault<z.ZodString>;\n}, \"strip\", z.ZodTypeAny, {\n toolConfigs: Record<string, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }>;\n messagePrefix: string;\n}, {\n toolConfigs?: Record<string, {\n requireApproval?: boolean | undefined;\n description?: string | undefined;\n }> | undefined;\n messagePrefix?: string | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;cAEcC,eAAeD,CAAAA,CAAEM;eACdN,CAAAA,CAAEQ,WAAWR,CAAAA,CAAEO,UAAUP,CAAAA,CAAEE,WAAWF,CAAAA,CAAEM;IAD3CL,eAwBZ,EAtBuBD,CAAAA,CAAEI,WAsBzB,CAtBqCJ,CAAAA,CAAEG,UAsBvC,CAAA;IAAA,WAAA,EArBmBH,CAAAA,CAAEI,WAqBrB,CArBiCJ,CAAAA,CAAEE,SAqBnC,CAAA;EAAA,CAAA,EAvBwCF,OAAEE,EAG5BF,CAAAA,CAAEK,UAH0BH,EAAAA;IACLF,eAAEG,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;IAAhBH,WAAEI,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAW,CAAA,EACHJ;IAAdA,eAAEI,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;IACPJ,WAAEK,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAU,CAAA,CAAA,CAH2BL,CAAAA;EAAW,aAAlCO,EAUbP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rupt","TValue","HumanInTheLoopConfig","Omit","ActionRequest","Record","HumanInTheLoopRequest","AcceptPayload","ResponsePayload","EditPayload","HumanInTheLoopMiddlewareHumanResponse","ToolConfig","contextSchema","ZodUnion","ZodRecord","ZodDefault","HumanInTheLoopMiddlewareConfig","humanInTheLoopMiddleware","NonNullable","___types_js0","AgentMiddleware"],"sources":["../../../../src/agents/middlewareAgent/middleware/hitl.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v3\";\nimport { InferInteropZodInput } from \"@langchain/core/utils/types\";\ndeclare const ToolConfigSchema: z.ZodObject<{\n /**\n * Whether the human can approve the current action without changes\n */\n allowAccept: z.ZodOptional<z.ZodBoolean>;\n /**\n * Whether the human can reject the current action with feedback\n */\n allowEdit: z.ZodOptional<z.ZodBoolean>;\n /**\n * Whether the human can approve the current action with edited content\n */\n allowRespond: z.ZodOptional<z.ZodBoolean>;\n /**\n * The description attached to the request for human input\n */\n description: z.ZodOptional<z.ZodString>;\n}, \"strip\", z.ZodTypeAny, {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n}, {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n}>;\ntype ToolConfigSchema = z.input<typeof ToolConfigSchema>;\n/**\n * Represents information about an interrupt.\n */\nexport interface Interrupt<TValue = unknown> {\n /**\n * The ID of the interrupt.\n */\n id: string;\n /**\n * The requests for human input.\n */\n value: TValue;\n}\n/**\n * Configuration that defines which reviewer response types are permitted during a human interrupt.\n * These flags control what the human reviewer may do (e.g., accept/edit/respond),\n * not the tool action the agent has requested.\n */\nexport interface HumanInTheLoopConfig extends Omit<ToolConfigSchema, \"description\"> {\n}\n/**\n * Describes the agent-requested tool action (name and arguments).\n * This is what the AI intends to execute, subject to human review.\n */\nexport interface ActionRequest {\n /**\n * The tool/action name requested by the agent (e.g., \"send_email\").\n */\n action: string;\n /**\n * Arguments for the requested tool call (e.g., {\"a\": 1, \"b\": 2}).\n */\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention\n * to approve, edit, or respond to an agent-requested tool action.\n *\n * @example\n * ```ts\n * const hitlRequest: HumanInTheLoopRequest = {\n * actionRequest: { action: \"Approve XYZ action\", args: { ... } },\n * config: { allowAccept: true, allowEdit: true, allowRespond: true },\n * description: \"Please review the command before execution\"\n * };\n * response = interrupt([request])[0]\n * ```\n */\nexport interface HumanInTheLoopRequest {\n /**\n * The agent-requested tool action to be reviewed.\n */\n actionRequest: ActionRequest;\n /**\n * Which reviewer responses are allowed (accept/edit/respond).\n */\n config: HumanInTheLoopConfig;\n /**\n * Optional human-facing description shown in the approval prompt.\n */\n description?: string;\n}\n/**\n * Response when a human approves the agent-requested action.\n */\nexport interface AcceptPayload {\n type: \"accept\";\n}\n/**\n * Response when a human provides a manual response instead of executing\n * the agent-requested action.\n */\nexport interface ResponsePayload {\n type: \"response\";\n args?: string;\n}\n/**\n * Response when a human edits the agent-requested action (tool name and/or args).\n */\nexport interface EditPayload {\n type: \"edit\";\n args: ActionRequest;\n}\nexport type HumanInTheLoopMiddlewareHumanResponse = AcceptPayload | ResponsePayload | EditPayload;\n/**\n * Configuration for a tool requiring human in the loop.\n */\nexport interface ToolConfig extends HumanInTheLoopConfig {\n /**\n * Human-facing description shown in the approval request.\n */\n description?: string;\n}\ndeclare const contextSchema: z.ZodObject<{\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 accept/edit/respond\n * - `false` -> auto-approve (no human review)\n * - `ToolConfig` -> explicitly specify which reviewer responses are allowed for this tool\n */\n interruptOn: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodBoolean, z.ZodObject<{\n /**\n * Whether the human can approve the current action without changes\n */\n allowAccept: z.ZodOptional<z.ZodBoolean>;\n /**\n * Whether the human can reject the current action with feedback\n */\n allowEdit: z.ZodOptional<z.ZodBoolean>;\n /**\n * Whether the human can approve the current action with edited content\n */\n allowRespond: z.ZodOptional<z.ZodBoolean>;\n /**\n * The description attached to the request for human input\n */\n description: z.ZodOptional<z.ZodString>;\n }, \"strip\", z.ZodTypeAny, {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }, {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }>]>>>;\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 ToolConfig}. If a tool specifies a custom\n * `description`, that per-tool text is used and this prefix is ignored.\n */\n descriptionPrefix: z.ZodDefault<z.ZodString>;\n}, \"strip\", z.ZodTypeAny, {\n interruptOn?: Record<string, boolean | {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }> | undefined;\n descriptionPrefix: string;\n}, {\n interruptOn?: Record<string, boolean | {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }> | undefined;\n descriptionPrefix?: string | undefined;\n}>;\nexport type HumanInTheLoopMiddlewareConfig = InferInteropZodInput<typeof contextSchema>;\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. You can loop over the request to determine\n * which tools were interrupted, and how to handle them separately.\n *\n * ```ts\n * import { type ToolApprovalRequest, type HumanInTheLoopMiddlewareHumanResponse } from \"langchain/middleware\";\n * import { type Interrupt } from \"langchain\";\n *\n * const result = await agent.invoke(request);\n * const interruptRequest = initialResult.__interrupt__?.[0] as Interrupt<\n * ToolApprovalRequest[]\n * >;\n * const resume: HumanInTheLoopMiddlewareHumanResponse[] =\n * interruptRequest.value.map((request) => {\n * if (request.action === \"calculator\") {\n * return { id: request.toolCallId, type: \"accept\" };\n * } else if (request.action === \"write_file\") {\n * return {\n * id: request.toolCallId,\n * type: \"edit\",\n * args: { filename: \"safe.txt\", content: \"Safe content\" },\n * };\n * }\n *\n * throw new Error(`Unknown action: ${request.action}`);\n * });\n *\n * // Resume with approval\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 Response Types**: Accept, edit, ignore, or manually respond to 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 * ## Response Types\n *\n * When a tool requires approval, the human operator can respond with:\n * - `accept`: Execute the tool with original arguments\n * - `edit`: Modify the tool arguments before execution\n * - `ignore`: Skip the tool and terminate the agent\n * - `response`: 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].allowAccept - Whether the human can approve the current action without changes\n * @param options.interruptOn[toolName].allowEdit - Whether the human can reject the current action with feedback\n * @param options.interruptOn[toolName].allowRespond - Whether the human can approve the current action with edited content\n * @param options.interruptOn[toolName].description - Custom approval message for the tool\n * @param options.messagePrefix - Default prefix for approval messages (default: \"Tool execution requires approval\"). Only used for tools that do not define a custom `description` in their ToolConfig.\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/middleware\";\n * import { createAgent } from \"langchain\";\n *\n * const hitlMiddleware = humanInTheLoopMiddleware({\n * interruptOn: {\n * // Interrupt write_file tool and allow edits or accepts\n * \"write_file\": {\n * allowEdit: true,\n * allowAccept: true,\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 HumanInTheLoopRequest, type Interrupt } from \"langchain/middleware\";\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 = initialResult.__interrupt__?.[0] as Interrupt<\n * HumanInTheLoopRequest[]\n * >;\n *\n * // Show tool call details to user\n * console.log(\"Tool:\", interruptRequest.value[0].actionRequest);\n * console.log(\"Allowed actions:\", interruptRequest.value[0].config);\n *\n * // Resume with approval\n * await agent.invoke(\n * new Command({ resume: [{ type: \"accept\" }] }),\n * config\n * );\n * }\n * ```\n *\n * @example\n * Different response types\n * ```typescript\n * // Accept the tool call as-is\n * new Command({ resume: [{ type: \"accept\" }] })\n *\n * // Edit the tool arguments\n * new Command({\n * resume: [{\n * type: \"edit\",\n * args: { action: \"write_file\", args: { filename: \"safe.txt\", content: \"Modified\" } }\n * }]\n * })\n *\n * // Skip tool and terminate agent\n * new Command({ resume: [{ type: \"response\" }] })\n *\n * // Provide manual response\n * new Command({\n * resume: [{\n * type: \"response\",\n * // this must be a string\n * args: \"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 * allowAccept: true,\n * allowEdit: true,\n * allowRespond: true,\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 * allowAccept: true,\n * description: \"⛔ DESTRUCTIVE OPERATION - Requires manager approval\"\n * }\n * },\n * messagePrefix: \"Database operation pending approval\"\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\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 declare function humanInTheLoopMiddleware(options: NonNullable<HumanInTheLoopMiddlewareConfig>): import(\"../types.js\").AgentMiddleware<undefined, z.ZodObject<{\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 accept/edit/respond\n * - `false` -> auto-approve (no human review)\n * - `ToolConfig` -> explicitly specify which reviewer responses are allowed for this tool\n */\n interruptOn: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodBoolean, z.ZodObject<{\n /**\n * Whether the human can approve the current action without changes\n */\n allowAccept: z.ZodOptional<z.ZodBoolean>;\n /**\n * Whether the human can reject the current action with feedback\n */\n allowEdit: z.ZodOptional<z.ZodBoolean>;\n /**\n * Whether the human can approve the current action with edited content\n */\n allowRespond: z.ZodOptional<z.ZodBoolean>;\n /**\n * The description attached to the request for human input\n */\n description: z.ZodOptional<z.ZodString>;\n }, \"strip\", z.ZodTypeAny, {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }, {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }>]>>>;\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 ToolConfig}. If a tool specifies a custom\n * `description`, that per-tool text is used and this prefix is ignored.\n */\n descriptionPrefix: z.ZodDefault<z.ZodString>;\n}, \"strip\", z.ZodTypeAny, {\n interruptOn?: Record<string, boolean | {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }> | undefined;\n descriptionPrefix: string;\n}, {\n interruptOn?: Record<string, boolean | {\n allowAccept?: boolean | undefined;\n allowEdit?: boolean | undefined;\n allowRespond?: boolean | undefined;\n description?: string | undefined;\n }> | undefined;\n descriptionPrefix?: string | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;;cAGcE,kBAAkBF,CAAAA,CAAEO;;AADiC;;EA4BjE,WAvB+BJ,EAAhBH,CAAAA,CAAEI,WAAcD,CAAFH,CAAAA,CAAEG,UAAAA,CAAAA;EAAU;;;EAIf,SAIMA,EAJnBH,CAAAA,CAAEI,WAIiBD,CAJLH,CAAAA,CAAEG,UAIGA,CAAAA;EAAU;;;EAId,YAChBG,EALIN,CAAAA,CAAEI,WAKNE,CALkBN,CAAAA,CAAEG,UAKpBG,CAAAA;EAAU;AAjBmB;AAAA;EA4BtB,WAAA,EAZJN,CAAAA,CAAEI,WAYE,CAZUJ,CAAAA,CAAEK,SAYZ,CAAA;CAAA,EAAA,OAAkBH,EAX3BF,CAAAA,CAAEM,UAWyBJ,EAAAA;EAAgB,WAA7BM,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;EAAK,SAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAmBdG,YAAAA,CAAAA,EAAAA,OAAAA,GAAoB,SAAA;EAAA,WAAA,CAAA,EAAA,MAAA,GAAA,SAAA;CAAA,EAAA;EAA8B,WAArBC,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;EAAI,SAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAMjCC,YAAAA,CAAAA,EAAAA,OAAa,GAAA,SAQd;EAgBCE,WAAAA,CAAAA,EAAAA,MAAAA,GAAAA,SAAqB;CAAA,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