langchain 1.0.0-alpha.3 → 1.0.0-alpha.5

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 (201) hide show
  1. package/dist/agents/ReactAgent.cjs +1 -1
  2. package/dist/agents/ReactAgent.cjs.map +1 -1
  3. package/dist/agents/ReactAgent.d.cts +3 -3
  4. package/dist/agents/ReactAgent.d.cts.map +1 -1
  5. package/dist/agents/ReactAgent.d.ts +3 -3
  6. package/dist/agents/ReactAgent.d.ts.map +1 -1
  7. package/dist/agents/ReactAgent.js +2 -2
  8. package/dist/agents/ReactAgent.js.map +1 -1
  9. package/dist/agents/RunnableCallable.cjs +5 -0
  10. package/dist/agents/RunnableCallable.cjs.map +1 -1
  11. package/dist/agents/RunnableCallable.d.cts +2 -0
  12. package/dist/agents/RunnableCallable.d.cts.map +1 -1
  13. package/dist/agents/RunnableCallable.d.ts +2 -0
  14. package/dist/agents/RunnableCallable.d.ts.map +1 -1
  15. package/dist/agents/RunnableCallable.js +5 -0
  16. package/dist/agents/RunnableCallable.js.map +1 -1
  17. package/dist/agents/annotation.cjs +2 -2
  18. package/dist/agents/annotation.cjs.map +1 -1
  19. package/dist/agents/annotation.d.cts +4 -4
  20. package/dist/agents/annotation.d.cts.map +1 -1
  21. package/dist/agents/annotation.d.ts +3 -3
  22. package/dist/agents/annotation.d.ts.map +1 -1
  23. package/dist/agents/annotation.js +2 -2
  24. package/dist/agents/annotation.js.map +1 -1
  25. package/dist/agents/createAgent.cjs +10 -0
  26. package/dist/agents/createAgent.cjs.map +1 -0
  27. package/dist/agents/createAgent.js +10 -0
  28. package/dist/agents/createAgent.js.map +1 -0
  29. package/dist/agents/errors.cjs +1 -1
  30. package/dist/agents/errors.cjs.map +1 -1
  31. package/dist/agents/errors.js +1 -1
  32. package/dist/agents/errors.js.map +1 -1
  33. package/dist/agents/index.cjs +23 -4
  34. package/dist/agents/index.cjs.map +1 -1
  35. package/dist/agents/index.d.cts +96 -33
  36. package/dist/agents/index.d.cts.map +1 -1
  37. package/dist/agents/index.d.ts +96 -33
  38. package/dist/agents/index.d.ts.map +1 -1
  39. package/dist/agents/index.js +23 -4
  40. package/dist/agents/index.js.map +1 -1
  41. package/dist/agents/middlewareAgent/ReactAgent.cjs +255 -0
  42. package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -0
  43. package/dist/agents/middlewareAgent/ReactAgent.d.cts +68 -0
  44. package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -0
  45. package/dist/agents/middlewareAgent/ReactAgent.d.ts +68 -0
  46. package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -0
  47. package/dist/agents/middlewareAgent/ReactAgent.js +254 -0
  48. package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -0
  49. package/dist/agents/middlewareAgent/annotation.cjs +39 -0
  50. package/dist/agents/middlewareAgent/annotation.cjs.map +1 -0
  51. package/dist/agents/middlewareAgent/annotation.js +38 -0
  52. package/dist/agents/middlewareAgent/annotation.js.map +1 -0
  53. package/dist/agents/middlewareAgent/index.cjs +11 -0
  54. package/dist/agents/middlewareAgent/index.cjs.map +1 -0
  55. package/dist/agents/middlewareAgent/index.js +11 -0
  56. package/dist/agents/middlewareAgent/index.js.map +1 -0
  57. package/dist/agents/middlewareAgent/middleware.cjs +47 -0
  58. package/dist/agents/middlewareAgent/middleware.cjs.map +1 -0
  59. package/dist/agents/middlewareAgent/middleware.d.cts +46 -0
  60. package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -0
  61. package/dist/agents/middlewareAgent/middleware.d.ts +46 -0
  62. package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -0
  63. package/dist/agents/middlewareAgent/middleware.js +46 -0
  64. package/dist/agents/middlewareAgent/middleware.js.map +1 -0
  65. package/dist/agents/middlewareAgent/middlewares/hitl.cjs +235 -0
  66. package/dist/agents/middlewareAgent/middlewares/hitl.cjs.map +1 -0
  67. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts +199 -0
  68. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts.map +1 -0
  69. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts +199 -0
  70. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts.map +1 -0
  71. package/dist/agents/middlewareAgent/middlewares/hitl.js +234 -0
  72. package/dist/agents/middlewareAgent/middlewares/hitl.js.map +1 -0
  73. package/dist/agents/middlewareAgent/middlewares/index.cjs +8 -0
  74. package/dist/agents/middlewareAgent/middlewares/index.d.cts +4 -0
  75. package/dist/agents/middlewareAgent/middlewares/index.d.ts +4 -0
  76. package/dist/agents/middlewareAgent/middlewares/index.js +5 -0
  77. package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs +153 -0
  78. package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs.map +1 -0
  79. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts +152 -0
  80. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts.map +1 -0
  81. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts +152 -0
  82. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts.map +1 -0
  83. package/dist/agents/middlewareAgent/middlewares/promptCaching.js +152 -0
  84. package/dist/agents/middlewareAgent/middlewares/promptCaching.js.map +1 -0
  85. package/dist/agents/middlewareAgent/middlewares/summarization.cjs +262 -0
  86. package/dist/agents/middlewareAgent/middlewares/summarization.cjs.map +1 -0
  87. package/dist/agents/middlewareAgent/middlewares/summarization.d.cts +89 -0
  88. package/dist/agents/middlewareAgent/middlewares/summarization.d.cts.map +1 -0
  89. package/dist/agents/middlewareAgent/middlewares/summarization.d.ts +89 -0
  90. package/dist/agents/middlewareAgent/middlewares/summarization.d.ts.map +1 -0
  91. package/dist/agents/middlewareAgent/middlewares/summarization.js +260 -0
  92. package/dist/agents/middlewareAgent/middlewares/summarization.js.map +1 -0
  93. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs +29 -0
  94. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -0
  95. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js +29 -0
  96. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -0
  97. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +332 -0
  98. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -0
  99. package/dist/agents/middlewareAgent/nodes/AgentNode.js +331 -0
  100. package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -0
  101. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs +27 -0
  102. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -0
  103. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js +27 -0
  104. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -0
  105. package/dist/agents/middlewareAgent/nodes/middleware.cjs +73 -0
  106. package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -0
  107. package/dist/agents/middlewareAgent/nodes/middleware.js +73 -0
  108. package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -0
  109. package/dist/agents/middlewareAgent/nodes/utils.cjs +74 -0
  110. package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -0
  111. package/dist/agents/middlewareAgent/nodes/utils.js +70 -0
  112. package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -0
  113. package/dist/agents/middlewareAgent/types.d.cts +393 -0
  114. package/dist/agents/middlewareAgent/types.d.cts.map +1 -0
  115. package/dist/agents/middlewareAgent/types.d.ts +393 -0
  116. package/dist/agents/middlewareAgent/types.d.ts.map +1 -0
  117. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  118. package/dist/agents/nodes/AgentNode.js.map +1 -1
  119. package/dist/agents/nodes/ToolNode.cjs +1 -1
  120. package/dist/agents/nodes/ToolNode.cjs.map +1 -1
  121. package/dist/agents/nodes/ToolNode.d.cts +4 -4
  122. package/dist/agents/nodes/ToolNode.d.cts.map +1 -1
  123. package/dist/agents/nodes/ToolNode.d.ts +1 -1
  124. package/dist/agents/nodes/ToolNode.d.ts.map +1 -1
  125. package/dist/agents/nodes/ToolNode.js +1 -1
  126. package/dist/agents/nodes/ToolNode.js.map +1 -1
  127. package/dist/agents/responses.cjs +1 -1
  128. package/dist/agents/responses.cjs.map +1 -1
  129. package/dist/agents/responses.d.cts +1 -1
  130. package/dist/agents/responses.d.cts.map +1 -1
  131. package/dist/agents/responses.d.ts +1 -1
  132. package/dist/agents/responses.d.ts.map +1 -1
  133. package/dist/agents/responses.js +1 -1
  134. package/dist/agents/responses.js.map +1 -1
  135. package/dist/agents/types.d.cts +12 -12
  136. package/dist/agents/types.d.cts.map +1 -1
  137. package/dist/agents/types.d.ts +8 -8
  138. package/dist/agents/types.d.ts.map +1 -1
  139. package/dist/agents/utils.cjs +1 -1
  140. package/dist/agents/utils.cjs.map +1 -1
  141. package/dist/agents/utils.js +1 -1
  142. package/dist/agents/utils.js.map +1 -1
  143. package/dist/agents/withAgentName.cjs +1 -1
  144. package/dist/agents/withAgentName.cjs.map +1 -1
  145. package/dist/agents/withAgentName.js +1 -1
  146. package/dist/agents/withAgentName.js.map +1 -1
  147. package/dist/chains/api/api_chain.d.cts +1 -1
  148. package/dist/chains/base.d.cts +1 -1
  149. package/dist/chains/combine_docs_chain.d.cts +1 -1
  150. package/dist/chains/combine_documents/stuff.d.cts +1 -1
  151. package/dist/chains/conversational_retrieval_chain.d.cts +1 -1
  152. package/dist/chains/graph_qa/cypher.d.cts +1 -1
  153. package/dist/chains/history_aware_retriever.d.cts +2 -2
  154. package/dist/chains/llm_chain.d.cts +3 -3
  155. package/dist/chains/openai_functions/base.d.cts +3 -3
  156. package/dist/chains/openai_functions/openapi.d.cts +1 -1
  157. package/dist/chains/openai_functions/structured_output.d.cts +3 -3
  158. package/dist/chains/openai_functions/tagging.d.cts +1 -1
  159. package/dist/chains/query_constructor/index.cjs +1 -1
  160. package/dist/chains/query_constructor/index.d.cts +2 -2
  161. package/dist/chains/query_constructor/index.d.ts +1 -1
  162. package/dist/chains/query_constructor/index.js +1 -1
  163. package/dist/chains/question_answering/load.d.ts +2 -2
  164. package/dist/chains/question_answering/load.d.ts.map +1 -1
  165. package/dist/chains/retrieval.d.cts +1 -1
  166. package/dist/chains/router/llm_router.d.cts +1 -1
  167. package/dist/chains/router/multi_prompt.cjs +1 -1
  168. package/dist/chains/router/multi_prompt.js +1 -1
  169. package/dist/chains/router/multi_retrieval_qa.cjs +1 -1
  170. package/dist/chains/router/multi_retrieval_qa.js +1 -1
  171. package/dist/chains/sql_db/sql_db_chain.d.cts +2 -2
  172. package/dist/chains/summarization/load.d.ts +2 -2
  173. package/dist/chains/summarization/load.d.ts.map +1 -1
  174. package/dist/chat_models/universal.d.cts +3 -3
  175. package/dist/evaluation/agents/trajectory.d.cts +3 -3
  176. package/dist/evaluation/agents/trajectory.d.ts.map +1 -1
  177. package/dist/evaluation/comparison/pairwise.d.cts +1 -1
  178. package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
  179. package/dist/evaluation/criteria/criteria.d.cts +1 -1
  180. package/dist/evaluation/qa/eval_chain.d.cts +1 -1
  181. package/dist/index.cjs +5 -2
  182. package/dist/index.cjs.map +1 -1
  183. package/dist/index.d.cts +6 -5
  184. package/dist/index.d.ts +4 -3
  185. package/dist/index.js +5 -3
  186. package/dist/index.js.map +1 -1
  187. package/dist/load/import_map.cjs +1 -1
  188. package/dist/load/import_map.js +1 -1
  189. package/dist/memory/summary.d.cts +1 -1
  190. package/dist/output_parsers/fix.d.cts +1 -1
  191. package/dist/output_parsers/http_response.d.cts +1 -1
  192. package/dist/output_parsers/structured.cjs +1 -1
  193. package/dist/output_parsers/structured.d.cts +2 -2
  194. package/dist/output_parsers/structured.d.ts +1 -1
  195. package/dist/output_parsers/structured.js +1 -1
  196. package/dist/tools/fs.d.cts +1 -1
  197. package/dist/tools/json.d.cts +1 -1
  198. package/dist/tools/retriever.d.cts +1 -1
  199. package/dist/tools/vectorstore.d.cts +1 -1
  200. package/dist/tools/webbrowser.d.cts +1 -1
  201. package/package.json +14 -3
