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,4 +1,17 @@
1
1
  //#region src/agents/interrupt.d.ts
2
+ /**
3
+ * Represents information about an interrupt.
4
+ */
5
+ interface Interrupt<TValue = unknown> {
6
+ /**
7
+ * The ID of the interrupt.
8
+ */
9
+ id: string;
10
+ /**
11
+ * The requests for human input.
12
+ */
13
+ value: TValue;
14
+ }
2
15
  /**
3
16
  * Configuration interface that defines what actions are allowed for a human interrupt.
4
17
  * This controls the available interaction options when the graph is paused for human input.
@@ -75,5 +88,5 @@ type HumanResponse = {
75
88
  args: null | string | ActionRequest;
76
89
  };
77
90
  //#endregion
78
- export { ActionRequest, HumanInterrupt, HumanInterruptConfig, HumanResponse };
91
+ export { ActionRequest, HumanInterrupt, HumanInterruptConfig, HumanResponse, Interrupt };
79
92
  //# sourceMappingURL=interrupt.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interrupt.d.cts","names":["interrupt","HumanInterruptConfig","ActionRequest","Record","HumanInterrupt","HumanResponse"],"sources":["../../src/agents/interrupt.d.ts"],"sourcesContent":["export { interrupt } from \"@langchain/langgraph\";\n/**\n * Configuration interface that defines what actions are allowed for a human interrupt.\n * This controls the available interaction options when the graph is paused for human input.\n */\nexport interface HumanInterruptConfig {\n /**\n * Whether the human can choose to ignore/skip the current step\n */\n allow_ignore: boolean;\n /**\n * Whether the human can provide a text response/feedback\n */\n allow_respond: boolean;\n /**\n * Whether the human can edit the provided content/state\n */\n allow_edit: boolean;\n /**\n * Whether the human can accept/approve the current state\n */\n allow_accept: boolean;\n}\n/**\n * Represents a request for human action within the graph execution.\n * Contains the action type and any associated arguments needed for the action.\n */\nexport interface ActionRequest {\n /**\n * The type or name of action being requested (e.g., \"Approve XYZ action\")\n */\n action: string;\n /**\n * Key-value pairs of arguments needed for the action\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention.\n * This is passed to the `interrupt` function when execution is paused for human input.\n */\nexport interface HumanInterrupt {\n /**\n * The specific action being requested from the human\n */\n action_request: ActionRequest;\n /**\n * Configuration defining what actions are allowed\n */\n config: HumanInterruptConfig;\n /**\n * Optional detailed description of what input is needed\n */\n description?: string;\n}\n/**\n * The response provided by a human to an interrupt, which is returned when graph execution resumes.\n */\nexport type HumanResponse = {\n /**\n * The type of response:\n * - \"accept\": Approves the current state without changes\n * - \"ignore\": Skips/ignores the current step\n * - \"response\": Provides text feedback or instructions\n * - \"edit\": Modifies the current state/content\n */\n type: \"accept\" | \"ignore\" | \"response\" | \"edit\";\n /**\n * The response payload:\n * - null: For ignore/accept actions\n * - string: For text responses\n * - ActionRequest: For edit actions with updated content\n */\n args: null | string | ActionRequest;\n};\n"],"mappings":";AAKA;AAsBA;AAeA;;AAIoBE,UAzCHD,oBAAAA,CAyCGC;EAAa;AAID;AAShC;;;;;;;;;;;;;;;;;;;UAhCiBA,aAAAA;;;;;;;;;QASPC;;;;;;UAMOC,cAAAA;;;;kBAIGF;;;;UAIRD;;;;;;;;;KASAI,aAAAA;;;;;;;;;;;;;;;wBAecH"}