@@ -1 +1 @@
1
- {"version":3,"file":"annotation.d.cts","names":["BaseMessage","Messages","AnnotationRoot","BinaryOperatorAggregate","LastValue","InteropZodToStateDefinition","InteropZodObject","ResponseFormatUndefined","PreHookAnnotation","createReactAgentBaseAnnotation","createReactAgentAnnotation","Record","T","createReactAgentAnnotationConditional","ReactAgentAnnotation","ReturnType","ToAnnotationRoot","AnyAnnotationRoot","A","enhanceStateSchemaWithMessageReducer"],"sources":["../../src/agents/annotation.d.ts"],"sourcesContent":["import { BaseMessage } from \"@langchain/core/messages\";\nimport { Messages, AnnotationRoot, type BinaryOperatorAggregate, type LastValue } from \"@langchain/langgraph\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport { type InteropZodObject } from \"@langchain/core/utils/types\";\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nexport declare const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\nexport type PreHookAnnotation = typeof PreHookAnnotation;\n// Base annotation without structuredResponse (for ResponseFormatUndefined)\nexport declare const createReactAgentBaseAnnotation: () => AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Full annotation with structuredResponse (for regular cases)\ndeclare const createReactAgentAnnotation: <\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{\n structuredResponse: LastValue<T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\nexport declare function createReactAgentAnnotationConditional<T extends Record<string, any> | ResponseFormatUndefined>(hasStructuredResponse?: boolean): AnnotationRoot<{\n structuredResponse: LastValue<T extends ResponseFormatUndefined ? never : T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Helper type to select the right annotation based on the response format type\nexport type ReactAgentAnnotation<T extends Record<string, any> | ResponseFormatUndefined> = T extends ResponseFormatUndefined ? ReturnType<typeof createReactAgentBaseAnnotation> : T extends Record<string, any> ? ReturnType<typeof createReactAgentAnnotation<T>> : never;\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n/**\n * Enhances a state schema to ensure proper message handling.\n * If a Zod schema is provided, it creates an annotation that includes the messagesStateReducer\n * and infers appropriate reducers for all other fields.\n *\n * @param stateSchema - The state schema to enhance.\n * @returns The enhanced state schema.\n */\nexport declare function enhanceStateSchemaWithMessageReducer(stateSchema: AnyAnnotationRoot | InteropZodObject): AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;\n}> | AnyAnnotationRoot;\nexport {};\n"],"mappings":";;;;;;;cAKqBQ,mBAAmBN;oBAClBC,wBAAwBH,eAAeC;EADxCO,QAAAA,EAEPL,uBACZ,CADoCH,WACpC,EAAA,EADmDC,QACnD,CAAA;CAAA,CAAA;AAF4CD,KAGlCQ,iBAAAA,GAHkCR,OAGPQ,iBAHOR;;AAAxBG,cAKDM,8BALCN,EAAAA,GAAAA,GAKqCD,cALrCC,CAAAA;EAAuB,QACPH,EAKxBG,uBALwBH,CAKAA,WALAA,EAAAA,EAKeC,QALfD,CAAAA;CAAW,CAAA;;cAQnCU,0BAV0BR,EAAAA;AAAc;AAItD,UAQUS,MAREH,CAAAA,MAAAA,EAAiB,GAAA,CAAA,GAQGG,MAROH,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,GAAiB,GAQEN,cARF,CAAA;EAEnCO,kBAAAA,EAOGL,SAPHK,CAOaG,CAPbH,CAAAA;EAEnB,QAAA,EAMYN,uBANZ,CAMoCH,WANpC,EAAA,EAMmDC,QANnD,CAAA;CAAA,CAAA;;;;AAIQU,KAUEG,oBAVFH,CAAAA,UAUiCA,MAVjCA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAUuDJ,uBAVvDI,CAAAA,GAUkFC,CAVlFD,SAU4FJ,uBAV5FI,GAUsHI,UAVtHJ,CAAAA,OAUwIF,8BAVxIE,CAAAA,GAU0KC,CAV1KD,SAUoLA,MAVpLA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAU0MI,UAV1MJ,CAAAA,OAU4ND,0BAV5NC,CAUuPC,CAVvPD,CAAAA,CAAAA,GAAAA,KAAAA;AAAsBA,KAWpBK,gBAXoBL,CAAAA,UAWOM,iBAXPN,GAW2BL,gBAX3BK,CAAAA,GAW+CO,CAX/CP,SAWyDM,iBAXzDN,GAW6EO,CAX7EP,GAWiFO,CAXjFP,SAW2FL,gBAX3FK,GAW8GT,cAX9GS,CAW6HN,2BAX7HM,CAWyJO,CAXzJP,CAAAA,CAAAA,GAAAA,KAAAA;;AACRP,KAYZa,iBAAAA,GAAoBf,cAZRE,CAAAA,GAAAA,CAAAA;;;;;AADgD;AAUxE"}
1
+ {"version":3,"file":"annotation.d.cts","names":["BaseMessage","Messages","AnnotationRoot","BinaryOperatorAggregate","LastValue","InteropZodToStateDefinition","InteropZodObject","ResponseFormatUndefined","PreHookAnnotation","createAgentBaseAnnotation","createAgentAnnotation","Record","T","createAgentAnnotationConditional","ReactAgentAnnotation","ReturnType","ToAnnotationRoot","AnyAnnotationRoot","A","enhanceStateSchemaWithMessageReducer"],"sources":["../../src/agents/annotation.d.ts"],"sourcesContent":["import { BaseMessage } from \"@langchain/core/messages\";\nimport { Messages, AnnotationRoot, type BinaryOperatorAggregate, type LastValue } from \"@langchain/langgraph\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport { type InteropZodObject } from \"@langchain/core/utils/types\";\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nexport declare const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\nexport type PreHookAnnotation = typeof PreHookAnnotation;\n// Base annotation without structuredResponse (for ResponseFormatUndefined)\nexport declare const createAgentBaseAnnotation: () => AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Full annotation with structuredResponse (for regular cases)\ndeclare const createAgentAnnotation: <\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{\n structuredResponse: LastValue<T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\nexport declare function createAgentAnnotationConditional<T extends Record<string, any> | ResponseFormatUndefined>(hasStructuredResponse?: boolean): AnnotationRoot<{\n structuredResponse: LastValue<T extends ResponseFormatUndefined ? never : T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Helper type to select the right annotation based on the response format type\nexport type ReactAgentAnnotation<T extends Record<string, any> | ResponseFormatUndefined> = T extends ResponseFormatUndefined ? ReturnType<typeof createAgentBaseAnnotation> : T extends Record<string, any> ? ReturnType<typeof createAgentAnnotation<T>> : never;\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n/**\n * Enhances a state schema to ensure proper message handling.\n * If a Zod schema is provided, it creates an annotation that includes the messagesStateReducer\n * and infers appropriate reducers for all other fields.\n *\n * @param stateSchema - The state schema to enhance.\n * @returns The enhanced state schema.\n */\nexport declare function enhanceStateSchemaWithMessageReducer(stateSchema: AnyAnnotationRoot | InteropZodObject): AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;\n}> | AnyAnnotationRoot;\nexport {};\n"],"mappings":";;;;;;;cAKqBQ,mBAAmBN;oBAClBC,wBAAwBH,eAAeC;EADxCO,QAAAA,EAEPL,uBACZ,CADoCH,WACpC,EAAA,EADmDC,QACnD,CAAA;CAAA,CAAA;AAF4CD,KAGlCQ,iBAAAA,GAHkCR,OAGPQ,iBAHOR;;AAAxBG,cAKDM,yBALCN,EAAAA,GAAAA,GAKgCD,cALhCC,CAAAA;EAAuB,QACPH,EAKxBG,uBALwBH,CAKAA,WALAA,EAAAA,EAKeC,QALfD,CAAAA;CAAW,CAAA;;cAQnCU,qBAV0BR,EAAAA;AAAc;AAItD,UAQUS,MAREH,CAAAA,MAAAA,EAAiB,GAAA,CAAA,GAQGG,MAROH,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,GAAiB,GAQEN,cARF,CAAA;EAEnCO,kBAAAA,EAOGL,SALtB,CAKgCQ,CALhC,CAAA;EAAA,QAAA,EAMYT,uBANZ,CAMoCH,WANpC,EAAA,EAMmDC,QANnD,CAAA;CAAA,CAAA;;;;AAIQU,KAUEG,oBAVFH,CAAAA,UAUiCA,MAVjCA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAUuDJ,uBAVvDI,CAAAA,GAUkFC,CAVlFD,SAU4FJ,uBAV5FI,GAUsHI,UAVtHJ,CAAAA,OAUwIF,yBAVxIE,CAAAA,GAUqKC,CAVrKD,SAU+KA,MAV/KA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAUqMI,UAVrMJ,CAAAA,OAUuND,qBAVvNC,CAU6OC,CAV7OD,CAAAA,CAAAA,GAAAA,KAAAA;AAAsBA,KAWpBK,gBAXoBL,CAAAA,UAWOM,iBAXPN,GAW2BL,gBAX3BK,CAAAA,GAW+CO,CAX/CP,SAWyDM,iBAXzDN,GAW6EO,CAX7EP,GAWiFO,CAXjFP,SAW2FL,gBAX3FK,GAW8GT,cAX9GS,CAW6HN,2BAX7HM,CAWyJO,CAXzJP,CAAAA,CAAAA,GAAAA,KAAAA;;AACRP,KAYZa,iBAAAA,GAAoBf,cAZRE,CAAAA,GAAAA,CAAAA;;;;;AADgD;AAUxE"}
@@ -11,11 +11,11 @@ declare const PreHookAnnotation: AnnotationRoot<{
11
11
  }>;
12
12
  type PreHookAnnotation = typeof PreHookAnnotation;
13
13
  // Base annotation without structuredResponse (for ResponseFormatUndefined)
14
- declare const createReactAgentBaseAnnotation: () => AnnotationRoot<{
14
+ declare const createAgentBaseAnnotation: () => AnnotationRoot<{
15
15
  messages: BinaryOperatorAggregate<BaseMessage[], Messages>;
16
16
  }>;
17
17
  // Full annotation with structuredResponse (for regular cases)
18
- declare const createReactAgentAnnotation: <
18
+ declare const createAgentAnnotation: <
19
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
20
  T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{
21
21
  structuredResponse: LastValue<T>;
@@ -24,7 +24,7 @@ T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{
24
24
  // Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse
25
25
 
26
26
  // Helper type to select the right annotation based on the response format type
27
- type ReactAgentAnnotation<T extends Record<string, any> | ResponseFormatUndefined> = T extends ResponseFormatUndefined ? ReturnType<typeof createReactAgentBaseAnnotation> : T extends Record<string, any> ? ReturnType<typeof createReactAgentAnnotation<T>> : never;
27
+ type ReactAgentAnnotation<T extends Record<string, any> | ResponseFormatUndefined> = T extends ResponseFormatUndefined ? ReturnType<typeof createAgentBaseAnnotation> : T extends Record<string, any> ? ReturnType<typeof createAgentAnnotation<T>> : never;
28
28
  type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;
29
29
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
30
  type AnyAnnotationRoot = AnnotationRoot<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"annotation.d.ts","names":["BaseMessage","Messages","AnnotationRoot","BinaryOperatorAggregate","LastValue","InteropZodToStateDefinition","InteropZodObject","ResponseFormatUndefined","PreHookAnnotation","createReactAgentBaseAnnotation","createReactAgentAnnotation","Record","T","createReactAgentAnnotationConditional","ReactAgentAnnotation","ReturnType","ToAnnotationRoot","AnyAnnotationRoot","A","enhanceStateSchemaWithMessageReducer"],"sources":["../../src/agents/annotation.d.ts"],"sourcesContent":["import { BaseMessage } from \"@langchain/core/messages\";\nimport { Messages, AnnotationRoot, type BinaryOperatorAggregate, type LastValue } from \"@langchain/langgraph\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport { type InteropZodObject } from \"@langchain/core/utils/types\";\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nexport declare const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\nexport type PreHookAnnotation = typeof PreHookAnnotation;\n// Base annotation without structuredResponse (for ResponseFormatUndefined)\nexport declare const createReactAgentBaseAnnotation: () => AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Full annotation with structuredResponse (for regular cases)\ndeclare const createReactAgentAnnotation: <\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{\n structuredResponse: LastValue<T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\nexport declare function createReactAgentAnnotationConditional<T extends Record<string, any> | ResponseFormatUndefined>(hasStructuredResponse?: boolean): AnnotationRoot<{\n structuredResponse: LastValue<T extends ResponseFormatUndefined ? never : T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Helper type to select the right annotation based on the response format type\nexport type ReactAgentAnnotation<T extends Record<string, any> | ResponseFormatUndefined> = T extends ResponseFormatUndefined ? ReturnType<typeof createReactAgentBaseAnnotation> : T extends Record<string, any> ? ReturnType<typeof createReactAgentAnnotation<T>> : never;\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n/**\n * Enhances a state schema to ensure proper message handling.\n * If a Zod schema is provided, it creates an annotation that includes the messagesStateReducer\n * and infers appropriate reducers for all other fields.\n *\n * @param stateSchema - The state schema to enhance.\n * @returns The enhanced state schema.\n */\nexport declare function enhanceStateSchemaWithMessageReducer(stateSchema: AnyAnnotationRoot | InteropZodObject): AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;\n}> | AnyAnnotationRoot;\nexport {};\n"],"mappings":";;;;;;;cAKqBQ,mBAAmBN;oBAClBC,wBAAwBH,eAAeC;EADxCO,QAAAA,EAEPL,uBACZ,CADoCH,WACpC,EAAA,EADmDC,QACnD,CAAA;CAAA,CAAA;AAF4CD,KAGlCQ,iBAAAA,GAHkCR,OAGPQ,iBAHOR;;AAAxBG,cAKDM,8BALCN,EAAAA,GAAAA,GAKqCD,cALrCC,CAAAA;EAAuB,QACPH,EAKxBG,uBALwBH,CAKAA,WALAA,EAAAA,EAKeC,QALfD,CAAAA;CAAW,CAAA;;cAQnCU,0BAV0BR,EAAAA;AAAc;AAItD,UAQUS,MAREH,CAAAA,MAAAA,EAAiB,GAAA,CAAA,GAQGG,MAROH,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,GAAiB,GAQEN,cARF,CAAA;EAEnCO,kBAAAA,EAOGL,SAPHK,CAOaG,CAPbH,CAAAA;EAEnB,QAAA,EAMYN,uBANZ,CAMoCH,WANpC,EAAA,EAMmDC,QANnD,CAAA;CAAA,CAAA;;;;AAIQU,KAUEG,oBAVFH,CAAAA,UAUiCA,MAVjCA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAUuDJ,uBAVvDI,CAAAA,GAUkFC,CAVlFD,SAU4FJ,uBAV5FI,GAUsHI,UAVtHJ,CAAAA,OAUwIF,8BAVxIE,CAAAA,GAU0KC,CAV1KD,SAUoLA,MAVpLA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAU0MI,UAV1MJ,CAAAA,OAU4ND,0BAV5NC,CAUuPC,CAVvPD,CAAAA,CAAAA,GAAAA,KAAAA;AAAsBA,KAWpBK,gBAXoBL,CAAAA,UAWOM,iBAXPN,GAW2BL,gBAX3BK,CAAAA,GAW+CO,CAX/CP,SAWyDM,iBAXzDN,GAW6EO,CAX7EP,GAWiFO,CAXjFP,SAW2FL,gBAX3FK,GAW8GT,cAX9GS,CAW6HN,2BAX7HM,CAWyJO,CAXzJP,CAAAA,CAAAA,GAAAA,KAAAA;;AACRP,KAYZa,iBAAAA,GAAoBf,cAZRE,CAAAA,GAAAA,CAAAA;;;;;AADgD;AAUxE"}
1
+ {"version":3,"file":"annotation.d.ts","names":["BaseMessage","Messages","AnnotationRoot","BinaryOperatorAggregate","LastValue","InteropZodToStateDefinition","InteropZodObject","ResponseFormatUndefined","PreHookAnnotation","createAgentBaseAnnotation","createAgentAnnotation","Record","T","createAgentAnnotationConditional","ReactAgentAnnotation","ReturnType","ToAnnotationRoot","AnyAnnotationRoot","A","enhanceStateSchemaWithMessageReducer"],"sources":["../../src/agents/annotation.d.ts"],"sourcesContent":["import { BaseMessage } from \"@langchain/core/messages\";\nimport { Messages, AnnotationRoot, type BinaryOperatorAggregate, type LastValue } from \"@langchain/langgraph\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport { type InteropZodObject } from \"@langchain/core/utils/types\";\nimport type { ResponseFormatUndefined } from \"./responses.js\";\nexport declare const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\nexport type PreHookAnnotation = typeof PreHookAnnotation;\n// Base annotation without structuredResponse (for ResponseFormatUndefined)\nexport declare const createAgentBaseAnnotation: () => AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Full annotation with structuredResponse (for regular cases)\ndeclare const createAgentAnnotation: <\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{\n structuredResponse: LastValue<T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\nexport declare function createAgentAnnotationConditional<T extends Record<string, any> | ResponseFormatUndefined>(hasStructuredResponse?: boolean): AnnotationRoot<{\n structuredResponse: LastValue<T extends ResponseFormatUndefined ? never : T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>;\n// Helper type to select the right annotation based on the response format type\nexport type ReactAgentAnnotation<T extends Record<string, any> | ResponseFormatUndefined> = T extends ResponseFormatUndefined ? ReturnType<typeof createAgentBaseAnnotation> : T extends Record<string, any> ? ReturnType<typeof createAgentAnnotation<T>> : never;\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n/**\n * Enhances a state schema to ensure proper message handling.\n * If a Zod schema is provided, it creates an annotation that includes the messagesStateReducer\n * and infers appropriate reducers for all other fields.\n *\n * @param stateSchema - The state schema to enhance.\n * @returns The enhanced state schema.\n */\nexport declare function enhanceStateSchemaWithMessageReducer(stateSchema: AnyAnnotationRoot | InteropZodObject): AnnotationRoot<{\n messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;\n}> | AnyAnnotationRoot;\nexport {};\n"],"mappings":";;;;;;;cAKqBQ,mBAAmBN;oBAClBC,wBAAwBH,eAAeC;EADxCO,QAAAA,EAEPL,uBACZ,CADoCH,WACpC,EAAA,EADmDC,QACnD,CAAA;CAAA,CAAA;AAF4CD,KAGlCQ,iBAAAA,GAHkCR,OAGPQ,iBAHOR;;AAAxBG,cAKDM,yBALCN,EAAAA,GAAAA,GAKgCD,cALhCC,CAAAA;EAAuB,QACPH,EAKxBG,uBALwBH,CAKAA,WALAA,EAAAA,EAKeC,QALfD,CAAAA;CAAW,CAAA;;cAQnCU,qBAV0BR,EAAAA;AAAc;AAItD,UAQUS,MAREH,CAAAA,MAAAA,EAAiB,GAAA,CAAA,GAQGG,MAROH,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,GAAiB,GAQEN,cARF,CAAA;EAEnCO,kBAAAA,EAOGL,SALtB,CAKgCQ,CALhC,CAAA;EAAA,QAAA,EAMYT,uBANZ,CAMoCH,WANpC,EAAA,EAMmDC,QANnD,CAAA;CAAA,CAAA;;;;AAIQU,KAUEG,oBAVFH,CAAAA,UAUiCA,MAVjCA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAUuDJ,uBAVvDI,CAAAA,GAUkFC,CAVlFD,SAU4FJ,uBAV5FI,GAUsHI,UAVtHJ,CAAAA,OAUwIF,yBAVxIE,CAAAA,GAUqKC,CAVrKD,SAU+KA,MAV/KA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAUqMI,UAVrMJ,CAAAA,OAUuND,qBAVvNC,CAU6OC,CAV7OD,CAAAA,CAAAA,GAAAA,KAAAA;AAAsBA,KAWpBK,gBAXoBL,CAAAA,UAWOM,iBAXPN,GAW2BL,gBAX3BK,CAAAA,GAW+CO,CAX/CP,SAWyDM,iBAXzDN,GAW6EO,CAX7EP,GAWiFO,CAXjFP,SAW2FL,gBAX3FK,GAW8GT,cAX9GS,CAW6HN,2BAX7HM,CAWyJO,CAXzJP,CAAAA,CAAAA,GAAAA,KAAAA;;AACRP,KAYZa,iBAAAA,GAAoBf,cAZRE,CAAAA,GAAAA,CAAAA;;;;;AADgD;AAUxE"}
@@ -12,7 +12,7 @@ const PreHookAnnotation = Annotation.Root({
12
12
  default: () => []
13
13
  })
14
14
  });