1
+ {"version":3,"file":"interrupt.d.cts","names":["interrupt","Interrupt","TValue","HumanInterruptConfig","ActionRequest","Record","HumanInterrupt","HumanResponse"],"sources":["../../src/agents/interrupt.d.ts"],"sourcesContent":["export { interrupt } from \"@langchain/langgraph\";\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 interface that defines what actions are allowed for a human interrupt.\n * This controls the available interaction options when the graph is paused for human input.\n */\nexport interface HumanInterruptConfig {\n /**\n * Whether the human can choose to ignore/skip the current step\n */\n allow_ignore: boolean;\n /**\n * Whether the human can provide a text response/feedback\n */\n allow_respond: boolean;\n /**\n * Whether the human can edit the provided content/state\n */\n allow_edit: boolean;\n /**\n * Whether the human can accept/approve the current state\n */\n allow_accept: boolean;\n}\n/**\n * Represents a request for human action within the graph execution.\n * Contains the action type and any associated arguments needed for the action.\n */\nexport interface ActionRequest {\n /**\n * The type or name of action being requested (e.g., \"Approve XYZ action\")\n */\n action: string;\n /**\n * Key-value pairs of arguments needed for the action\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention.\n * This is passed to the `interrupt` function when execution is paused for human input.\n */\nexport interface HumanInterrupt {\n /**\n * The specific action being requested from the human\n */\n action_request: ActionRequest;\n /**\n * Configuration defining what actions are allowed\n */\n config: HumanInterruptConfig;\n /**\n * Optional detailed description of what input is needed\n */\n description?: string;\n}\n/**\n * The response provided by a human to an interrupt, which is returned when graph execution resumes.\n */\nexport type HumanResponse = {\n /**\n * The type of response:\n * - \"accept\": Approves the current state without changes\n * - \"ignore\": Skips/ignores the current step\n * - \"response\": Provides text feedback or instructions\n * - \"edit\": Modifies the current state/content\n */\n type: \"accept\" | \"ignore\" | \"response\" | \"edit\";\n /**\n * The response payload:\n * - null: For ignore/accept actions\n * - string: For text responses\n * - ActionRequest: For edit actions with updated content\n */\n args: null | string | ActionRequest;\n};\n"],"mappings":";AAIA;AAcA;AAsBA;AAeiBM,UAnDAL,SAmDc,CAAA,SAAA,OAAA,CAAA,CAAA;EAAA;;;EAQC,EAAA,EAAA,MAAA;EASpBM;;;SA5DDL;;;;;;UAMMC,oBAAAA;;;;;;;;;;;;;;;;;;;;;;UAsBAC,aAAAA;;;;;;;;;QASPC;;;;;;UAMOC,cAAAA;;;;kBAIGF;;;;UAIRD;;;;;;;;;KASAI,aAAAA;;;;;;;;;;;;;;;wBAecH"}
@@ -2,6 +2,19 @@ import "@langchain/langgraph";
2
2
 
3
3
  //#region src/agents/interrupt.d.ts
4
4
 
5
+ /**
6
+ * Represents information about an interrupt.
7
+ */
8
+ interface Interrupt<TValue = unknown> {
9
+ /**
10
+ * The ID of the interrupt.
11
+ */
12
+ id: string;
13
+ /**
14
+ * The requests for human input.
15
+ */
16
+ value: TValue;
17
+ }
5
18
  /**
6
19
  * Configuration interface that defines what actions are allowed for a human interrupt.
7
20
  * This controls the available interaction options when the graph is paused for human input.
@@ -78,5 +91,5 @@ type HumanResponse = {
78
91
  args: null | string | ActionRequest;
79
92
  };
80
93
  //#endregion
81
- export { ActionRequest, HumanInterrupt, HumanInterruptConfig, HumanResponse };
94
+ export { ActionRequest, HumanInterrupt, HumanInterruptConfig, HumanResponse, Interrupt };
82
95
  //# sourceMappingURL=interrupt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interrupt.d.ts","names":["interrupt","HumanInterruptConfig","ActionRequest","Record","HumanInterrupt","HumanResponse"],"sources":["../../src/agents/interrupt.d.ts"],"sourcesContent":["export { interrupt } from \"@langchain/langgraph\";\n/**\n * Configuration interface that defines what actions are allowed for a human interrupt.\n * This controls the available interaction options when the graph is paused for human input.\n */\nexport interface HumanInterruptConfig {\n /**\n * Whether the human can choose to ignore/skip the current step\n */\n allow_ignore: boolean;\n /**\n * Whether the human can provide a text response/feedback\n */\n allow_respond: boolean;\n /**\n * Whether the human can edit the provided content/state\n */\n allow_edit: boolean;\n /**\n * Whether the human can accept/approve the current state\n */\n allow_accept: boolean;\n}\n/**\n * Represents a request for human action within the graph execution.\n * Contains the action type and any associated arguments needed for the action.\n */\nexport interface ActionRequest {\n /**\n * The type or name of action being requested (e.g., \"Approve XYZ action\")\n */\n action: string;\n /**\n * Key-value pairs of arguments needed for the action\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention.\n * This is passed to the `interrupt` function when execution is paused for human input.\n */\nexport interface HumanInterrupt {\n /**\n * The specific action being requested from the human\n */\n action_request: ActionRequest;\n /**\n * Configuration defining what actions are allowed\n */\n config: HumanInterruptConfig;\n /**\n * Optional detailed description of what input is needed\n */\n description?: string;\n}\n/**\n * The response provided by a human to an interrupt, which is returned when graph execution resumes.\n */\nexport type HumanResponse = {\n /**\n * The type of response:\n * - \"accept\": Approves the current state without changes\n * - \"ignore\": Skips/ignores the current step\n * - \"response\": Provides text feedback or instructions\n * - \"edit\": Modifies the current state/content\n */\n type: \"accept\" | \"ignore\" | \"response\" | \"edit\";\n /**\n * The response payload:\n * - null: For ignore/accept actions\n * - string: For text responses\n * - ActionRequest: For edit actions with updated content\n */\n args: null | string | ActionRequest;\n};\n"],"mappings":";;;;;;AAKA;AAsBA;AAeiBI,UArCAH,oBAAAA,CAqCc;EAAA;;;EAQC,YAAA,EAAA,OAAA;EASpBI;;;;;;;;;;;;;;;;;UAhCKH,aAAAA;;;;;;;;;QASPC;;;;;;UAMOC,cAAAA;;;;kBAIGF;;;;UAIRD;;;;;;;;;KASAI,aAAAA;;;;;;;;;;;;;;;wBAecH"}
1
+ {"version":3,"file":"interrupt.d.ts","names":["interrupt","Interrupt","TValue","HumanInterruptConfig","ActionRequest","Record","HumanInterrupt","HumanResponse"],"sources":["../../src/agents/interrupt.d.ts"],"sourcesContent":["export { interrupt } from \"@langchain/langgraph\";\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 interface that defines what actions are allowed for a human interrupt.\n * This controls the available interaction options when the graph is paused for human input.\n */\nexport interface HumanInterruptConfig {\n /**\n * Whether the human can choose to ignore/skip the current step\n */\n allow_ignore: boolean;\n /**\n * Whether the human can provide a text response/feedback\n */\n allow_respond: boolean;\n /**\n * Whether the human can edit the provided content/state\n */\n allow_edit: boolean;\n /**\n * Whether the human can accept/approve the current state\n */\n allow_accept: boolean;\n}\n/**\n * Represents a request for human action within the graph execution.\n * Contains the action type and any associated arguments needed for the action.\n */\nexport interface ActionRequest {\n /**\n * The type or name of action being requested (e.g., \"Approve XYZ action\")\n */\n action: string;\n /**\n * Key-value pairs of arguments needed for the action\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention.\n * This is passed to the `interrupt` function when execution is paused for human input.\n */\nexport interface HumanInterrupt {\n /**\n * The specific action being requested from the human\n */\n action_request: ActionRequest;\n /**\n * Configuration defining what actions are allowed\n */\n config: HumanInterruptConfig;\n /**\n * Optional detailed description of what input is needed\n */\n description?: string;\n}\n/**\n * The response provided by a human to an interrupt, which is returned when graph execution resumes.\n */\nexport type HumanResponse = {\n /**\n * The type of response:\n * - \"accept\": Approves the current state without changes\n * - \"ignore\": Skips/ignores the current step\n * - \"response\": Provides text feedback or instructions\n * - \"edit\": Modifies the current state/content\n */\n type: \"accept\" | \"ignore\" | \"response\" | \"edit\";\n /**\n * The response payload:\n * - null: For ignore/accept actions\n * - string: For text responses\n * - ActionRequest: For edit actions with updated content\n */\n args: null | string | ActionRequest;\n};\n"],"mappings":";;;;;;AAIA;AAciBG,UAdAF,SAcAE,CAAoB,SAAA,OAAA,CAAA,CAAA;EAsBpBC;AAejB;;EAA+B,EAAA,EAIXA,MAAAA;EAAa;AAID;AAShC;SA5DWF;;;;;;UAMMC,oBAAAA;;;;;;;;;;;;;;;;;;;;;;UAsBAC,aAAAA;;;;;;;;;QASPC;;;;;;UAMOC,cAAAA;;;;kBAIGF;;;;UAIRD;;;;;;;;;KASAI,aAAAA;;;;;;;;;;;;;;;wBAecH"}
@@ -17,18 +17,10 @@ var ReactAgent = class {
17
17
  this.options = options;
18
18
  this.#toolBehaviorVersion = options.version ?? this.#toolBehaviorVersion;
19
19
  /**
20
- * Check if the LLM already has bound tools and throw if it does.
20
+ * define complete list of tools based on options and middleware
21
21
  */
22
- if (options.llm && typeof options.llm !== "function") require_utils.validateLLMHasNoBoundTools(options.llm);
23
- /**
24
- * validate that model and llm options are not provided together
25
- */
26
- if (options.llm && options.model) throw new Error("Cannot provide both `model` and `llm` options.");
27
- /**
28
- * validate that either model or llm option is provided
29
- */
30
- if (!options.llm && !options.model) throw new Error("Either `model` or `llm` option must be provided to create an agent.");
31
- const toolClasses = (Array.isArray(options.tools) ? options.tools : options.tools?.tools) ?? [];
22
+ const middlewareTools = this.options.middleware?.filter((m) => m.tools).flatMap((m) => m.tools) ?? [];
23
+ const toolClasses = [...(Array.isArray(options.tools) ? options.tools : options.tools?.tools) ?? [], ...middlewareTools];
32
24
  /**
33
25
  * If any of the tools are configured to return_directly after running,
34
26
  * our graph needs to check if these were called
@@ -39,31 +31,36 @@ var ReactAgent = class {
39
31
  const allNodeWorkflows = workflow;
40
32
  const beforeModelNodes = [];
41
33
  const afterModelNodes = [];
42
- const prepareModelRequestHookMiddleware = [];
34
+ const modifyModelRequestHookMiddleware = [];
35
+ const middlewareNames = /* @__PURE__ */ new Set();
43
36
  const middleware = this.options.middleware ?? [];
44
37
  for (let i = 0; i < middleware.length; i++) {
45
38
  let beforeModelNode;
46
39
  let afterModelNode;
47
40
  const m = middleware[i];
41
+ if (middlewareNames.has(m.name)) throw new Error(`Middleware ${m.name} is defined multiple times`);
42
+ middlewareNames.add(m.name);
48
43
  if (m.beforeModel) {
49
44
  beforeModelNode = new require_BeforeModalNode.BeforeModelNode(m);
50
- const name = `before_model_${m.name}_${i}`;
45
+ const name = `${m.name}.before_model`;
51
46
  beforeModelNodes.push({
52
47
  index: i,
53
- name
48
+ name,
49
+ allowed: m.beforeModelJumpTo
54
50
  });
55
51
  allNodeWorkflows.addNode(name, beforeModelNode, beforeModelNode.nodeOptions);
56
52
  }
57
53
  if (m.afterModel) {
58
54
  afterModelNode = new require_AfterModalNode.AfterModelNode(m);
59
- const name = `after_model_${m.name}_${i}`;
55
+ const name = `${m.name}.after_model`;
60
56
  afterModelNodes.push({
61
57
  index: i,
62
- name
58
+ name,
59
+ allowed: m.afterModelJumpTo
63
60
  });
64
61
  allNodeWorkflows.addNode(name, afterModelNode, afterModelNode.nodeOptions);
65
62
  }
66
- if (m.prepareModelRequest) prepareModelRequestHookMiddleware.push([m, () => ({
63
+ if (m.modifyModelRequest) modifyModelRequestHookMiddleware.push([m, () => ({
67
64
  ...beforeModelNode?.getState(),
68
65
  ...afterModelNode?.getState()
69
66
  })]);
@@ -72,9 +69,8 @@ var ReactAgent = class {
72
69
  * Add Nodes
73
70
  */
74
71
  allNodeWorkflows.addNode("model_request", new require_AgentNode.AgentNode({
75
- llm: this.options.llm,
76
72
  model: this.options.model,
77
- prompt: this.options.prompt,
73
+ systemPrompt: this.options.systemPrompt,
78
74
  includeAgentName: this.options.includeAgentName,
79
75
  name: this.options.name,
80
76
  responseFormat: this.options.responseFormat,
@@ -82,7 +78,7 @@ var ReactAgent = class {
82
78
  toolClasses,
83
79
  shouldReturnDirect,
84
80
  signal: this.options.signal,
85
- prepareModelRequestHookMiddleware
81
+ modifyModelRequestHookMiddleware
86
82
  }), require_AgentNode.AgentNode.nodeOptions);
87
83
  /**
88
84
  * add single tool node for all tools
@@ -96,9 +92,18 @@ var ReactAgent = class {
96
92
  */
97
93
  if (beforeModelNodes.length > 0) allNodeWorkflows.addEdge(__langchain_langgraph.START, beforeModelNodes[0].name);
98
94
  else allNodeWorkflows.addEdge(__langchain_langgraph.START, "model_request");
99
- for (let i = 0; i < beforeModelNodes.length - 1; i++) allNodeWorkflows.addEdge(beforeModelNodes[i].name, beforeModelNodes[i + 1].name);
100
- const lastBeforeModelNode = beforeModelNodes.at(-1);
101
- if (beforeModelNodes.length > 0 && lastBeforeModelNode) allNodeWorkflows.addEdge(lastBeforeModelNode.name, "model_request");
95
+ for (let i = 0; i < beforeModelNodes.length; i++) {
96
+ const node = beforeModelNodes[i];
97
+ const current = node.name;
98
+ const isLast = i === beforeModelNodes.length - 1;
99
+ const nextDefault = isLast ? "model_request" : beforeModelNodes[i + 1].name;
100
+ if (node.allowed && node.allowed.length > 0) {
101
+ const hasTools = toolClasses.filter(require_utils.isClientTool).length > 0;
102
+ const allowedMapped = node.allowed.map((t) => require_utils$1.parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
103
+ const destinations = Array.from(new Set([nextDefault, ...allowedMapped]));
104
+ allNodeWorkflows.addConditionalEdges(current, this.#createBeforeModelRouter(toolClasses.filter(require_utils.isClientTool), nextDefault), destinations);
105
+ } else allNodeWorkflows.addEdge(current, nextDefault);
106
+ }
102
107
  const lastAfterModelNode = afterModelNodes.at(-1);
103
108
  if (afterModelNodes.length > 0 && lastAfterModelNode) allNodeWorkflows.addEdge("model_request", lastAfterModelNode.name);
104
109
  else {
@@ -106,12 +111,24 @@ var ReactAgent = class {
106
111
  if (modelPaths.length === 1) allNodeWorkflows.addEdge("model_request", modelPaths[0]);
107
112
  else allNodeWorkflows.addConditionalEdges("model_request", this.#createModelRouter(), modelPaths);
108
113
  }
109
- for (let i = afterModelNodes.length - 1; i > 0; i--) allNodeWorkflows.addEdge(afterModelNodes[i].name, afterModelNodes[i - 1].name);
114
+ for (let i = afterModelNodes.length - 1; i > 0; i--) {
115
+ const node = afterModelNodes[i];
116
+ const current = node.name;
117
+ const nextDefault = afterModelNodes[i - 1].name;
118
+ if (node.allowed && node.allowed.length > 0) {
119
+ const hasTools = toolClasses.filter(require_utils.isClientTool).length > 0;
120
+ const allowedMapped = node.allowed.map((t) => require_utils$1.parseJumpToTarget(t)).filter((dest) => dest !== "tools" || hasTools);
121
+ const destinations = Array.from(new Set([nextDefault, ...allowedMapped]));
122
+ allNodeWorkflows.addConditionalEdges(current, this.#createAfterModelSequenceRouter(toolClasses.filter(require_utils.isClientTool), node.allowed, nextDefault), destinations);
123
+ } else allNodeWorkflows.addEdge(current, nextDefault);
124
+ }
110
125
  if (afterModelNodes.length > 0) {
111
- const firstAfterModelNode = afterModelNodes[0].name;
112
- const modelPaths = this.#getModelPaths(toolClasses.filter(require_utils.isClientTool));
113
- if (modelPaths.length === 1) allNodeWorkflows.addEdge(firstAfterModelNode, modelPaths[0]);
114
- else allNodeWorkflows.addConditionalEdges(firstAfterModelNode, this.#createModelRouter(), modelPaths);
126
+ const firstAfterModel = afterModelNodes[0];
127
+ const firstAfterModelNode = firstAfterModel.name;
128
+ const modelPaths = this.#getModelPaths(toolClasses.filter(require_utils.isClientTool), true).filter((p) => p !== "tools" || toolClasses.filter(require_utils.isClientTool).length > 0);
129
+ const allowJump = Boolean(firstAfterModel.allowed && firstAfterModel.allowed.length > 0);
130
+ const destinations = modelPaths;
131
+ allNodeWorkflows.addConditionalEdges(firstAfterModelNode, this.#createAfterModelRouter(toolClasses.filter(require_utils.isClientTool), allowJump), destinations);
115
132
  }
116
133
  /**
117
134
  * add edges for tools node
@@ -128,15 +145,13 @@ var ReactAgent = class {
128
145
  */
129
146
  this.#graph = allNodeWorkflows.compile({
130
147
  checkpointer: this.options.checkpointer ?? this.options.checkpointSaver,
131
- interruptBefore: this.options.interruptBefore,
132
- interruptAfter: this.options.interruptAfter,
133
148
  store: this.options.store,
134
149
  name: this.options.name,
135
150
  description: this.options.description
136
151
  });
137
152
  }
138
153
  /**
139
- * Get the compiled graph.
154
+ * Get the compiled {@link https://docs.langchain.com/oss/javascript/langgraph/use-graph-api | StateGraph}.
140
155
  */
141
156
  get graph() {
142
157
  return this.#graph;
@@ -144,79 +159,271 @@ var ReactAgent = class {
144
159
  /**
145
160
  * Get possible edge destinations from model node.
146
161
  * @param toolClasses names of tools to call
162
+ * @param includeModelRequest whether to include "model_request" as a valid path (for jumpTo routing)
147
163
  * @returns list of possible edge destinations
148
164
  */
149
- #getModelPaths(toolClasses) {
165
+ #getModelPaths(toolClasses, includeModelRequest = false) {
150
166
  const paths = [];
151
167
  if (toolClasses.length > 0) paths.push("tools");
168
+ if (includeModelRequest) paths.push("model_request");
152
169
  paths.push(__langchain_langgraph.END);
153
170
  return paths;
154
171
  }
155
172
  /**
173
+ * Create routing function for tools node conditional edges.
174
+ */
175
+ #createToolsRouter(shouldReturnDirect) {
176
+ /**
177
+ * ToDo: fix type
178
+ */
179
+ return (state) => {
180
+ const messages = state.messages;
181
+ const lastMessage = messages[messages.length - 1];
182
+ if (__langchain_core_messages.ToolMessage.isInstance(lastMessage) && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? "model_request" : __langchain_langgraph.END;
183
+ return "model_request";
184
+ };
185
+ }
186
+ /**
156
187
  * Create routing function for model node conditional edges.
157
188
  */
158
189
  #createModelRouter() {
159
190
  /**
160
191
  * determine if the agent should continue or not
161
192
  */
162
- /**
163
- * ToDo: fix type
164
- */
165
193
  return (state) => {
166
194
  const messages = state.messages;
167
195
  const lastMessage = messages.at(-1);
168
196
  if (!__langchain_core_messages.AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls || lastMessage.tool_calls.length === 0) return __langchain_langgraph.END;
197
+ const hasOnlyStructuredResponseCalls = lastMessage.tool_calls.every((toolCall) => toolCall.name.startsWith("extract-"));
198
+ if (hasOnlyStructuredResponseCalls) return __langchain_langgraph.END;
169
199
  /**
170
200
  * The tool node processes a single message.
171
201
  */
172
202
  if (this.#toolBehaviorVersion === "v1") return "tools";
173
203
  /**
174
- * Route to tools node
204
+ * Route to tools node (filter out any structured response tool calls)
175
205
  */
176
- return lastMessage.tool_calls.map((toolCall) => new __langchain_langgraph.Send("tools", {
206
+ const regularToolCalls = lastMessage.tool_calls.filter((toolCall) => !toolCall.name.startsWith("extract-"));
207
+ if (regularToolCalls.length === 0) return __langchain_langgraph.END;
208
+ return regularToolCalls.map((toolCall) => new __langchain_langgraph.Send("tools", {
177
209
  ...state,
178
210
  lg_tool_call: toolCall
179
211
  }));
180
212
  };
181
213
  }
182
214
  /**
183
- * Create routing function for tools node conditional edges.
215
+ * Create routing function for jumpTo functionality after afterModel hooks.
216
+ *
217
+ * This router checks if the `jumpTo` property is set in the state after afterModel middleware
218
+ * execution. If set, it routes to the specified target ("model_request" or "tools").
219
+ * If not set, it falls back to the normal model routing logic for afterModel context.
220
+ *
221
+ * The jumpTo property is automatically cleared after use to prevent infinite loops.
222
+ *
223
+ * @param toolClasses - Available tool classes for validation
224
+ * @returns Router function that handles jumpTo logic and normal routing
184
225
  */
185
- #createToolsRouter(shouldReturnDirect) {
186
- /**
187
- * ToDo: fix type
188
- */
226
+ #createAfterModelRouter(toolClasses, allowJump) {
227
+ const hasStructuredResponse = Boolean(this.options.responseFormat);
189
228
  return (state) => {
190
229
  const messages = state.messages;
191
- const lastMessage = messages[messages.length - 1];
192
- if (__langchain_core_messages.ToolMessage.isInstance(lastMessage) && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? "model_request" : __langchain_langgraph.END;
193
- return "model_request";
230
+ const lastMessage = messages.at(-1);
231
+ if (__langchain_core_messages.AIMessage.isInstance(lastMessage) && (!lastMessage.tool_calls || lastMessage.tool_calls.length === 0)) return __langchain_langgraph.END;
232
+ if (allowJump && state.jumpTo) {
233
+ if (state.jumpTo === __langchain_langgraph.END) return __langchain_langgraph.END;
234
+ if (state.jumpTo === "tools") {
235
+ if (toolClasses.length === 0) return __langchain_langgraph.END;
236
+ return new __langchain_langgraph.Send("tools", {
237
+ ...state,
238
+ jumpTo: void 0
239
+ });
240
+ }
241
+ return new __langchain_langgraph.Send("model_request", {
242
+ ...state,
243
+ jumpTo: void 0
244
+ });
245
+ }
246
+ const toolMessages = messages.filter(__langchain_core_messages.ToolMessage.isInstance);
247
+ const lastAiMessage = messages.filter(__langchain_core_messages.AIMessage.isInstance).at(-1);
248
+ const pendingToolCalls = lastAiMessage?.tool_calls?.filter((call) => !toolMessages.some((m) => m.tool_call_id === call.id));
249
+ if (pendingToolCalls && pendingToolCalls.length > 0) return pendingToolCalls.map((toolCall) => new __langchain_langgraph.Send("tools", {
250
+ ...state,
251
+ lg_tool_call: toolCall
252
+ }));
253
+ const hasStructuredResponseCalls = lastAiMessage?.tool_calls?.some((toolCall) => toolCall.name.startsWith("extract-"));
254
+ if (pendingToolCalls && pendingToolCalls.length === 0 && !hasStructuredResponseCalls && hasStructuredResponse) return "model_request";
255
+ if (!__langchain_core_messages.AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls || lastMessage.tool_calls.length === 0) return __langchain_langgraph.END;
256
+ const hasOnlyStructuredResponseCalls = lastMessage.tool_calls.every((toolCall) => toolCall.name.startsWith("extract-"));
257
+ const hasRegularToolCalls = lastMessage.tool_calls.some((toolCall) => !toolCall.name.startsWith("extract-"));
258
+ if (hasOnlyStructuredResponseCalls || !hasRegularToolCalls) return __langchain_langgraph.END;
259
+ /**
260
+ * For routing from afterModel nodes, always use simple string paths
261
+ * The Send API is handled at the model_request node level
262
+ */
263
+ return "tools";
264
+ };
265
+ }
266
+ /**
267
+ * Router for afterModel sequence nodes (connecting later middlewares to earlier ones),
268
+ * honoring allowed jump targets and defaulting to the next node.
269
+ */
270
+ #createAfterModelSequenceRouter(toolClasses, allowed, nextDefault) {
271
+ const allowedSet = new Set(allowed.map((t) => require_utils$1.parseJumpToTarget(t)));
272
+ return (state) => {
273
+ if (state.jumpTo) {
274
+ const dest = require_utils$1.parseJumpToTarget(state.jumpTo);
275
+ if (dest === __langchain_langgraph.END && allowedSet.has(__langchain_langgraph.END)) return __langchain_langgraph.END;
276
+ if (dest === "tools" && allowedSet.has("tools")) {
277
+ if (toolClasses.length === 0) return __langchain_langgraph.END;
278
+ return new __langchain_langgraph.Send("tools", {
279
+ ...state,
280
+ jumpTo: void 0
281
+ });
282
+ }
283
+ if (dest === "model_request" && allowedSet.has("model_request")) return new __langchain_langgraph.Send("model_request", {
284
+ ...state,
285
+ jumpTo: void 0
286
+ });
287
+ }
288
+ return nextDefault;
289
+ };
290
+ }
291
+ /**
292
+ * Create routing function for jumpTo functionality after beforeModel hooks.
293
+ * Falls back to the default next node if no jumpTo is present.
294
+ */
295
+ #createBeforeModelRouter(toolClasses, nextDefault) {
296
+ return (state) => {
297
+ if (!state.jumpTo) return nextDefault;
298
+ const destination = require_utils$1.parseJumpToTarget(state.jumpTo);
299
+ if (destination === __langchain_langgraph.END) return __langchain_langgraph.END;
300
+ if (destination === "tools") {
301
+ if (toolClasses.length === 0) return __langchain_langgraph.END;
302
+ return new __langchain_langgraph.Send("tools", {
303
+ ...state,
304
+ jumpTo: void 0
305
+ });
306
+ }
307
+ return new __langchain_langgraph.Send("model_request", {
308
+ ...state,
309
+ jumpTo: void 0
310
+ });
194
311
  };
195
312
  }
196
313
  /**
197
314
  * Initialize middleware states if not already present in the input state.
198
315
  */
199
- #initializeMiddlewareStates(state) {
316
+ async #initializeMiddlewareStates(state) {
200
317
  if (!this.options.middleware || this.options.middleware.length === 0 || state instanceof __langchain_langgraph.Command || !state) return state;
201
- const defaultStates = require_utils$1.initializeMiddlewareStates(this.options.middleware, state);
318
+ const defaultStates = await require_utils$1.initializeMiddlewareStates(this.options.middleware, state);
202
319
  const updatedState = { ...state };
203
320
  if (!updatedState) return updatedState;
204
321
  for (const [key, value] of Object.entries(defaultStates)) if (!(key in updatedState)) updatedState[key] = value;
205
322
  return updatedState;
206
323
  }
207
324
  /**
208
- * @inheritdoc
325
+ * Executes the agent with the given state and returns the final state after all processing.
326
+ *
327
+ * This method runs the agent's entire workflow synchronously, including:
328
+ * - Processing the input messages through any configured middleware
329
+ * - Calling the language model to generate responses
330
+ * - Executing any tool calls made by the model
331
+ * - Running all middleware hooks (beforeModel, afterModel, etc.)
332
+ *
333
+ * @param state - The initial state for the agent execution. Can be:
334
+ * - An object containing `messages` array and any middleware-specific state properties
335
+ * - A Command object for more advanced control flow
336
+ *
337
+ * @param config - Optional runtime configuration including:
338
+ * @param config.context - The context for the agent execution.
339
+ * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.
340
+ * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.
341
+ * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.
342
+ * @param config.recursionLimit - The recursion limit for the agent execution.
343
+ *
344
+ * @returns A Promise that resolves to the final agent state after execution completes.
345
+ * The returned state includes:
346
+ * - a `messages` property containing an array with all messages (input, AI responses, tool calls/results)
347
+ * - a `structuredResponse` property containing the structured response (if configured)
348
+ * - all state values defined in the middleware
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const agent = new ReactAgent({
353
+ * llm: myModel,
354
+ * tools: [calculator, webSearch],
355
+ * responseFormat: z.object({
356
+ * weather: z.string(),
357
+ * }),
358
+ * });
359
+ *
360
+ * const result = await agent.invoke({
361
+ * messages: [{ role: "human", content: "What's the weather in Paris?" }]
362
+ * });
363
+ *
364
+ * console.log(result.structuredResponse.weather); // outputs: "It's sunny and 75°F."
365
+ * ```
209
366
  */
210
- get invoke() {
211
- const invokeFunc = async (state, config) => {
212
- const initializedState = this.#initializeMiddlewareStates(state);
213
- return this.#graph.invoke(initializedState, config);
214
- };
215
- return invokeFunc;
367
+ async invoke(state, config) {
368
+ const initializedState = await this.#initializeMiddlewareStates(state);
369
+ return this.#graph.invoke(initializedState, config);
216
370
  }
217
371
  /**
218
- * ToDo(@christian-bromann): Add stream and streamEvents methods
372
+ * Executes the agent with streaming, returning an async iterable of events as they occur.
373
+ *
374
+ * This method runs the agent's workflow similar to `invoke`, but instead of waiting for
375
+ * completion, it streams events in real-time. This allows you to:
376
+ * - Display intermediate results to users as they're generated
377
+ * - Monitor the agent's progress through each step
378
+ * - Handle tool calls and results as they happen
379
+ * - Update UI with streaming responses from the LLM
380
+ *
381
+ * @param state - The initial state for the agent execution. Can be:
382
+ * - An object containing `messages` array and any middleware-specific state properties
383
+ * - A Command object for more advanced control flow
384
+ *
385
+ * @param config - Optional runtime configuration including:
386
+ * @param config.context - The context for the agent execution.
387
+ * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.
388
+ * @param config.store - The store for the agent execution for persisting state, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/memory#memory-storage | Memory storage}.
389
+ * @param config.signal - An optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} for the agent execution.
390
+ * @param config.streamMode - The streaming mode for the agent execution, see more in {@link https://docs.langchain.com/oss/javascript/langgraph/streaming#supported-stream-modes | Supported stream modes}.
391
+ * @param config.recursionLimit - The recursion limit for the agent execution.
392
+ *
393
+ * @returns A Promise that resolves to an IterableReadableStream of events.
394
+ * Events include:
395
+ * - `on_chat_model_start`: When the LLM begins processing
396
+ * - `on_chat_model_stream`: Streaming tokens from the LLM
397
+ * - `on_chat_model_end`: When the LLM completes
398
+ * - `on_tool_start`: When a tool execution begins
399
+ * - `on_tool_end`: When a tool execution completes
400
+ * - `on_chain_start`: When middleware chains begin
401
+ * - `on_chain_end`: When middleware chains complete
402
+ * - And other LangGraph v2 stream events
403
+ *
404
+ * @example
405
+ * ```typescript
406
+ * const agent = new ReactAgent({
407
+ * llm: myModel,
408
+ * tools: [calculator, webSearch]
409
+ * });
410
+ *
411
+ * const stream = await agent.stream({
412
+ * messages: [{ role: "human", content: "What's 2+2 and the weather in NYC?" }]
413
+ * });
414
+ *
415
+ * for await (const event of stream) {
416
+ * //
417
+ * }
418
+ * ```
219
419
  */
420
+ async stream(state, config) {
421
+ const initializedState = await this.#initializeMiddlewareStates(state);
422
+ return this.#graph.streamEvents(initializedState, {
423
+ ...config,
424
+ version: "v2"
425
+ });
426
+ }
220
427
  /**
221
428
  * Visualize the graph as a PNG image.
222
429
  * @param params - Parameters for the drawMermaidPng method.