15
- function createReactAgentAnnotationConditional(hasStructuredResponse = true) {
15
+ function createAgentAnnotationConditional(hasStructuredResponse = true) {
16
16
  const baseAnnotation = { messages: Annotation({
17
17
  reducer: messagesStateReducer,
18
18
  default: () => []
@@ -143,5 +143,5 @@ function createAnnotationForZodType(zodType) {
143
143
  }
144
144
 
145
145
  //#endregion
146
- export { createReactAgentAnnotationConditional, enhanceStateSchemaWithMessageReducer };
146
+ export { createAgentAnnotationConditional, enhanceStateSchemaWithMessageReducer };
147
147
  //# sourceMappingURL=annotation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotation.js","names":["PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>","stateSchema: AnyAnnotationRoot | InteropZodObject","annotationFields: Record<string, any>","_: unknown","update: unknown","current: unknown[]","update: unknown[]","config: (typeof ZOD_TYPE_CONFIGS)[keyof typeof ZOD_TYPE_CONFIGS]","defaultValueFn: () => unknown","zodType: any","config"],"sources":["../../src/agents/annotation.ts"],"sourcesContent":["import { BaseMessage } from \"@langchain/core/messages\";\nimport {\n Annotation,\n Messages,\n AnnotationRoot,\n messagesStateReducer,\n type BinaryOperatorAggregate,\n type LastValue,\n} from \"@langchain/langgraph\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport {\n isInteropZodSchema,\n getInteropZodObjectShape,\n getInteropZodDefaultGetter,\n type InteropZodObject,\n} from \"@langchain/core/utils/types\";\nimport type { ResponseFormatUndefined } from \"./responses.js\";\n\nexport const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}> = Annotation.Root({\n llmInputMessages: Annotation<BaseMessage[], Messages>({\n reducer: (_, update) => messagesStateReducer([], update),\n default: () => [],\n }),\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n});\nexport type PreHookAnnotation = typeof PreHookAnnotation;\n\n// Base annotation without structuredResponse (for ResponseFormatUndefined)\nexport const createReactAgentBaseAnnotation = () =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n });\n\n// Full annotation with structuredResponse (for regular cases)\nconst createReactAgentAnnotation = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n>(): AnnotationRoot<{\n structuredResponse: LastValue<T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}> =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n structuredResponse: Annotation<T>(),\n });\n\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\nexport function createReactAgentAnnotationConditional<\n T extends Record<string, any> | ResponseFormatUndefined\n>(\n hasStructuredResponse = true\n): AnnotationRoot<{\n structuredResponse: LastValue<T extends ResponseFormatUndefined ? never : T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}> {\n const baseAnnotation = {\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n };\n\n if (!hasStructuredResponse) {\n return Annotation.Root(baseAnnotation) as AnnotationRoot<{\n structuredResponse: LastValue<\n T extends ResponseFormatUndefined ? never : T\n >;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n }>;\n }\n\n return Annotation.Root({\n ...baseAnnotation,\n structuredResponse:\n Annotation<T extends ResponseFormatUndefined ? never : T>(),\n });\n}\n\n// Helper type to select the right annotation based on the response format type\nexport type ReactAgentAnnotation<\n T extends Record<string, any> | ResponseFormatUndefined\n> = T extends ResponseFormatUndefined\n ? ReturnType<typeof createReactAgentBaseAnnotation>\n : T extends Record<string, any>\n ? ReturnType<typeof createReactAgentAnnotation<T>>\n : never;\n\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? AnnotationRoot<InteropZodToStateDefinition<A>>\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n\n/**\n * Enhances a state schema to ensure proper message handling.\n * If a Zod schema is provided, it creates an annotation that includes the messagesStateReducer\n * and infers appropriate reducers for all other fields.\n *\n * @param stateSchema - The state schema to enhance.\n * @returns The enhanced state schema.\n */\nexport function enhanceStateSchemaWithMessageReducer(\n stateSchema: AnyAnnotationRoot | InteropZodObject\n) {\n /**\n * If it's already an annotation, return as-is\n */\n if (typeof stateSchema === \"object\" && \"State\" in stateSchema) {\n return stateSchema;\n }\n\n /**\n * If it's a Zod schema, create annotations for all fields\n */\n if (isInteropZodSchema(stateSchema)) {\n const shape = getInteropZodObjectShape(stateSchema);\n const annotationFields: Record<string, any> = {};\n\n /**\n * Process each field in the Zod schema\n */\n for (const [key, zodType] of Object.entries(shape)) {\n annotationFields[key] =\n key === \"messages\"\n ? /**\n * Special handling for messages field - always use messagesStateReducer\n */\n Annotation<BaseMessage[]>({\n reducer: messagesStateReducer,\n default: () => [],\n })\n : /**\n * For other fields, create appropriate annotations based on type\n */\n createAnnotationForZodType(zodType);\n }\n\n /**\n * Ensure messages field exists even if not in the Zod schema\n */\n if (!annotationFields.messages) {\n annotationFields.messages = Annotation<BaseMessage[]>({\n reducer: messagesStateReducer,\n default: () => [],\n });\n }\n\n return Annotation.Root(annotationFields);\n }\n\n /**\n * Fallback: create a base annotation with message reducer only\n */\n return Annotation.Root({\n messages: Annotation<BaseMessage[]>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n });\n}\n\n/**\n * Type configuration for different Zod types\n */\nconst ZOD_TYPE_CONFIGS = {\n ZodString: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: \"\",\n },\n ZodNumber: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: 0,\n },\n ZodBoolean: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: false,\n },\n ZodArray: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: [] as unknown[],\n },\n ZodRecord: {\n reducer: (current: unknown[], update: unknown[]) => ({\n ...current,\n ...update,\n }),\n fallbackDefault: {} as Record<string, unknown>,\n },\n ZodObject: {\n reducer: (current: unknown[], update: unknown[]) => ({\n ...current,\n ...update,\n }),\n fallbackDefault: {} as Record<string, unknown>,\n },\n} as const;\n\n/**\n * Creates an annotation based on type configuration and default value\n */\nfunction createAnnotationFromConfig(\n config: (typeof ZOD_TYPE_CONFIGS)[keyof typeof ZOD_TYPE_CONFIGS],\n defaultValueFn: () => unknown\n) {\n return Annotation<any>({\n reducer: config.reducer,\n default: defaultValueFn,\n });\n}\n\n/**\n * Creates an appropriate annotation for a given Zod type.\n */\nfunction createAnnotationForZodType(zodType: any): any {\n const typeName = zodType._def?.typeName;\n const defaultGetter = getInteropZodDefaultGetter(zodType);\n const isOptional = typeName === \"ZodOptional\";\n\n /**\n * Handle Zod wrapper first\n */\n if (\n typeName === \"ZodDefault\" ||\n typeName === \"ZodOptional\" ||\n typeName === \"ZodNullable\"\n ) {\n const innerTypeName = zodType._def.innerType._def?.typeName;\n const config =\n ZOD_TYPE_CONFIGS[innerTypeName as keyof typeof ZOD_TYPE_CONFIGS];\n return config\n ? createAnnotationFromConfig(\n config,\n () =>\n defaultGetter?.() ||\n (isOptional ? undefined : config?.fallbackDefault)\n )\n : Annotation<unknown>({\n reducer: (_: unknown, update: unknown) => update,\n default: () => defaultGetter?.(),\n });\n }\n\n /**\n * Handle regular types\n */\n const config = ZOD_TYPE_CONFIGS[typeName as keyof typeof ZOD_TYPE_CONFIGS];\n if (config) {\n return createAnnotationFromConfig(\n config,\n () => defaultGetter?.() || config?.fallbackDefault\n );\n }\n\n /**\n * Fallback for unknown types\n */\n return Annotation<unknown>({\n reducer: (_: unknown, update: unknown) => update,\n default: () => defaultGetter?.(),\n });\n}\n"],"mappings":";;;;AAkBA,MAAaA,oBAGR,WAAW,KAAK;CACnB,kBAAkB,WAAoC;EACpD,SAAS,CAAC,GAAG,WAAW,qBAAqB,CAAE,GAAE,OAAO;EACxD,SAAS,MAAM,CAAE;CAClB,EAAC;CACF,UAAU,WAAoC;EAC5C,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC;AACH,EAAC;AA6BF,SAAgB,sCAGd,wBAAwB,MAIvB;CACD,MAAM,iBAAiB,EACrB,UAAU,WAAoC;EAC5C,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH;AAED,KAAI,CAAC,sBACH,QAAO,WAAW,KAAK,eAAe;AAQxC,QAAO,WAAW,KAAK;EACrB,GAAG;EACH,oBACE,YAA2D;CAC9D,EAAC;AACH;;;;;;;;;AA6BD,SAAgB,qCACdC,aACA;;;;AAIA,KAAI,OAAO,gBAAgB,YAAY,WAAW,YAChD,QAAO;;;;AAMT,KAAI,mBAAmB,YAAY,EAAE;EACnC,MAAM,QAAQ,yBAAyB,YAAY;EACnD,MAAMC,mBAAwC,CAAE;;;;AAKhD,OAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,MAAM,EAChD,iBAAiB,OACf,QAAQ,aAIJ,WAA0B;GACxB,SAAS;GACT,SAAS,MAAM,CAAE;EAClB,EAAC,GAIF,2BAA2B,QAAQ;;;;AAM3C,MAAI,CAAC,iBAAiB,UACpB,iBAAiB,WAAW,WAA0B;GACpD,SAAS;GACT,SAAS,MAAM,CAAE;EAClB,EAAC;AAGJ,SAAO,WAAW,KAAK,iBAAiB;CACzC;;;;AAKD,QAAO,WAAW,KAAK,EACrB,UAAU,WAA0B;EAClC,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH,EAAC;AACH;;;;AAKD,MAAM,mBAAmB;CACvB,WAAW;EACT,SAAS,CAACC,GAAYC,WAAoB;EAC1C,iBAAiB;CAClB;CACD,WAAW;EACT,SAAS,CAACD,GAAYC,WAAoB;EAC1C,iBAAiB;CAClB;CACD,YAAY;EACV,SAAS,CAACD,GAAYC,WAAoB;EAC1C,iBAAiB;CAClB;CACD,UAAU;EACR,SAAS,CAACD,GAAYC,WAAoB;EAC1C,iBAAiB,CAAE;CACpB;CACD,WAAW;EACT,SAAS,CAACC,SAAoBC,YAAuB;GACnD,GAAG;GACH,GAAG;EACJ;EACD,iBAAiB,CAAE;CACpB;CACD,WAAW;EACT,SAAS,CAACD,SAAoBC,YAAuB;GACnD,GAAG;GACH,GAAG;EACJ;EACD,iBAAiB,CAAE;CACpB;AACF;;;;AAKD,SAAS,2BACPC,QACAC,gBACA;AACA,QAAO,WAAgB;EACrB,SAAS,OAAO;EAChB,SAAS;CACV,EAAC;AACH;;;;AAKD,SAAS,2BAA2BC,SAAmB;CACrD,MAAM,WAAW,QAAQ,MAAM;CAC/B,MAAM,gBAAgB,2BAA2B,QAAQ;CACzD,MAAM,aAAa,aAAa;;;;AAKhC,KACE,aAAa,gBACb,aAAa,iBACb,aAAa,eACb;EACA,MAAM,gBAAgB,QAAQ,KAAK,UAAU,MAAM;EACnD,MAAMC,WACJ,iBAAiB;AACnB,SAAOA,WACH,2BACEA,UACA,MACE,iBAAiB,KAChB,aAAa,SAAYA,UAAQ,iBACrC,GACD,WAAoB;GAClB,SAAS,CAACP,GAAYC,WAAoB;GAC1C,SAAS,MAAM,iBAAiB;EACjC,EAAC;CACP;;;;CAKD,MAAM,SAAS,iBAAiB;AAChC,KAAI,OACF,QAAO,2BACL,QACA,MAAM,iBAAiB,IAAI,QAAQ,gBACpC;;;;AAMH,QAAO,WAAoB;EACzB,SAAS,CAACD,GAAYC,WAAoB;EAC1C,SAAS,MAAM,iBAAiB;CACjC,EAAC;AACH"}
1
+ {"version":3,"file":"annotation.js","names":["PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}>","stateSchema: AnyAnnotationRoot | InteropZodObject","annotationFields: Record<string, any>","_: unknown","update: unknown","current: unknown[]","update: unknown[]","config: (typeof ZOD_TYPE_CONFIGS)[keyof typeof ZOD_TYPE_CONFIGS]","defaultValueFn: () => unknown","zodType: any","config"],"sources":["../../src/agents/annotation.ts"],"sourcesContent":["import { BaseMessage } from \"@langchain/core/messages\";\nimport {\n Annotation,\n Messages,\n AnnotationRoot,\n messagesStateReducer,\n type BinaryOperatorAggregate,\n type LastValue,\n} from \"@langchain/langgraph\";\nimport type { InteropZodToStateDefinition } from \"@langchain/langgraph/zod\";\nimport {\n isInteropZodSchema,\n getInteropZodObjectShape,\n getInteropZodDefaultGetter,\n type InteropZodObject,\n} from \"@langchain/core/utils/types\";\nimport type { ResponseFormatUndefined } from \"./responses.js\";\n\nexport const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}> = Annotation.Root({\n llmInputMessages: Annotation<BaseMessage[], Messages>({\n reducer: (_, update) => messagesStateReducer([], update),\n default: () => [],\n }),\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n});\nexport type PreHookAnnotation = typeof PreHookAnnotation;\n\n// Base annotation without structuredResponse (for ResponseFormatUndefined)\nexport const createAgentBaseAnnotation = () =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n });\n\n// Full annotation with structuredResponse (for regular cases)\nconst createAgentAnnotation = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n>(): AnnotationRoot<{\n structuredResponse: LastValue<T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}> =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n structuredResponse: Annotation<T>(),\n });\n\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\nexport function createAgentAnnotationConditional<\n T extends Record<string, any> | ResponseFormatUndefined\n>(\n hasStructuredResponse = true\n): AnnotationRoot<{\n structuredResponse: LastValue<T extends ResponseFormatUndefined ? never : T>;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n}> {\n const baseAnnotation = {\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n };\n\n if (!hasStructuredResponse) {\n return Annotation.Root(baseAnnotation) as AnnotationRoot<{\n structuredResponse: LastValue<\n T extends ResponseFormatUndefined ? never : T\n >;\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n }>;\n }\n\n return Annotation.Root({\n ...baseAnnotation,\n structuredResponse:\n Annotation<T extends ResponseFormatUndefined ? never : T>(),\n });\n}\n\n// Helper type to select the right annotation based on the response format type\nexport type ReactAgentAnnotation<\n T extends Record<string, any> | ResponseFormatUndefined\n> = T extends ResponseFormatUndefined\n ? ReturnType<typeof createAgentBaseAnnotation>\n : T extends Record<string, any>\n ? ReturnType<typeof createAgentAnnotation<T>>\n : never;\n\nexport type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? AnnotationRoot<InteropZodToStateDefinition<A>>\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyAnnotationRoot = AnnotationRoot<any>;\n\n/**\n * Enhances a state schema to ensure proper message handling.\n * If a Zod schema is provided, it creates an annotation that includes the messagesStateReducer\n * and infers appropriate reducers for all other fields.\n *\n * @param stateSchema - The state schema to enhance.\n * @returns The enhanced state schema.\n */\nexport function enhanceStateSchemaWithMessageReducer(\n stateSchema: AnyAnnotationRoot | InteropZodObject\n) {\n /**\n * If it's already an annotation, return as-is\n */\n if (typeof stateSchema === \"object\" && \"State\" in stateSchema) {\n return stateSchema;\n }\n\n /**\n * If it's a Zod schema, create annotations for all fields\n */\n if (isInteropZodSchema(stateSchema)) {\n const shape = getInteropZodObjectShape(stateSchema);\n const annotationFields: Record<string, any> = {};\n\n /**\n * Process each field in the Zod schema\n */\n for (const [key, zodType] of Object.entries(shape)) {\n annotationFields[key] =\n key === \"messages\"\n ? /**\n * Special handling for messages field - always use messagesStateReducer\n */\n Annotation<BaseMessage[]>({\n reducer: messagesStateReducer,\n default: () => [],\n })\n : /**\n * For other fields, create appropriate annotations based on type\n */\n createAnnotationForZodType(zodType);\n }\n\n /**\n * Ensure messages field exists even if not in the Zod schema\n */\n if (!annotationFields.messages) {\n annotationFields.messages = Annotation<BaseMessage[]>({\n reducer: messagesStateReducer,\n default: () => [],\n });\n }\n\n return Annotation.Root(annotationFields);\n }\n\n /**\n * Fallback: create a base annotation with message reducer only\n */\n return Annotation.Root({\n messages: Annotation<BaseMessage[]>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n });\n}\n\n/**\n * Type configuration for different Zod types\n */\nconst ZOD_TYPE_CONFIGS = {\n ZodString: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: \"\",\n },\n ZodNumber: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: 0,\n },\n ZodBoolean: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: false,\n },\n ZodArray: {\n reducer: (_: unknown, update: unknown) => update,\n fallbackDefault: [] as unknown[],\n },\n ZodRecord: {\n reducer: (current: unknown[], update: unknown[]) => ({\n ...current,\n ...update,\n }),\n fallbackDefault: {} as Record<string, unknown>,\n },\n ZodObject: {\n reducer: (current: unknown[], update: unknown[]) => ({\n ...current,\n ...update,\n }),\n fallbackDefault: {} as Record<string, unknown>,\n },\n} as const;\n\n/**\n * Creates an annotation based on type configuration and default value\n */\nfunction createAnnotationFromConfig(\n config: (typeof ZOD_TYPE_CONFIGS)[keyof typeof ZOD_TYPE_CONFIGS],\n defaultValueFn: () => unknown\n) {\n return Annotation<any>({\n reducer: config.reducer,\n default: defaultValueFn,\n });\n}\n\n/**\n * Creates an appropriate annotation for a given Zod type.\n */\nfunction createAnnotationForZodType(zodType: any): any {\n const typeName = zodType._def?.typeName;\n const defaultGetter = getInteropZodDefaultGetter(zodType);\n const isOptional = typeName === \"ZodOptional\";\n\n /**\n * Handle Zod wrapper first\n */\n if (\n typeName === \"ZodDefault\" ||\n typeName === \"ZodOptional\" ||\n typeName === \"ZodNullable\"\n ) {\n const innerTypeName = zodType._def.innerType._def?.typeName;\n const config =\n ZOD_TYPE_CONFIGS[innerTypeName as keyof typeof ZOD_TYPE_CONFIGS];\n return config\n ? createAnnotationFromConfig(\n config,\n () =>\n defaultGetter?.() ||\n (isOptional ? undefined : config?.fallbackDefault)\n )\n : Annotation<unknown>({\n reducer: (_: unknown, update: unknown) => update,\n default: () => defaultGetter?.(),\n });\n }\n\n /**\n * Handle regular types\n */\n const config = ZOD_TYPE_CONFIGS[typeName as keyof typeof ZOD_TYPE_CONFIGS];\n if (config) {\n return createAnnotationFromConfig(\n config,\n () => defaultGetter?.() || config?.fallbackDefault\n );\n }\n\n /**\n * Fallback for unknown types\n */\n return Annotation<unknown>({\n reducer: (_: unknown, update: unknown) => update,\n default: () => defaultGetter?.(),\n });\n}\n"],"mappings":";;;;AAkBA,MAAaA,oBAGR,WAAW,KAAK;CACnB,kBAAkB,WAAoC;EACpD,SAAS,CAAC,GAAG,WAAW,qBAAqB,CAAE,GAAE,OAAO;EACxD,SAAS,MAAM,CAAE;CAClB,EAAC;CACF,UAAU,WAAoC;EAC5C,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC;AACH,EAAC;AA6BF,SAAgB,iCAGd,wBAAwB,MAIvB;CACD,MAAM,iBAAiB,EACrB,UAAU,WAAoC;EAC5C,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH;AAED,KAAI,CAAC,sBACH,QAAO,WAAW,KAAK,eAAe;AAQxC,QAAO,WAAW,KAAK;EACrB,GAAG;EACH,oBACE,YAA2D;CAC9D,EAAC;AACH;;;;;;;;;AA6BD,SAAgB,qCACdC,aACA;;;;AAIA,KAAI,OAAO,gBAAgB,YAAY,WAAW,YAChD,QAAO;;;;AAMT,KAAI,mBAAmB,YAAY,EAAE;EACnC,MAAM,QAAQ,yBAAyB,YAAY;EACnD,MAAMC,mBAAwC,CAAE;;;;AAKhD,OAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,MAAM,EAChD,iBAAiB,OACf,QAAQ,aAIJ,WAA0B;GACxB,SAAS;GACT,SAAS,MAAM,CAAE;EAClB,EAAC,GAIF,2BAA2B,QAAQ;;;;AAM3C,MAAI,CAAC,iBAAiB,UACpB,iBAAiB,WAAW,WAA0B;GACpD,SAAS;GACT,SAAS,MAAM,CAAE;EAClB,EAAC;AAGJ,SAAO,WAAW,KAAK,iBAAiB;CACzC;;;;AAKD,QAAO,WAAW,KAAK,EACrB,UAAU,WAA0B;EAClC,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH,EAAC;AACH;;;;AAKD,MAAM,mBAAmB;CACvB,WAAW;EACT,SAAS,CAACC,GAAYC,WAAoB;EAC1C,iBAAiB;CAClB;CACD,WAAW;EACT,SAAS,CAACD,GAAYC,WAAoB;EAC1C,iBAAiB;CAClB;CACD,YAAY;EACV,SAAS,CAACD,GAAYC,WAAoB;EAC1C,iBAAiB;CAClB;CACD,UAAU;EACR,SAAS,CAACD,GAAYC,WAAoB;EAC1C,iBAAiB,CAAE;CACpB;CACD,WAAW;EACT,SAAS,CAACC,SAAoBC,YAAuB;GACnD,GAAG;GACH,GAAG;EACJ;EACD,iBAAiB,CAAE;CACpB;CACD,WAAW;EACT,SAAS,CAACD,SAAoBC,YAAuB;GACnD,GAAG;GACH,GAAG;EACJ;EACD,iBAAiB,CAAE;CACpB;AACF;;;;AAKD,SAAS,2BACPC,QACAC,gBACA;AACA,QAAO,WAAgB;EACrB,SAAS,OAAO;EAChB,SAAS;CACV,EAAC;AACH;;;;AAKD,SAAS,2BAA2BC,SAAmB;CACrD,MAAM,WAAW,QAAQ,MAAM;CAC/B,MAAM,gBAAgB,2BAA2B,QAAQ;CACzD,MAAM,aAAa,aAAa;;;;AAKhC,KACE,aAAa,gBACb,aAAa,iBACb,aAAa,eACb;EACA,MAAM,gBAAgB,QAAQ,KAAK,UAAU,MAAM;EACnD,MAAMC,WACJ,iBAAiB;AACnB,SAAOA,WACH,2BACEA,UACA,MACE,iBAAiB,KAChB,aAAa,SAAYA,UAAQ,iBACrC,GACD,WAAoB;GAClB,SAAS,CAACP,GAAYC,WAAoB;GAC1C,SAAS,MAAM,iBAAiB;EACjC,EAAC;CACP;;;;CAKD,MAAM,SAAS,iBAAiB;AAChC,KAAI,OACF,QAAO,2BACL,QACA,MAAM,iBAAiB,IAAI,QAAQ,gBACpC;;;;AAMH,QAAO,WAAoB;EACzB,SAAS,CAACD,GAAYC,WAAoB;EAC1C,SAAS,MAAM,iBAAiB;CACjC,EAAC;AACH"}
@@ -0,0 +1,10 @@
1
+ const require_ReactAgent = require('./ReactAgent.cjs');
2
+
3
+ //#region src/agents/createAgent.ts
4
+ function createAgent(params) {
5
+ return new require_ReactAgent.ReactAgent(params);
6
+ }
7
+
8
+ //#endregion
9
+ exports.createAgent = createAgent;
10
+ //# sourceMappingURL=createAgent.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAgent.cjs","names":["params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n >","ReactAgent"],"sources":["../../src/agents/createAgent.ts"],"sourcesContent":["import type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { MessagesAnnotation } from \"@langchain/langgraph\";\n\nimport { type AnyAnnotationRoot } from \"./annotation.js\";\nimport type { CreateAgentParams, ExtractZodArrayTypes } from \"./types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n InteropZodType<T>\n > & {\n responseFormat: InteropZodType<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n }\n): ReactAgent<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n TypedToolStrategy<T>\n > & {\n responseFormat: TypedToolStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<StateSchema, T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n ProviderStrategy<T>\n > & {\n responseFormat: ProviderStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 8: Without responseFormat property at all\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n >\n): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n }\n): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n }\n): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema>;\n\n// Implementation\nexport function createAgent<\n StateSchema extends AnyAnnotationRoot | InteropZodObject,\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject\n>(\n params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n >\n): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema> {\n return new ReactAgent(params);\n}\n"],"mappings":";;;AAqQA,SAAgB,YAKdA,QAMkE;AAClE,QAAO,IAAIC,8BAAW;AACvB"}
@@ -0,0 +1,10 @@
1
+ import { ReactAgent } from "./ReactAgent.js";
2
+
3
+ //#region src/agents/createAgent.ts
4
+ function createAgent(params) {
5
+ return new ReactAgent(params);
6
+ }
7
+
8
+ //#endregion
9
+ export { createAgent };
10
+ //# sourceMappingURL=createAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAgent.js","names":["params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n >"],"sources":["../../src/agents/createAgent.ts"],"sourcesContent":["import type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { MessagesAnnotation } from \"@langchain/langgraph\";\n\nimport { type AnyAnnotationRoot } from \"./annotation.js\";\nimport type { CreateAgentParams, ExtractZodArrayTypes } from \"./types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n InteropZodType<T>\n > & {\n responseFormat: InteropZodType<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n }\n): ReactAgent<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n TypedToolStrategy<T>\n > & {\n responseFormat: TypedToolStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<StateSchema, T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n ProviderStrategy<T>\n > & {\n responseFormat: ProviderStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 8: Without responseFormat property at all\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n >\n): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n }\n): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n }\n): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema>;\n\n// Implementation\nexport function createAgent<\n StateSchema extends AnyAnnotationRoot | InteropZodObject,\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject\n>(\n params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n >\n): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema> {\n return new ReactAgent(params);\n}\n"],"mappings":";;;AAqQA,SAAgB,YAKdA,QAMkE;AAClE,QAAO,IAAI,WAAW;AACvB"}
@@ -2,7 +2,7 @@
2
2
  //#region src/agents/errors.ts
3
3
  var MultipleToolsBoundError = class extends Error {
4
4
  constructor() {
5
- super("The provided LLM already has bound tools. Please provide an LLM without bound tools to createReactAgent. The agent will bind the tools provided in the 'tools' parameter.");
5
+ super("The provided LLM already has bound tools. Please provide an LLM without bound tools to createAgent. The agent will bind the tools provided in the 'tools' parameter.");
6
6
  }
7
7
  };
8
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":["toolNames: string[]","toolName: string","errors: string[]","toolError: unknown","toolCall: ToolCall"],"sources":["../../src/agents/errors.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\n\nexport class MultipleToolsBoundError extends Error {\n constructor() {\n super(\n \"The provided LLM already has bound tools. \" +\n \"Please provide an LLM without bound tools to createReactAgent. \" +\n \"The agent will bind the tools provided in the 'tools' parameter.\"\n );\n }\n}\n\n/**\n * Raised when model returns multiple structured output tool calls when only one is expected.\n */\nexport class MultipleStructuredOutputsError extends Error {\n public readonly toolNames: string[];\n\n constructor(toolNames: string[]) {\n super(\n `The model has called multiple tools: ${toolNames.join(\n \", \"\n )} to return a structured output. ` +\n \"This is not supported. Please provide a single structured output.\"\n );\n this.toolNames = toolNames;\n }\n}\n\n/**\n * Raised when structured output tool call arguments fail to parse according to the schema.\n */\nexport class StructuredOutputParsingError extends Error {\n public readonly toolName: string;\n\n public readonly errors: string[];\n\n constructor(toolName: string, errors: string[]) {\n super(\n `Failed to parse structured output for tool '${toolName}':${errors\n .map((e) => `\\n - ${e}`)\n .join(\"\")}.`\n );\n this.toolName = toolName;\n this.errors = errors;\n }\n}\n\n/**\n * Raised when a tool call is throwing an error.\n */\nexport class ToolInvocationError extends Error {\n public readonly toolCall: ToolCall;\n\n public readonly toolError: Error;\n\n constructor(toolError: unknown, toolCall: ToolCall) {\n const error =\n toolError instanceof Error ? toolError : new Error(String(toolError));\n super(\n `Error invoking tool '${toolCall.name}' with kwargs ${JSON.stringify(\n toolCall.args\n )} ` +\n `with error:\\n ${error.stack}\\n Please fix the error and try again.`\n );\n\n this.toolCall = toolCall;\n this.toolError = error;\n }\n}\n"],"mappings":";;AAGA,IAAa,0BAAb,cAA6C,MAAM;CACjD,cAAc;EACZ,MACE,4KAGD;CACF;AACF;;;;AAKD,IAAa,iCAAb,cAAoD,MAAM;CACxD,AAAgB;CAEhB,YAAYA,WAAqB;EAC/B,MACE,CAAC,qCAAqC,EAAE,UAAU,KAChD,KACD,CAAC,iGAAgC,CACmC,CACtE;EACD,KAAK,YAAY;CAClB;AACF;;;;AAKD,IAAa,+BAAb,cAAkD,MAAM;CACtD,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,UAAkBC,QAAkB;EAC9C,MACE,CAAC,4CAA4C,EAAE,SAAS,EAAE,EAAE,OACzD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACxB,KAAK,GAAG,CAAC,CAAC,CAAC,CACf;EACD,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;AACF;;;;AAKD,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,WAAoBC,UAAoB;EAClD,MAAM,QACJ,qBAAqB,QAAQ,YAAY,IAAI,MAAM,OAAO,UAAU;EACtE,MACE,CAAC,qBAAqB,EAAE,SAAS,KAAK,cAAc,EAAE,KAAK,UACzD,SAAS,KACV,CAAC,eAAC,EACgB,MAAM,MAAM,sCAAsC,CAAC,CACvE;EAED,KAAK,WAAW;EAChB,KAAK,YAAY;CAClB;AACF"}
1
+ {"version":3,"file":"errors.cjs","names":["toolNames: string[]","toolName: string","errors: string[]","toolError: unknown","toolCall: ToolCall"],"sources":["../../src/agents/errors.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\n\nexport class MultipleToolsBoundError extends Error {\n constructor() {\n super(\n \"The provided LLM already has bound tools. \" +\n \"Please provide an LLM without bound tools to createAgent. \" +\n \"The agent will bind the tools provided in the 'tools' parameter.\"\n );\n }\n}\n\n/**\n * Raised when model returns multiple structured output tool calls when only one is expected.\n */\nexport class MultipleStructuredOutputsError extends Error {\n public readonly toolNames: string[];\n\n constructor(toolNames: string[]) {\n super(\n `The model has called multiple tools: ${toolNames.join(\n \", \"\n )} to return a structured output. ` +\n \"This is not supported. Please provide a single structured output.\"\n );\n this.toolNames = toolNames;\n }\n}\n\n/**\n * Raised when structured output tool call arguments fail to parse according to the schema.\n */\nexport class StructuredOutputParsingError extends Error {\n public readonly toolName: string;\n\n public readonly errors: string[];\n\n constructor(toolName: string, errors: string[]) {\n super(\n `Failed to parse structured output for tool '${toolName}':${errors\n .map((e) => `\\n - ${e}`)\n .join(\"\")}.`\n );\n this.toolName = toolName;\n this.errors = errors;\n }\n}\n\n/**\n * Raised when a tool call is throwing an error.\n */\nexport class ToolInvocationError extends Error {\n public readonly toolCall: ToolCall;\n\n public readonly toolError: Error;\n\n constructor(toolError: unknown, toolCall: ToolCall) {\n const error =\n toolError instanceof Error ? toolError : new Error(String(toolError));\n super(\n `Error invoking tool '${toolCall.name}' with kwargs ${JSON.stringify(\n toolCall.args\n )} ` +\n `with error:\\n ${error.stack}\\n Please fix the error and try again.`\n );\n\n this.toolCall = toolCall;\n this.toolError = error;\n }\n}\n"],"mappings":";;AAGA,IAAa,0BAAb,cAA6C,MAAM;CACjD,cAAc;EACZ,MACE,uKAGD;CACF;AACF;;;;AAKD,IAAa,iCAAb,cAAoD,MAAM;CACxD,AAAgB;CAEhB,YAAYA,WAAqB;EAC/B,MACE,CAAC,qCAAqC,EAAE,UAAU,KAChD,KACD,CAAC,iGAAgC,CACmC,CACtE;EACD,KAAK,YAAY;CAClB;AACF;;;;AAKD,IAAa,+BAAb,cAAkD,MAAM;CACtD,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,UAAkBC,QAAkB;EAC9C,MACE,CAAC,4CAA4C,EAAE,SAAS,EAAE,EAAE,OACzD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACxB,KAAK,GAAG,CAAC,CAAC,CAAC,CACf;EACD,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;AACF;;;;AAKD,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,WAAoBC,UAAoB;EAClD,MAAM,QACJ,qBAAqB,QAAQ,YAAY,IAAI,MAAM,OAAO,UAAU;EACtE,MACE,CAAC,qBAAqB,EAAE,SAAS,KAAK,cAAc,EAAE,KAAK,UACzD,SAAS,KACV,CAAC,eAAC,EACgB,MAAM,MAAM,sCAAsC,CAAC,CACvE;EAED,KAAK,WAAW;EAChB,KAAK,YAAY;CAClB;AACF"}
@@ -1,7 +1,7 @@
1
1
  //#region src/agents/errors.ts
2
2
  var MultipleToolsBoundError = class extends Error {
3
3
  constructor() {
4
- super("The provided LLM already has bound tools. Please provide an LLM without bound tools to createReactAgent. The agent will bind the tools provided in the 'tools' parameter.");
4
+ super("The provided LLM already has bound tools. Please provide an LLM without bound tools to createAgent. The agent will bind the tools provided in the 'tools' parameter.");
5
5
  }
6
6
  };
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":["toolNames: string[]","toolName: string","errors: string[]","toolError: unknown","toolCall: ToolCall"],"sources":["../../src/agents/errors.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\n\nexport class MultipleToolsBoundError extends Error {\n constructor() {\n super(\n \"The provided LLM already has bound tools. \" +\n \"Please provide an LLM without bound tools to createReactAgent. \" +\n \"The agent will bind the tools provided in the 'tools' parameter.\"\n );\n }\n}\n\n/**\n * Raised when model returns multiple structured output tool calls when only one is expected.\n */\nexport class MultipleStructuredOutputsError extends Error {\n public readonly toolNames: string[];\n\n constructor(toolNames: string[]) {\n super(\n `The model has called multiple tools: ${toolNames.join(\n \", \"\n )} to return a structured output. ` +\n \"This is not supported. Please provide a single structured output.\"\n );\n this.toolNames = toolNames;\n }\n}\n\n/**\n * Raised when structured output tool call arguments fail to parse according to the schema.\n */\nexport class StructuredOutputParsingError extends Error {\n public readonly toolName: string;\n\n public readonly errors: string[];\n\n constructor(toolName: string, errors: string[]) {\n super(\n `Failed to parse structured output for tool '${toolName}':${errors\n .map((e) => `\\n - ${e}`)\n .join(\"\")}.`\n );\n this.toolName = toolName;\n this.errors = errors;\n }\n}\n\n/**\n * Raised when a tool call is throwing an error.\n */\nexport class ToolInvocationError extends Error {\n public readonly toolCall: ToolCall;\n\n public readonly toolError: Error;\n\n constructor(toolError: unknown, toolCall: ToolCall) {\n const error =\n toolError instanceof Error ? toolError : new Error(String(toolError));\n super(\n `Error invoking tool '${toolCall.name}' with kwargs ${JSON.stringify(\n toolCall.args\n )} ` +\n `with error:\\n ${error.stack}\\n Please fix the error and try again.`\n );\n\n this.toolCall = toolCall;\n this.toolError = error;\n }\n}\n"],"mappings":";AAGA,IAAa,0BAAb,cAA6C,MAAM;CACjD,cAAc;EACZ,MACE,4KAGD;CACF;AACF;;;;AAKD,IAAa,iCAAb,cAAoD,MAAM;CACxD,AAAgB;CAEhB,YAAYA,WAAqB;EAC/B,MACE,CAAC,qCAAqC,EAAE,UAAU,KAChD,KACD,CAAC,iGAAgC,CACmC,CACtE;EACD,KAAK,YAAY;CAClB;AACF;;;;AAKD,IAAa,+BAAb,cAAkD,MAAM;CACtD,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,UAAkBC,QAAkB;EAC9C,MACE,CAAC,4CAA4C,EAAE,SAAS,EAAE,EAAE,OACzD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACxB,KAAK,GAAG,CAAC,CAAC,CAAC,CACf;EACD,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;AACF;;;;AAKD,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,WAAoBC,UAAoB;EAClD,MAAM,QACJ,qBAAqB,QAAQ,YAAY,IAAI,MAAM,OAAO,UAAU;EACtE,MACE,CAAC,qBAAqB,EAAE,SAAS,KAAK,cAAc,EAAE,KAAK,UACzD,SAAS,KACV,CAAC,eAAC,EACgB,MAAM,MAAM,sCAAsC,CAAC,CACvE;EAED,KAAK,WAAW;EAChB,KAAK,YAAY;CAClB;AACF"}
1
+ {"version":3,"file":"errors.js","names":["toolNames: string[]","toolName: string","errors: string[]","toolError: unknown","toolCall: ToolCall"],"sources":["../../src/agents/errors.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\n\nexport class MultipleToolsBoundError extends Error {\n constructor() {\n super(\n \"The provided LLM already has bound tools. \" +\n \"Please provide an LLM without bound tools to createAgent. \" +\n \"The agent will bind the tools provided in the 'tools' parameter.\"\n );\n }\n}\n\n/**\n * Raised when model returns multiple structured output tool calls when only one is expected.\n */\nexport class MultipleStructuredOutputsError extends Error {\n public readonly toolNames: string[];\n\n constructor(toolNames: string[]) {\n super(\n `The model has called multiple tools: ${toolNames.join(\n \", \"\n )} to return a structured output. ` +\n \"This is not supported. Please provide a single structured output.\"\n );\n this.toolNames = toolNames;\n }\n}\n\n/**\n * Raised when structured output tool call arguments fail to parse according to the schema.\n */\nexport class StructuredOutputParsingError extends Error {\n public readonly toolName: string;\n\n public readonly errors: string[];\n\n constructor(toolName: string, errors: string[]) {\n super(\n `Failed to parse structured output for tool '${toolName}':${errors\n .map((e) => `\\n - ${e}`)\n .join(\"\")}.`\n );\n this.toolName = toolName;\n this.errors = errors;\n }\n}\n\n/**\n * Raised when a tool call is throwing an error.\n */\nexport class ToolInvocationError extends Error {\n public readonly toolCall: ToolCall;\n\n public readonly toolError: Error;\n\n constructor(toolError: unknown, toolCall: ToolCall) {\n const error =\n toolError instanceof Error ? toolError : new Error(String(toolError));\n super(\n `Error invoking tool '${toolCall.name}' with kwargs ${JSON.stringify(\n toolCall.args\n )} ` +\n `with error:\\n ${error.stack}\\n Please fix the error and try again.`\n );\n\n this.toolCall = toolCall;\n this.toolError = error;\n }\n}\n"],"mappings":";AAGA,IAAa,0BAAb,cAA6C,MAAM;CACjD,cAAc;EACZ,MACE,uKAGD;CACF;AACF;;;;AAKD,IAAa,iCAAb,cAAoD,MAAM;CACxD,AAAgB;CAEhB,YAAYA,WAAqB;EAC/B,MACE,CAAC,qCAAqC,EAAE,UAAU,KAChD,KACD,CAAC,iGAAgC,CACmC,CACtE;EACD,KAAK,YAAY;CAClB;AACF;;;;AAKD,IAAa,+BAAb,cAAkD,MAAM;CACtD,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,UAAkBC,QAAkB;EAC9C,MACE,CAAC,4CAA4C,EAAE,SAAS,EAAE,EAAE,OACzD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACxB,KAAK,GAAG,CAAC,CAAC,CAAC,CACf;EACD,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;AACF;;;;AAKD,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAgB;CAEhB,AAAgB;CAEhB,YAAYC,WAAoBC,UAAoB;EAClD,MAAM,QACJ,qBAAqB,QAAQ,YAAY,IAAI,MAAM,OAAO,UAAU;EACtE,MACE,CAAC,qBAAqB,EAAE,SAAS,KAAK,cAAc,EAAE,KAAK,UACzD,SAAS,KACV,CAAC,eAAC,EACgB,MAAM,MAAM,sCAAsC,CAAC,CACvE;EAED,KAAK,WAAW;EAChB,KAAK,YAAY;CAClB;AACF"}
@@ -2,15 +2,34 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_errors = require('./errors.cjs');
3
3
  const require_responses = require('./responses.cjs');
4
4
  const require_ToolNode = require('./nodes/ToolNode.cjs');
5
- const require_ReactAgent = require('./ReactAgent.cjs');
5
+ const require_createAgent = require('./createAgent.cjs');
6
+ const require_middleware = require('./middlewareAgent/middleware.cjs');
7
+ const require_index = require('./middlewareAgent/index.cjs');
6
8
  require('./interrupt.cjs');
7
9
  const __langchain_langgraph = require_rolldown_runtime.__toESM(require("@langchain/langgraph"));
8
10
 
9
11
  //#region src/agents/index.ts
10
- function createReactAgent(params) {
11
- return new require_ReactAgent.ReactAgent(params);
12
+ function createAgent$2(params) {
13
+ /**
14
+ * Check if middlewares property is present
15
+ */
16
+ if ("middlewares" in params && params.middlewares !== void 0) {
17
+ /**
18
+ * The user wants to use the middleware version of the agent.
19
+ * Let's verify that `preModelHook` and `postModelHook` are not provided
20
+ */
21
+ if ("preModelHook" in params || "postModelHook" in params) throw new Error("The `preModelHook` and `postModelHook` parameters are not supported in the middleware version of the agent.");
22
+ /**
23
+ * Use v2 (middleware version)
24
+ */
25
+ return require_index.createAgent(params);
26
+ } else
27
+ /**
28
+ * Use v1 (original version)
29
+ */
30
+ return require_createAgent.createAgent(params);
12
31
  }
13
32
 
14
33
  //#endregion
15
- exports.createReactAgent = createReactAgent;
34
+ exports.createAgent = createAgent$2;
16
35
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["params: CreateReactAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n >","ReactAgent"],"sources":["../../src/agents/index.ts"],"sourcesContent":["import type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { MessagesAnnotation } from \"@langchain/langgraph\";\n\nimport { type AnyAnnotationRoot } from \"./annotation.js\";\nimport type { CreateReactAgentParams, ExtractZodArrayTypes } from \"./types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"./responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createReactAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createReactAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n T,\n ContextSchema,\n InteropZodType<T>\n > & {\n responseFormat: InteropZodType<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createReactAgent<\n T extends readonly InteropZodType<any>[],\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n }\n): ReactAgent<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n }\n): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n T,\n ContextSchema,\n TypedToolStrategy<T>\n > & {\n responseFormat: TypedToolStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n T,\n ContextSchema,\n ToolStrategy<T>\n > & {\n responseFormat: ToolStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n T,\n ContextSchema,\n ProviderStrategy<T>\n > & {\n responseFormat: ProviderStrategy<T>;\n }\n): ReactAgent<StateSchema, T, ContextSchema>;\n\n// Overload 8: Without responseFormat property at all\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateReactAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n >\n): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateReactAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n }\n): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createReactAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n }\n): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema>;\n\n// Implementation\nexport function createReactAgent<\n StateSchema extends AnyAnnotationRoot | InteropZodObject,\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject\n>(\n params: CreateReactAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n >\n): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema> {\n return new ReactAgent(params);\n}\n\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport * from \"./interrupt.js\";\nexport { ToolNode } from \"./nodes/ToolNode.js\";\nexport {\n toolStrategy,\n providerStrategy,\n ToolStrategy,\n ProviderStrategy,\n type ResponseFormat,\n} from \"./responses.js\";\n"],"mappings":";;;;;;;;;AA0QA,SAAgB,iBAKdA,QAMkE;AAClE,QAAO,IAAIC,8BAAW;AACvB"}
1
+ {"version":3,"file":"index.cjs","names":["createAgent","params: any","createAgentV2","createAgentV1"],"sources":["../../src/agents/index.ts"],"sourcesContent":["import type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport { MessagesAnnotation } from \"@langchain/langgraph\";\n\n// Import v1 (without middleware)\nimport { createAgent as createAgentV1 } from \"./createAgent.js\";\nimport { ReactAgent as ReactAgentV1 } from \"./ReactAgent.js\";\n\n// Import v2 (with middleware)\nimport { createAgent as createAgentV2 } from \"./middlewareAgent/index.js\";\nimport { ReactAgent as ReactAgentV2 } from \"./middlewareAgent/ReactAgent.js\";\n\nimport { type AnyAnnotationRoot } from \"./annotation.js\";\nimport type { CreateAgentParams, ExtractZodArrayTypes } from \"./types.js\";\nimport type {\n CreateAgentParams as CreateAgentParamsV2,\n AgentMiddleware,\n} from \"./middlewareAgent/types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"./responses.js\";\n\n// Re-export types and utilities\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport * from \"./interrupt.js\";\nexport { ToolNode } from \"./nodes/ToolNode.js\";\nexport {\n toolStrategy,\n providerStrategy,\n ToolStrategy,\n ProviderStrategy,\n type ResponseFormat,\n} from \"./responses.js\";\nexport { createMiddleware } from \"./middlewareAgent/index.js\";\nexport type { AgentMiddleware } from \"./middlewareAgent/types.js\";\n\n/**\n * Agents combine language models with tools to create systems that can reason\n * about tasks, decide which tools to use, and iteratively work towards solutions.\n * {@link createAgent} provides a production-ready ReAct (Reasoning + Acting)\n * agent implementation based on the paper {@link https://arxiv.org/abs/2210.03629|ReAct: Synergizing Reasoning and Acting in Language Models.}\n *\n * @example\n * ```ts\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({\n * // use chat model from \"@langchain/openai\"\n * model: \"openai:gpt-4o-mini\",\n * tools: [getWeather]\n * });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n\n// ===== V1 OVERLOADS (WITHOUT MIDDLEWARE) =====\n// These overloads come first to ensure proper type inference when middlewares is NOT provided\n\n// Overload 1: V1 - With responseFormat as single InteropZodType\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n InteropZodType<T>\n > & {\n responseFormat: InteropZodType<T>;\n }\n): ReactAgentV1<StateSchema, T, ContextSchema>;\n\n// Overload 2: V1 - With responseFormat as array of InteropZodTypes\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n }\n): ReactAgentV1<\n StateSchema,\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema\n>;\n\n// Overload 3: V1 - With responseFormat as JsonSchemaFormat\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n }\n): ReactAgentV1<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 4: V1 - With responseFormat as array of JsonSchemaFormat\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n }\n): ReactAgentV1<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 5: V1 - With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n }\n): ReactAgentV1<StateSchema, Record<string, unknown>, ContextSchema>;\n\n// Overload 6: V1 - With responseFormat as TypedToolStrategy\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n TypedToolStrategy<T>\n > & {\n responseFormat: TypedToolStrategy<T>;\n }\n): ReactAgentV1<StateSchema, T, ContextSchema>;\n\n// Overload 7: V1 - With responseFormat as single ToolStrategy\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<StateSchema, T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n }\n): ReactAgentV1<StateSchema, T, ContextSchema>;\n\n// Overload 8: V1 - With responseFormat as ProviderStrategy\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n T,\n ContextSchema,\n ProviderStrategy<T>\n > & {\n responseFormat: ProviderStrategy<T>;\n }\n): ReactAgentV1<StateSchema, T, ContextSchema>;\n\n// Overload 9: V1 - Without responseFormat property at all\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n >\n): ReactAgentV1<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 10: V1 - With responseFormat explicitly undefined\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: Omit<\n CreateAgentParams<\n StateSchema,\n ResponseFormatUndefined,\n ContextSchema,\n never\n >,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n }\n): ReactAgentV1<StateSchema, ResponseFormatUndefined, ContextSchema>;\n\n// Overload 11: V1 - For other ResponseFormat values (failsafe)\nexport function createAgent<\n StateSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = typeof MessagesAnnotation,\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateAgentParams<\n StateSchema,\n StructuredResponseFormat,\n ContextSchema,\n any\n > & {\n responseFormat: any;\n }\n): ReactAgentV1<StateSchema, StructuredResponseFormat, ContextSchema>;\n\n// ===== V2 OVERLOADS (WITH MIDDLEWARE) =====\n// These overloads explicitly require the middlewares property\n\n// Overload 12: With responseFormat as single InteropZodType and middlewares\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<T, ContextSchema, InteropZodType<T>> & {\n responseFormat: InteropZodType<T>;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<T, ContextSchema, TMiddlewares>;\n\n// Overload 13: With responseFormat as array of InteropZodTypes and middlewares\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n TMiddlewares\n>;\n\n// Overload 14: With responseFormat as JsonSchemaFormat and middlewares\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 15: With responseFormat as array of JsonSchemaFormat and middlewares\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 16: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[] and middlewares\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 17: With responseFormat as TypedToolStrategy and middlewares\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<T, ContextSchema, TypedToolStrategy<T>> & {\n responseFormat: TypedToolStrategy<T>;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<T, ContextSchema, TMiddlewares>;\n\n// Overload 18: With responseFormat as single ToolStrategy and middlewares\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<T, ContextSchema, TMiddlewares>;\n\n// Overload 19: With responseFormat as ProviderStrategy and middlewares\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<T, ContextSchema, ProviderStrategy<T>> & {\n responseFormat: ProviderStrategy<T>;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<T, ContextSchema, TMiddlewares>;\n\n// Overload 20: Without responseFormat but with middlewares\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParamsV2<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & { middlewares: TMiddlewares }\n): ReactAgentV2<ResponseFormatUndefined, ContextSchema, TMiddlewares>;\n\n// Overload 21: With responseFormat explicitly undefined and middlewares\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParamsV2<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<ResponseFormatUndefined, ContextSchema, TMiddlewares>;\n\n// Overload 22: For other ResponseFormat values with middlewares (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParamsV2<StructuredResponseFormat, ContextSchema, any> & {\n responseFormat: any;\n middlewares: TMiddlewares;\n }\n): ReactAgentV2<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n\nexport function createAgent(params: any): any {\n /**\n * Check if middlewares property is present\n */\n if (\"middlewares\" in params && params.middlewares !== undefined) {\n /**\n * The user wants to use the middleware version of the agent.\n * Let's verify that `preModelHook` and `postModelHook` are not provided\n */\n if (\"preModelHook\" in params || \"postModelHook\" in params) {\n throw new Error(\n \"The `preModelHook` and `postModelHook` parameters are not supported in the middleware version of the agent.\"\n );\n }\n\n /**\n * Use v2 (middleware version)\n */\n return createAgentV2(params);\n } else {\n /**\n * Use v1 (original version)\n */\n return createAgentV1(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAigBA,SAAgBA,cAAYC,QAAkB;;;;AAI5C,KAAI,iBAAiB,UAAU,OAAO,gBAAgB,QAAW;;;;;AAK/D,MAAI,kBAAkB,UAAU,mBAAmB,OACjD,OAAM,IAAI,MACR;;;;AAOJ,SAAOC,0BAAc,OAAO;CAC7B;;;;AAIC,QAAOC,gCAAc,OAAO;AAE/B"}
@@ -2,27 +2,28 @@ import { MultipleStructuredOutputsError, StructuredOutputParsingError } from "./
2
2
  import { JsonSchemaFormat, ProviderStrategy, ResponseFormat, ResponseFormatUndefined, ToolStrategy, TypedToolStrategy, providerStrategy, toolStrategy } from "./responses.cjs";
3
3
  import { AnyAnnotationRoot } from "./annotation.cjs";
4
4
  import { ToolNode } from "./nodes/ToolNode.cjs";
5
- import { AgentRuntime, AgentState, ClientTool, CreateReactAgentParams, ExtractZodArrayTypes, N, Prompt, ServerTool } from "./types.cjs";
5
+ import { AgentRuntime, AgentState, ClientTool, CreateAgentParams, ExtractZodArrayTypes, N, Prompt, ServerTool } from "./types.cjs";
6
+ import { AgentMiddleware, CreateAgentParams as CreateAgentParams$1 } from "./middlewareAgent/types.cjs";
6
7
  import { ReactAgent } from "./ReactAgent.cjs";
8
+ import { ReactAgent as ReactAgent$1 } from "./middlewareAgent/ReactAgent.cjs";
7
9
  import { ActionRequest, HumanInterrupt, HumanInterruptConfig, HumanResponse } from "./interrupt.cjs";
10
+ import { createMiddleware } from "./middlewareAgent/middleware.cjs";
8
11
  import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
9
12
  import { MessagesAnnotation } from "@langchain/langgraph";
10
13
 
11
14
  //#region src/agents/index.d.ts
12
15
 
13
16
  /**
14
- * Creates a StateGraph agent that relies on a chat model utilizing tool calling.
17
+ * Agents combine language models with tools to create systems that can reason
18
+ * about tasks, decide which tools to use, and iteratively work towards solutions.
19
+ * {@link createAgent} provides a production-ready ReAct (Reasoning + Acting)
20
+ * agent implementation based on the paper {@link https://arxiv.org/abs/2210.03629|ReAct: Synergizing Reasoning and Acting in Language Models.}
15
21
  *
16
22
  * @example
17
23
  * ```ts
18
- * import { ChatOpenAI } from "@langchain/openai";
19
- * import { createReactAgent, tool } from "langchain";
24
+ * import { createAgent, tool } from "langchain";
20
25
  * import { z } from "zod";
21
26
  *
22
- * const model = new ChatOpenAI({
23
- * model: "gpt-4o",
24
- * });
25
- *
26
27
  * const getWeather = tool((input) => {
27
28
  * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
28
29
  * return "It's 60 degrees and foggy.";
@@ -37,7 +38,11 @@ import { MessagesAnnotation } from "@langchain/langgraph";
37
38
  * })
38
39
  * })
39
40
  *
40
- * const agent = createReactAgent({ llm: model, tools: [getWeather] });
41
+ * const agent = createAgent({
42
+ * // use chat model from "@langchain/openai"
43
+ * model: "openai:gpt-4o-mini",
44
+ * tools: [getWeather]
45
+ * });
41
46
  *
42
47
  * const inputs = {
43
48
  * messages: [{ role: "user", content: "what is the weather in SF?" }],
@@ -51,48 +56,106 @@ import { MessagesAnnotation } from "@langchain/langgraph";
51
56
  * // Returns the messages in the state at each step of execution
52
57
  * ```
53
58
  */
54
- // Overload 1: With responseFormat as single InteropZodType
55
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, T, ContextSchema, InteropZodType<T>> & {
59
+ // ===== V1 OVERLOADS (WITHOUT MIDDLEWARE) =====
60
+ // These overloads come first to ensure proper type inference when middlewares is NOT provided
61
+ // Overload 1: V1 - With responseFormat as single InteropZodType
62
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, T, ContextSchema, InteropZodType<T>> & {
56
63
  responseFormat: InteropZodType<T>;
57
64
  }): ReactAgent<StateSchema, T, ContextSchema>;
58
- // Overload 2: With responseFormat as array of InteropZodTypes (infers union type)
59
- declare function createReactAgent<T extends readonly InteropZodType<any>[], StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, ExtractZodArrayTypes<T> extends Record<string, any> ? ExtractZodArrayTypes<T> : Record<string, any>, ContextSchema, T> & {
65
+ // Overload 2: V1 - With responseFormat as array of InteropZodTypes
66
+ declare function createAgent<T extends readonly InteropZodType<any>[], StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, ExtractZodArrayTypes<T> extends Record<string, any> ? ExtractZodArrayTypes<T> : Record<string, any>, ContextSchema, T> & {
60
67
  responseFormat: T;
61
68
  }): ReactAgent<StateSchema, ExtractZodArrayTypes<T> extends Record<string, any> ? ExtractZodArrayTypes<T> : Record<string, any>, ContextSchema>;
62
- // Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)
63
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, Record<string, unknown>, ContextSchema, JsonSchemaFormat> & {
69
+ // Overload 3: V1 - With responseFormat as JsonSchemaFormat
70
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, Record<string, unknown>, ContextSchema, JsonSchemaFormat> & {
64
71
  responseFormat: JsonSchemaFormat;
65
72
  }): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;
66
- // Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)
67
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, Record<string, unknown>, ContextSchema, JsonSchemaFormat[]> & {
73
+ // Overload 4: V1 - With responseFormat as array of JsonSchemaFormat
74
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, Record<string, unknown>, ContextSchema, JsonSchemaFormat[]> & {
68
75
  responseFormat: JsonSchemaFormat[];
69
76
  }): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;
70
- // Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]
71
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, Record<string, unknown>, ContextSchema, JsonSchemaFormat | JsonSchemaFormat[]> & {
77
+ // Overload 5: V1 - With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]
78
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, Record<string, unknown>, ContextSchema, JsonSchemaFormat | JsonSchemaFormat[]> & {
72
79
  responseFormat: JsonSchemaFormat | JsonSchemaFormat[];
73
80
  }): ReactAgent<StateSchema, Record<string, unknown>, ContextSchema>;
74
- // Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)
75
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, T, ContextSchema, TypedToolStrategy<T>> & {
81
+ // Overload 6: V1 - With responseFormat as TypedToolStrategy
82
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, T, ContextSchema, TypedToolStrategy<T>> & {
76
83
  responseFormat: TypedToolStrategy<T>;
77
84
  }): ReactAgent<StateSchema, T, ContextSchema>;
78
- // Overload 6: With responseFormat as single ToolStrategy instance
79
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, T, ContextSchema, ToolStrategy<T>> & {
85
+ // Overload 7: V1 - With responseFormat as single ToolStrategy
86
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, T, ContextSchema, ToolStrategy<T>> & {
80
87
  responseFormat: ToolStrategy<T>;
81
88
  }): ReactAgent<StateSchema, T, ContextSchema>;
82
- // Overload 7: With responseFormat as ProviderStrategy
83
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, T, ContextSchema, ProviderStrategy<T>> & {
89
+ // Overload 8: V1 - With responseFormat as ProviderStrategy
90
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, T, ContextSchema, ProviderStrategy<T>> & {
84
91
  responseFormat: ProviderStrategy<T>;
85
92
  }): ReactAgent<StateSchema, T, ContextSchema>;
86
- // Overload 8: Without responseFormat property at all
87
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: Omit<CreateReactAgentParams<StateSchema, ResponseFormatUndefined, ContextSchema, never>, "responseFormat">): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;
88
- // Overload 9: With responseFormat explicitly undefined
89
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: Omit<CreateReactAgentParams<StateSchema, ResponseFormatUndefined, ContextSchema, never>, "responseFormat"> & {
93
+ // Overload 9: V1 - Without responseFormat property at all
94
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: Omit<CreateAgentParams<StateSchema, ResponseFormatUndefined, ContextSchema, never>, "responseFormat">): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;
95
+ // Overload 10: V1 - With responseFormat explicitly undefined
96
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: Omit<CreateAgentParams<StateSchema, ResponseFormatUndefined, ContextSchema, never>, "responseFormat"> & {
90
97
  responseFormat?: undefined;
91
98
  }): ReactAgent<StateSchema, ResponseFormatUndefined, ContextSchema>;
92
- // Overload 10: For other ResponseFormat values (failsafe)
93
- declare function createReactAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, StructuredResponseFormat extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<StateSchema, StructuredResponseFormat, ContextSchema, ResponseFormat> & {
94
- responseFormat: ResponseFormat;
99
+ // Overload 11: V1 - For other ResponseFormat values (failsafe)
100
+ declare function createAgent<StateSchema extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, StructuredResponseFormat extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateAgentParams<StateSchema, StructuredResponseFormat, ContextSchema, any> & {
101
+ responseFormat: any;
95
102
  }): ReactAgent<StateSchema, StructuredResponseFormat, ContextSchema>;
103
+ // ===== V2 OVERLOADS (WITH MIDDLEWARE) =====
104
+ // These overloads explicitly require the middlewares property
105
+ // Overload 12: With responseFormat as single InteropZodType and middlewares
106
+ declare function createAgent<T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<T, ContextSchema, InteropZodType<T>> & {
107
+ responseFormat: InteropZodType<T>;
108
+ middlewares: TMiddlewares;
109
+ }): ReactAgent$1<T, ContextSchema, TMiddlewares>;
110
+ // Overload 13: With responseFormat as array of InteropZodTypes and middlewares
111
+ declare function createAgent<T extends readonly InteropZodType<any>[], ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<ExtractZodArrayTypes<T> extends Record<string, any> ? ExtractZodArrayTypes<T> : Record<string, any>, ContextSchema, T> & {
112
+ responseFormat: T;
113
+ middlewares: TMiddlewares;
114
+ }): ReactAgent$1<ExtractZodArrayTypes<T> extends Record<string, any> ? ExtractZodArrayTypes<T> : Record<string, any>, ContextSchema, TMiddlewares>;
115
+ // Overload 14: With responseFormat as JsonSchemaFormat and middlewares
116
+ declare function createAgent<ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<Record<string, unknown>, ContextSchema, JsonSchemaFormat> & {
117
+ responseFormat: JsonSchemaFormat;
118
+ middlewares: TMiddlewares;
119
+ }): ReactAgent$1<Record<string, unknown>, ContextSchema, TMiddlewares>;
120
+ // Overload 15: With responseFormat as array of JsonSchemaFormat and middlewares
121
+ declare function createAgent<ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<Record<string, unknown>, ContextSchema, JsonSchemaFormat[]> & {
122
+ responseFormat: JsonSchemaFormat[];
123
+ middlewares: TMiddlewares;
124
+ }): ReactAgent$1<Record<string, unknown>, ContextSchema, TMiddlewares>;
125
+ // Overload 16: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[] and middlewares
126
+ declare function createAgent<ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<Record<string, unknown>, ContextSchema, JsonSchemaFormat | JsonSchemaFormat[]> & {
127
+ responseFormat: JsonSchemaFormat | JsonSchemaFormat[];
128
+ middlewares: TMiddlewares;
129
+ }): ReactAgent$1<Record<string, unknown>, ContextSchema, TMiddlewares>;
130
+ // Overload 17: With responseFormat as TypedToolStrategy and middlewares
131
+ declare function createAgent<T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<T, ContextSchema, TypedToolStrategy<T>> & {
132
+ responseFormat: TypedToolStrategy<T>;
133
+ middlewares: TMiddlewares;
134
+ }): ReactAgent$1<T, ContextSchema, TMiddlewares>;
135
+ // Overload 18: With responseFormat as single ToolStrategy and middlewares
136
+ declare function createAgent<T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<T, ContextSchema, ToolStrategy<T>> & {
137
+ responseFormat: ToolStrategy<T>;
138
+ middlewares: TMiddlewares;
139
+ }): ReactAgent$1<T, ContextSchema, TMiddlewares>;
140
+ // Overload 19: With responseFormat as ProviderStrategy and middlewares
141
+ declare function createAgent<T extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<T, ContextSchema, ProviderStrategy<T>> & {
142
+ responseFormat: ProviderStrategy<T>;
143
+ middlewares: TMiddlewares;
144
+ }): ReactAgent$1<T, ContextSchema, TMiddlewares>;
145
+ // Overload 20: Without responseFormat but with middlewares
146
+ declare function createAgent<ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: Omit<CreateAgentParams$1<ResponseFormatUndefined, ContextSchema, never>, "responseFormat"> & {
147
+ middlewares: TMiddlewares;
148
+ }): ReactAgent$1<ResponseFormatUndefined, ContextSchema, TMiddlewares>;
149
+ // Overload 21: With responseFormat explicitly undefined and middlewares
150
+ declare function createAgent<ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: Omit<CreateAgentParams$1<ResponseFormatUndefined, ContextSchema, never>, "responseFormat"> & {
151
+ responseFormat?: undefined;
152
+ middlewares: TMiddlewares;
153
+ }): ReactAgent$1<ResponseFormatUndefined, ContextSchema, TMiddlewares>;
154
+ // Overload 22: For other ResponseFormat values with middlewares (failsafe)
155
+ declare function createAgent<StructuredResponseFormat extends Record<string, any> = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = readonly AgentMiddleware<any, any, any>[]>(params: CreateAgentParams$1<StructuredResponseFormat, ContextSchema, any> & {
156
+ responseFormat: any;
157
+ middlewares: TMiddlewares;
158
+ }): ReactAgent$1<StructuredResponseFormat, ContextSchema, TMiddlewares>;
96
159
  //#endregion
97
- export { createReactAgent };
160
+ export { createAgent };
98
161
  //# sourceMappingURL=index.d.cts.map