langchain 1.0.0-alpha.4 → 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 (157) hide show
  1. package/dist/agents/RunnableCallable.cjs +5 -0
  2. package/dist/agents/RunnableCallable.cjs.map +1 -1
  3. package/dist/agents/RunnableCallable.d.cts +2 -0
  4. package/dist/agents/RunnableCallable.d.cts.map +1 -1
  5. package/dist/agents/RunnableCallable.d.ts +2 -0
  6. package/dist/agents/RunnableCallable.d.ts.map +1 -1
  7. package/dist/agents/RunnableCallable.js +5 -0
  8. package/dist/agents/RunnableCallable.js.map +1 -1
  9. package/dist/agents/annotation.d.cts +1 -1
  10. package/dist/agents/createAgent.cjs +10 -0
  11. package/dist/agents/createAgent.cjs.map +1 -0
  12. package/dist/agents/createAgent.js +10 -0
  13. package/dist/agents/createAgent.js.map +1 -0
  14. package/dist/agents/index.cjs +23 -4
  15. package/dist/agents/index.cjs.map +1 -1
  16. package/dist/agents/index.d.cts +83 -20
  17. package/dist/agents/index.d.cts.map +1 -1
  18. package/dist/agents/index.d.ts +83 -20
  19. package/dist/agents/index.d.ts.map +1 -1
  20. package/dist/agents/index.js +23 -4
  21. package/dist/agents/index.js.map +1 -1
  22. package/dist/agents/middlewareAgent/ReactAgent.cjs +255 -0
  23. package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -0
  24. package/dist/agents/middlewareAgent/ReactAgent.d.cts +68 -0
  25. package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -0
  26. package/dist/agents/middlewareAgent/ReactAgent.d.ts +68 -0
  27. package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -0
  28. package/dist/agents/middlewareAgent/ReactAgent.js +254 -0
  29. package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -0
  30. package/dist/agents/middlewareAgent/annotation.cjs +39 -0
  31. package/dist/agents/middlewareAgent/annotation.cjs.map +1 -0
  32. package/dist/agents/middlewareAgent/annotation.js +38 -0
  33. package/dist/agents/middlewareAgent/annotation.js.map +1 -0
  34. package/dist/agents/middlewareAgent/index.cjs +11 -0
  35. package/dist/agents/middlewareAgent/index.cjs.map +1 -0
  36. package/dist/agents/middlewareAgent/index.js +11 -0
  37. package/dist/agents/middlewareAgent/index.js.map +1 -0
  38. package/dist/agents/middlewareAgent/middleware.cjs +47 -0
  39. package/dist/agents/middlewareAgent/middleware.cjs.map +1 -0
  40. package/dist/agents/middlewareAgent/middleware.d.cts +46 -0
  41. package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -0
  42. package/dist/agents/middlewareAgent/middleware.d.ts +46 -0
  43. package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -0
  44. package/dist/agents/middlewareAgent/middleware.js +46 -0
  45. package/dist/agents/middlewareAgent/middleware.js.map +1 -0
  46. package/dist/agents/middlewareAgent/middlewares/hitl.cjs +235 -0
  47. package/dist/agents/middlewareAgent/middlewares/hitl.cjs.map +1 -0
  48. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts +199 -0
  49. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts.map +1 -0
  50. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts +199 -0
  51. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts.map +1 -0
  52. package/dist/agents/middlewareAgent/middlewares/hitl.js +234 -0
  53. package/dist/agents/middlewareAgent/middlewares/hitl.js.map +1 -0
  54. package/dist/agents/middlewareAgent/middlewares/index.cjs +8 -0
  55. package/dist/agents/middlewareAgent/middlewares/index.d.cts +4 -0
  56. package/dist/agents/middlewareAgent/middlewares/index.d.ts +4 -0
  57. package/dist/agents/middlewareAgent/middlewares/index.js +5 -0
  58. package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs +153 -0
  59. package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs.map +1 -0
  60. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts +152 -0
  61. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts.map +1 -0
  62. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts +152 -0
  63. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts.map +1 -0
  64. package/dist/agents/middlewareAgent/middlewares/promptCaching.js +152 -0
  65. package/dist/agents/middlewareAgent/middlewares/promptCaching.js.map +1 -0
  66. package/dist/agents/middlewareAgent/middlewares/summarization.cjs +262 -0
  67. package/dist/agents/middlewareAgent/middlewares/summarization.cjs.map +1 -0
  68. package/dist/agents/middlewareAgent/middlewares/summarization.d.cts +89 -0
  69. package/dist/agents/middlewareAgent/middlewares/summarization.d.cts.map +1 -0
  70. package/dist/agents/middlewareAgent/middlewares/summarization.d.ts +89 -0
  71. package/dist/agents/middlewareAgent/middlewares/summarization.d.ts.map +1 -0
  72. package/dist/agents/middlewareAgent/middlewares/summarization.js +260 -0
  73. package/dist/agents/middlewareAgent/middlewares/summarization.js.map +1 -0
  74. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs +29 -0
  75. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -0
  76. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js +29 -0
  77. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -0
  78. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +332 -0
  79. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -0
  80. package/dist/agents/middlewareAgent/nodes/AgentNode.js +331 -0
  81. package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -0
  82. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs +27 -0
  83. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -0
  84. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js +27 -0
  85. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -0
  86. package/dist/agents/middlewareAgent/nodes/middleware.cjs +73 -0
  87. package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -0
  88. package/dist/agents/middlewareAgent/nodes/middleware.js +73 -0
  89. package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -0
  90. package/dist/agents/middlewareAgent/nodes/utils.cjs +74 -0
  91. package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -0
  92. package/dist/agents/middlewareAgent/nodes/utils.js +70 -0
  93. package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -0
  94. package/dist/agents/middlewareAgent/types.d.cts +393 -0
  95. package/dist/agents/middlewareAgent/types.d.cts.map +1 -0
  96. package/dist/agents/middlewareAgent/types.d.ts +393 -0
  97. package/dist/agents/middlewareAgent/types.d.ts.map +1 -0
  98. package/dist/agents/nodes/ToolNode.d.cts +3 -3
  99. package/dist/agents/types.d.cts +4 -4
  100. package/dist/chains/api/api_chain.d.cts +1 -1
  101. package/dist/chains/base.d.cts +1 -1
  102. package/dist/chains/combine_docs_chain.d.cts +1 -1
  103. package/dist/chains/combine_documents/stuff.d.cts +1 -1
  104. package/dist/chains/conversational_retrieval_chain.d.cts +1 -1
  105. package/dist/chains/graph_qa/cypher.d.cts +1 -1
  106. package/dist/chains/history_aware_retriever.d.cts +2 -2
  107. package/dist/chains/llm_chain.d.cts +3 -3
  108. package/dist/chains/openai_functions/base.d.cts +3 -3
  109. package/dist/chains/openai_functions/openapi.d.cts +1 -1
  110. package/dist/chains/openai_functions/structured_output.d.cts +3 -3
  111. package/dist/chains/openai_functions/tagging.d.cts +1 -1
  112. package/dist/chains/query_constructor/index.cjs +1 -1
  113. package/dist/chains/query_constructor/index.d.cts +2 -2
  114. package/dist/chains/query_constructor/index.d.ts +1 -1
  115. package/dist/chains/query_constructor/index.js +1 -1
  116. package/dist/chains/question_answering/load.d.ts +2 -2
  117. package/dist/chains/question_answering/load.d.ts.map +1 -1
  118. package/dist/chains/retrieval.d.cts +1 -1
  119. package/dist/chains/router/llm_router.d.cts +1 -1
  120. package/dist/chains/router/multi_prompt.cjs +1 -1
  121. package/dist/chains/router/multi_prompt.js +1 -1
  122. package/dist/chains/router/multi_retrieval_qa.cjs +1 -1
  123. package/dist/chains/router/multi_retrieval_qa.js +1 -1
  124. package/dist/chains/sql_db/sql_db_chain.d.cts +2 -2
  125. package/dist/chains/summarization/load.d.ts +2 -2
  126. package/dist/chains/summarization/load.d.ts.map +1 -1
  127. package/dist/chat_models/universal.d.cts +3 -3
  128. package/dist/evaluation/agents/trajectory.d.cts +3 -3
  129. package/dist/evaluation/agents/trajectory.d.ts.map +1 -1
  130. package/dist/evaluation/comparison/pairwise.d.cts +1 -1
  131. package/dist/evaluation/comparison/pairwise.d.cts.map +1 -1
  132. package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
  133. package/dist/evaluation/criteria/criteria.d.cts +1 -1
  134. package/dist/evaluation/criteria/criteria.d.cts.map +1 -1
  135. package/dist/evaluation/criteria/criteria.d.ts.map +1 -1
  136. package/dist/evaluation/qa/eval_chain.d.cts +1 -1
  137. package/dist/index.cjs +3 -0
  138. package/dist/index.cjs.map +1 -1
  139. package/dist/index.d.cts +5 -4
  140. package/dist/index.d.ts +3 -2
  141. package/dist/index.js +3 -1
  142. package/dist/index.js.map +1 -1
  143. package/dist/load/import_map.cjs +1 -1
  144. package/dist/load/import_map.js +1 -1
  145. package/dist/memory/summary.d.cts +1 -1
  146. package/dist/output_parsers/fix.d.cts +1 -1
  147. package/dist/output_parsers/http_response.d.cts +1 -1
  148. package/dist/output_parsers/structured.cjs +1 -1
  149. package/dist/output_parsers/structured.d.cts +2 -2
  150. package/dist/output_parsers/structured.d.ts +1 -1
  151. package/dist/output_parsers/structured.js +1 -1
  152. package/dist/tools/fs.d.cts +1 -1
  153. package/dist/tools/json.d.cts +1 -1
  154. package/dist/tools/retriever.d.cts +1 -1
  155. package/dist/tools/vectorstore.d.cts +1 -1
  156. package/dist/tools/webbrowser.d.cts +1 -1
  157. package/package.json +17 -6
@@ -10,6 +10,7 @@ var RunnableCallable = class extends __langchain_core_runnables.Runnable {
10
10
  config;
11
11
  trace = true;
12
12
  recurse = true;
13
+ #state;
13
14
  constructor(fields) {
14
15
  super();
15
16
  this.name = fields.name ?? fields.func.name;
@@ -17,10 +18,14 @@ var RunnableCallable = class extends __langchain_core_runnables.Runnable {
17
18
  this.config = fields.tags ? { tags: fields.tags } : void 0;
18
19
  this.recurse = fields.recurse ?? this.recurse;
19
20
  }
21
+ getState() {
22
+ return this.#state;
23
+ }
20
24
  async invoke(input, options) {
21
25
  const mergedConfig = (0, __langchain_core_runnables.mergeConfigs)(this.config, options);
22
26
  const returnValue = await __langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig(mergedConfig, async () => this.func(input, mergedConfig));
23
27
  if (__langchain_core_runnables.Runnable.isRunnable(returnValue) && this.recurse) return await __langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig(mergedConfig, async () => returnValue.invoke(input, mergedConfig));
28
+ this.#state = returnValue;
24
29
  return returnValue;
25
30
  }
26
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RunnableCallable.cjs","names":["Runnable","fields: RunnableCallableArgs<I, O>","input: I","options?: Partial<RunnableConfig> | undefined","AsyncLocalStorageProviderSingleton"],"sources":["../../src/agents/RunnableCallable.ts"],"sourcesContent":["import {\n mergeConfigs,\n Runnable,\n RunnableConfig,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\n\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\n\nexport class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[] = [\"langgraph\"];\n\n func: RunnableCallableArgs<I, O>[\"func\"];\n\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n\n config?: RunnableConfig;\n\n trace = true;\n\n recurse = true;\n\n constructor(fields: RunnableCallableArgs<I, O>) {\n super();\n this.name = fields.name ?? fields.func.name;\n this.func = fields.func;\n this.config = fields.tags ? { tags: fields.tags } : undefined;\n this.recurse = fields.recurse ?? this.recurse;\n }\n\n async invoke(\n input: I,\n options?: Partial<RunnableConfig> | undefined\n ): Promise<O> {\n const mergedConfig = mergeConfigs(this.config, options);\n\n const returnValue = await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => this.func(input, mergedConfig as I)\n );\n\n if (Runnable.isRunnable(returnValue) && this.recurse) {\n return await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => (returnValue as Runnable<I, O>).invoke(input, mergedConfig)\n );\n }\n\n return returnValue;\n }\n}\n"],"mappings":";;;;;AA0BA,IAAa,mBAAb,cAAgEA,oCAAe;CAC7E,eAAyB,CAAC,WAAY;CAEtC;CAEA;CAEA;CAEA,QAAQ;CAER,UAAU;CAEV,YAAYC,QAAoC;EAC9C,OAAO;EACP,KAAK,OAAO,OAAO,QAAQ,OAAO,KAAK;EACvC,KAAK,OAAO,OAAO;EACnB,KAAK,SAAS,OAAO,OAAO,EAAE,MAAM,OAAO,KAAM,IAAG;EACpD,KAAK,UAAU,OAAO,WAAW,KAAK;CACvC;CAED,MAAM,OACJC,OACAC,SACY;EACZ,MAAM,4DAA4B,KAAK,QAAQ,QAAQ;EAEvD,MAAM,cAAc,MAAMC,+DAAmC,cAC3D,cACA,YAAY,KAAK,KAAK,OAAO,aAAkB,CAChD;AAED,MAAIJ,oCAAS,WAAW,YAAY,IAAI,KAAK,QAC3C,QAAO,MAAMI,+DAAmC,cAC9C,cACA,YAAa,YAA+B,OAAO,OAAO,aAAa,CACxE;AAGH,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"RunnableCallable.cjs","names":["Runnable","fields: RunnableCallableArgs<I, O>","#state","input: I","options?: Partial<RunnableConfig> | undefined","AsyncLocalStorageProviderSingleton"],"sources":["../../src/agents/RunnableCallable.ts"],"sourcesContent":["import {\n mergeConfigs,\n Runnable,\n RunnableConfig,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\n\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\n\nexport class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[] = [\"langgraph\"];\n\n func: RunnableCallableArgs<I, O>[\"func\"];\n\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n\n config?: RunnableConfig;\n\n trace = true;\n\n recurse = true;\n\n #state: Awaited<O>;\n\n constructor(fields: RunnableCallableArgs<I, O>) {\n super();\n this.name = fields.name ?? fields.func.name;\n this.func = fields.func;\n this.config = fields.tags ? { tags: fields.tags } : undefined;\n this.recurse = fields.recurse ?? this.recurse;\n }\n\n getState(): Awaited<O> {\n return this.#state;\n }\n\n async invoke(\n input: I,\n options?: Partial<RunnableConfig> | undefined\n ): Promise<O> {\n const mergedConfig = mergeConfigs(this.config, options);\n\n const returnValue = await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => this.func(input, mergedConfig as I)\n );\n\n if (Runnable.isRunnable(returnValue) && this.recurse) {\n return await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => (returnValue as Runnable<I, O>).invoke(input, mergedConfig)\n );\n }\n\n this.#state = returnValue;\n return returnValue;\n }\n}\n"],"mappings":";;;;;AA0BA,IAAa,mBAAb,cAAgEA,oCAAe;CAC7E,eAAyB,CAAC,WAAY;CAEtC;CAEA;CAEA;CAEA,QAAQ;CAER,UAAU;CAEV;CAEA,YAAYC,QAAoC;EAC9C,OAAO;EACP,KAAK,OAAO,OAAO,QAAQ,OAAO,KAAK;EACvC,KAAK,OAAO,OAAO;EACnB,KAAK,SAAS,OAAO,OAAO,EAAE,MAAM,OAAO,KAAM,IAAG;EACpD,KAAK,UAAU,OAAO,WAAW,KAAK;CACvC;CAED,WAAuB;AACrB,SAAO,KAAKC;CACb;CAED,MAAM,OACJC,OACAC,SACY;EACZ,MAAM,4DAA4B,KAAK,QAAQ,QAAQ;EAEvD,MAAM,cAAc,MAAMC,+DAAmC,cAC3D,cACA,YAAY,KAAK,KAAK,OAAO,aAAkB,CAChD;AAED,MAAIL,oCAAS,WAAW,YAAY,IAAI,KAAK,QAC3C,QAAO,MAAMK,+DAAmC,cAC9C,cACA,YAAa,YAA+B,OAAO,OAAO,aAAa,CACxE;EAGH,KAAKH,SAAS;AACd,SAAO;CACR;AACF"}
@@ -20,6 +20,7 @@ interface RunnableCallableArgs<I, O> {
20
20
  recurse?: boolean;
21
21
  }
22
22
  declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {
23
+ #private;
23
24
  lc_namespace: string[];
24
25
  func: RunnableCallableArgs<I, O>["func"];
25
26
  tags?: RunnableCallableArgs<I, O>["tags"];
@@ -27,6 +28,7 @@ declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O>
27
28
  trace: boolean;
28
29
  recurse: boolean;
29
30
  constructor(fields: RunnableCallableArgs<I, O>);
31
+ getState(): Awaited<O>;
30
32
  invoke(input: I, options?: Partial<RunnableConfig> | undefined): Promise<O>;
31
33
  }
32
34
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"RunnableCallable.d.cts","names":["Runnable","RunnableConfig","RunnableCallableArgs","I","O","Promise","RunnableCallable","Partial"],"sources":["../../src/agents/RunnableCallable.d.ts"],"sourcesContent":["import { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\nexport declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[];\n func: RunnableCallableArgs<I, O>[\"func\"];\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n config?: RunnableConfig;\n trace: boolean;\n recurse: boolean;\n constructor(fields: RunnableCallableArgs<I, O>);\n invoke(input: I, options?: Partial<RunnableConfig> | undefined): Promise<O>;\n}\n"],"mappings":";;;UACiBE;;AAAjB;;EAAqC,IAQjBC,CAAAA,EAAAA,MAAAA;EAAC;;;EAAkB,IAAA,EAAA,CAAA,GAAA,IAAA,EAAnBA,CAAmB,EAAA,EAAA,GAAXC,CAAW,GAAPC,OAAO,CAACD,CAAD,CAAA;EAUlBE;;;EAA6D,IAAEF,CAAAA,EAAAA,MAAAA,EAAAA;EAAC;;;EAEvD,OACED,CAAAA,EAAAA,OAAAA;;AAArBD,cAHUI,gBAGVJ,CAAAA,IAAAA,OAAAA,EAAAA,IAAAA,OAAAA,CAAAA,SAH6DF,QAG7DE,CAHsEC,CAGtED,EAHyEE,CAGzEF,CAAAA,CAAAA;EAAoB,YAClBD,EAAAA,MAAAA,EAAAA;EAAc,IAGkBE,EALnCD,oBAKmCC,CALdA,CAKcA,EALXC,CAKWD,CAAAA,CAAAA,MAAAA,CAAAA;EAAC,IAAEC,CAAAA,EAJrCF,oBAIqCE,CAJhBD,CAIgBC,EAJbA,CAIaA,CAAAA,CAAAA,MAAAA,CAAAA;EAAC,MAAzBF,CAAAA,EAHXD,cAGWC;EAAoB,KAC1BC,EAAAA,OAAAA;EAAC,OAAoBF,EAAAA,OAAAA;EAAc,WAAtBM,CAAAA,MAAAA,EADPL,oBACOK,CADcJ,CACdI,EADiBH,CACjBG,CAAAA;EAAO,MAAuCH,CAAAA,KAAAA,EAA3DD,CAA2DC,EAAAA,OAAAA,CAAAA,EAA9CG,OAA8CH,CAAtCH,cAAsCG,CAAAA,GAAAA,SAAAA,CAAAA,EAARC,OAAQD,CAAAA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"RunnableCallable.d.cts","names":["Runnable","RunnableConfig","RunnableCallableArgs","I","O","Promise","RunnableCallable","Awaited","Partial"],"sources":["../../src/agents/RunnableCallable.d.ts"],"sourcesContent":["import { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\nexport declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n #private;\n lc_namespace: string[];\n func: RunnableCallableArgs<I, O>[\"func\"];\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n config?: RunnableConfig;\n trace: boolean;\n recurse: boolean;\n constructor(fields: RunnableCallableArgs<I, O>);\n getState(): Awaited<O>;\n invoke(input: I, options?: Partial<RunnableConfig> | undefined): Promise<O>;\n}\n"],"mappings":";;;UACiBE;;AAAjB;;EAAqC,IAQjBC,CAAAA,EAAAA,MAAAA;EAAC;;;EAAkB,IAAA,EAAA,CAAA,GAAA,IAAA,EAAnBA,CAAmB,EAAA,EAAA,GAAXC,CAAW,GAAPC,OAAO,CAACD,CAAD,CAAA;EAUlBE;;;EAA6D,IAAEF,CAAAA,EAAAA,MAAAA,EAAAA;EAAC;;;EAGvD,OACED,CAAAA,EAAAA,OAAAA;;AAArBD,cAJUI,gBAIVJ,CAAAA,IAAAA,OAAAA,EAAAA,IAAAA,OAAAA,CAAAA,SAJ6DF,QAI7DE,CAJsEC,CAItED,EAJyEE,CAIzEF,CAAAA,CAAAA;EAAoB,CAAA,OAClBD;EAAc,YAGkBE,EAAAA,MAAAA,EAAAA;EAAC,IAAEC,EALtCF,oBAKsCE,CALjBD,CAKiBC,EALdA,CAKcA,CAAAA,CAAAA,MAAAA,CAAAA;EAAC,IAAzBF,CAAAA,EAJbA,oBAIaA,CAJQC,CAIRD,EAJWE,CAIXF,CAAAA,CAAAA,MAAAA,CAAAA;EAAoB,MACpBE,CAAAA,EAJXH,cAIWG;EAAC,KAATG,EAAAA,OAAAA;EAAO,OACLJ,EAAAA,OAAAA;EAAC,WAAoBF,CAAAA,MAAAA,EAFfC,oBAEeD,CAFME,CAENF,EAFSG,CAETH,CAAAA;EAAc,QAAtBO,CAAAA,CAAAA,EADfD,OACeC,CADPJ,CACOI,CAAAA;EAAO,MAAuCJ,CAAAA,KAAAA,EAA3DD,CAA2DC,EAAAA,OAAAA,CAAAA,EAA9CI,OAA8CJ,CAAtCH,cAAsCG,CAAAA,GAAAA,SAAAA,CAAAA,EAARC,OAAQD,CAAAA,CAAAA,CAAAA"}
@@ -20,6 +20,7 @@ interface RunnableCallableArgs<I, O> {
20
20
  recurse?: boolean;
21
21
  }
22
22
  declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {
23
+ #private;
23
24
  lc_namespace: string[];
24
25
  func: RunnableCallableArgs<I, O>["func"];
25
26
  tags?: RunnableCallableArgs<I, O>["tags"];
@@ -27,6 +28,7 @@ declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O>
27
28
  trace: boolean;
28
29
  recurse: boolean;
29
30
  constructor(fields: RunnableCallableArgs<I, O>);
31
+ getState(): Awaited<O>;
30
32
  invoke(input: I, options?: Partial<RunnableConfig> | undefined): Promise<O>;
31
33
  }
32
34
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"RunnableCallable.d.ts","names":["Runnable","RunnableConfig","RunnableCallableArgs","I","O","Promise","RunnableCallable","Partial"],"sources":["../../src/agents/RunnableCallable.d.ts"],"sourcesContent":["import { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\nexport declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[];\n func: RunnableCallableArgs<I, O>[\"func\"];\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n config?: RunnableConfig;\n trace: boolean;\n recurse: boolean;\n constructor(fields: RunnableCallableArgs<I, O>);\n invoke(input: I, options?: Partial<RunnableConfig> | undefined): Promise<O>;\n}\n"],"mappings":";;;UACiBE;;AAAjB;;EAAqC,IAQjBC,CAAAA,EAAAA,MAAAA;EAAC;;;EAAkB,IAAA,EAAA,CAAA,GAAA,IAAA,EAAnBA,CAAmB,EAAA,EAAA,GAAXC,CAAW,GAAPC,OAAO,CAACD,CAAD,CAAA;EAUlBE;;;EAA6D,IAAEF,CAAAA,EAAAA,MAAAA,EAAAA;EAAC;;;EAEvD,OACED,CAAAA,EAAAA,OAAAA;;AAArBD,cAHUI,gBAGVJ,CAAAA,IAAAA,OAAAA,EAAAA,IAAAA,OAAAA,CAAAA,SAH6DF,QAG7DE,CAHsEC,CAGtED,EAHyEE,CAGzEF,CAAAA,CAAAA;EAAoB,YAClBD,EAAAA,MAAAA,EAAAA;EAAc,IAGkBE,EALnCD,oBAKmCC,CALdA,CAKcA,EALXC,CAKWD,CAAAA,CAAAA,MAAAA,CAAAA;EAAC,IAAEC,CAAAA,EAJrCF,oBAIqCE,CAJhBD,CAIgBC,EAJbA,CAIaA,CAAAA,CAAAA,MAAAA,CAAAA;EAAC,MAAzBF,CAAAA,EAHXD,cAGWC;EAAoB,KAC1BC,EAAAA,OAAAA;EAAC,OAAoBF,EAAAA,OAAAA;EAAc,WAAtBM,CAAAA,MAAAA,EADPL,oBACOK,CADcJ,CACdI,EADiBH,CACjBG,CAAAA;EAAO,MAAuCH,CAAAA,KAAAA,EAA3DD,CAA2DC,EAAAA,OAAAA,CAAAA,EAA9CG,OAA8CH,CAAtCH,cAAsCG,CAAAA,GAAAA,SAAAA,CAAAA,EAARC,OAAQD,CAAAA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"RunnableCallable.d.ts","names":["Runnable","RunnableConfig","RunnableCallableArgs","I","O","Promise","RunnableCallable","Awaited","Partial"],"sources":["../../src/agents/RunnableCallable.d.ts"],"sourcesContent":["import { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\nexport declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n #private;\n lc_namespace: string[];\n func: RunnableCallableArgs<I, O>[\"func\"];\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n config?: RunnableConfig;\n trace: boolean;\n recurse: boolean;\n constructor(fields: RunnableCallableArgs<I, O>);\n getState(): Awaited<O>;\n invoke(input: I, options?: Partial<RunnableConfig> | undefined): Promise<O>;\n}\n"],"mappings":";;;UACiBE;;AAAjB;;EAAqC,IAQjBC,CAAAA,EAAAA,MAAAA;EAAC;;;EAAkB,IAAA,EAAA,CAAA,GAAA,IAAA,EAAnBA,CAAmB,EAAA,EAAA,GAAXC,CAAW,GAAPC,OAAO,CAACD,CAAD,CAAA;EAUlBE;;;EAA6D,IAAEF,CAAAA,EAAAA,MAAAA,EAAAA;EAAC;;;EAGvD,OACED,CAAAA,EAAAA,OAAAA;;AAArBD,cAJUI,gBAIVJ,CAAAA,IAAAA,OAAAA,EAAAA,IAAAA,OAAAA,CAAAA,SAJ6DF,QAI7DE,CAJsEC,CAItED,EAJyEE,CAIzEF,CAAAA,CAAAA;EAAoB,CAAA,OAClBD;EAAc,YAGkBE,EAAAA,MAAAA,EAAAA;EAAC,IAAEC,EALtCF,oBAKsCE,CALjBD,CAKiBC,EALdA,CAKcA,CAAAA,CAAAA,MAAAA,CAAAA;EAAC,IAAzBF,CAAAA,EAJbA,oBAIaA,CAJQC,CAIRD,EAJWE,CAIXF,CAAAA,CAAAA,MAAAA,CAAAA;EAAoB,MACpBE,CAAAA,EAJXH,cAIWG;EAAC,KAATG,EAAAA,OAAAA;EAAO,OACLJ,EAAAA,OAAAA;EAAC,WAAoBF,CAAAA,MAAAA,EAFfC,oBAEeD,CAFME,CAENF,EAFSG,CAETH,CAAAA;EAAc,QAAtBO,CAAAA,CAAAA,EADfD,OACeC,CADPJ,CACOI,CAAAA;EAAO,MAAuCJ,CAAAA,KAAAA,EAA3DD,CAA2DC,EAAAA,OAAAA,CAAAA,EAA9CI,OAA8CJ,CAAtCH,cAAsCG,CAAAA,GAAAA,SAAAA,CAAAA,EAARC,OAAQD,CAAAA,CAAAA,CAAAA"}
@@ -9,6 +9,7 @@ var RunnableCallable = class extends Runnable {
9
9
  config;
10
10
  trace = true;
11
11
  recurse = true;
12
+ #state;
12
13
  constructor(fields) {
13
14
  super();
14
15
  this.name = fields.name ?? fields.func.name;
@@ -16,10 +17,14 @@ var RunnableCallable = class extends Runnable {
16
17
  this.config = fields.tags ? { tags: fields.tags } : void 0;
17
18
  this.recurse = fields.recurse ?? this.recurse;
18
19
  }
20
+ getState() {
21
+ return this.#state;
22
+ }
19
23
  async invoke(input, options) {
20
24
  const mergedConfig = mergeConfigs(this.config, options);
21
25
  const returnValue = await AsyncLocalStorageProviderSingleton.runWithConfig(mergedConfig, async () => this.func(input, mergedConfig));
22
26
  if (Runnable.isRunnable(returnValue) && this.recurse) return await AsyncLocalStorageProviderSingleton.runWithConfig(mergedConfig, async () => returnValue.invoke(input, mergedConfig));
27
+ this.#state = returnValue;
23
28
  return returnValue;
24
29
  }
25
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RunnableCallable.js","names":["fields: RunnableCallableArgs<I, O>","input: I","options?: Partial<RunnableConfig> | undefined"],"sources":["../../src/agents/RunnableCallable.ts"],"sourcesContent":["import {\n mergeConfigs,\n Runnable,\n RunnableConfig,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\n\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\n\nexport class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[] = [\"langgraph\"];\n\n func: RunnableCallableArgs<I, O>[\"func\"];\n\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n\n config?: RunnableConfig;\n\n trace = true;\n\n recurse = true;\n\n constructor(fields: RunnableCallableArgs<I, O>) {\n super();\n this.name = fields.name ?? fields.func.name;\n this.func = fields.func;\n this.config = fields.tags ? { tags: fields.tags } : undefined;\n this.recurse = fields.recurse ?? this.recurse;\n }\n\n async invoke(\n input: I,\n options?: Partial<RunnableConfig> | undefined\n ): Promise<O> {\n const mergedConfig = mergeConfigs(this.config, options);\n\n const returnValue = await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => this.func(input, mergedConfig as I)\n );\n\n if (Runnable.isRunnable(returnValue) && this.recurse) {\n return await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => (returnValue as Runnable<I, O>).invoke(input, mergedConfig)\n );\n }\n\n return returnValue;\n }\n}\n"],"mappings":";;;;AA0BA,IAAa,mBAAb,cAAgE,SAAe;CAC7E,eAAyB,CAAC,WAAY;CAEtC;CAEA;CAEA;CAEA,QAAQ;CAER,UAAU;CAEV,YAAYA,QAAoC;EAC9C,OAAO;EACP,KAAK,OAAO,OAAO,QAAQ,OAAO,KAAK;EACvC,KAAK,OAAO,OAAO;EACnB,KAAK,SAAS,OAAO,OAAO,EAAE,MAAM,OAAO,KAAM,IAAG;EACpD,KAAK,UAAU,OAAO,WAAW,KAAK;CACvC;CAED,MAAM,OACJC,OACAC,SACY;EACZ,MAAM,eAAe,aAAa,KAAK,QAAQ,QAAQ;EAEvD,MAAM,cAAc,MAAM,mCAAmC,cAC3D,cACA,YAAY,KAAK,KAAK,OAAO,aAAkB,CAChD;AAED,MAAI,SAAS,WAAW,YAAY,IAAI,KAAK,QAC3C,QAAO,MAAM,mCAAmC,cAC9C,cACA,YAAa,YAA+B,OAAO,OAAO,aAAa,CACxE;AAGH,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"RunnableCallable.js","names":["fields: RunnableCallableArgs<I, O>","#state","input: I","options?: Partial<RunnableConfig> | undefined"],"sources":["../../src/agents/RunnableCallable.ts"],"sourcesContent":["import {\n mergeConfigs,\n Runnable,\n RunnableConfig,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\n\nexport interface RunnableCallableArgs<I, O> {\n /**\n * The name of the runnable.\n */\n name?: string;\n /**\n * The function to call.\n */\n func: (...args: I[]) => O | Promise<O>;\n /**\n * The tags to add to the runnable.\n */\n tags?: string[];\n /**\n * Whether to recurse the runnable.\n */\n recurse?: boolean;\n}\n\nexport class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[] = [\"langgraph\"];\n\n func: RunnableCallableArgs<I, O>[\"func\"];\n\n tags?: RunnableCallableArgs<I, O>[\"tags\"];\n\n config?: RunnableConfig;\n\n trace = true;\n\n recurse = true;\n\n #state: Awaited<O>;\n\n constructor(fields: RunnableCallableArgs<I, O>) {\n super();\n this.name = fields.name ?? fields.func.name;\n this.func = fields.func;\n this.config = fields.tags ? { tags: fields.tags } : undefined;\n this.recurse = fields.recurse ?? this.recurse;\n }\n\n getState(): Awaited<O> {\n return this.#state;\n }\n\n async invoke(\n input: I,\n options?: Partial<RunnableConfig> | undefined\n ): Promise<O> {\n const mergedConfig = mergeConfigs(this.config, options);\n\n const returnValue = await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => this.func(input, mergedConfig as I)\n );\n\n if (Runnable.isRunnable(returnValue) && this.recurse) {\n return await AsyncLocalStorageProviderSingleton.runWithConfig(\n mergedConfig,\n async () => (returnValue as Runnable<I, O>).invoke(input, mergedConfig)\n );\n }\n\n this.#state = returnValue;\n return returnValue;\n }\n}\n"],"mappings":";;;;AA0BA,IAAa,mBAAb,cAAgE,SAAe;CAC7E,eAAyB,CAAC,WAAY;CAEtC;CAEA;CAEA;CAEA,QAAQ;CAER,UAAU;CAEV;CAEA,YAAYA,QAAoC;EAC9C,OAAO;EACP,KAAK,OAAO,OAAO,QAAQ,OAAO,KAAK;EACvC,KAAK,OAAO,OAAO;EACnB,KAAK,SAAS,OAAO,OAAO,EAAE,MAAM,OAAO,KAAM,IAAG;EACpD,KAAK,UAAU,OAAO,WAAW,KAAK;CACvC;CAED,WAAuB;AACrB,SAAO,KAAKC;CACb;CAED,MAAM,OACJC,OACAC,SACY;EACZ,MAAM,eAAe,aAAa,KAAK,QAAQ,QAAQ;EAEvD,MAAM,cAAc,MAAM,mCAAmC,cAC3D,cACA,YAAY,KAAK,KAAK,OAAO,aAAkB,CAChD;AAED,MAAI,SAAS,WAAW,YAAY,IAAI,KAAK,QAC3C,QAAO,MAAM,mCAAmC,cAC9C,cACA,YAAa,YAA+B,OAAO,OAAO,aAAa,CACxE;EAGH,KAAKF,SAAS;AACd,SAAO;CACR;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { ResponseFormatUndefined } from "./responses.cjs";
2
2
  import { InteropZodObject } from "@langchain/core/utils/types";
3
- import { BaseMessage } from "@langchain/core/messages";
4
3
  import { AnnotationRoot, BinaryOperatorAggregate, LastValue, Messages } from "@langchain/langgraph";
4
+ import { BaseMessage } from "@langchain/core/messages";
5
5
  import { InteropZodToStateDefinition } from "@langchain/langgraph/zod";
6
6
 
7
7
  //#region src/agents/annotation.d.ts
@@ -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,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 createAgent(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.createAgent = createAgent;
34
+ exports.createAgent = createAgent$2;
16
35
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["params: CreateAgentParams<\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 { 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\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":";;;;;;;;;AAqQA,SAAgB,YAKdA,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"}
@@ -3,26 +3,27 @@ import { JsonSchemaFormat, ProviderStrategy, ResponseFormat, ResponseFormatUndef
3
3
  import { AnyAnnotationRoot } from "./annotation.cjs";
4
4
  import { ToolNode } from "./nodes/ToolNode.cjs";
5
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
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 = createAgent({ 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
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
55
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)
65
+ // Overload 2: V1 - With responseFormat as array of InteropZodTypes
59
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)
69
+ // Overload 3: V1 - With responseFormat as JsonSchemaFormat
63
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)
73
+ // Overload 4: V1 - With responseFormat as array of JsonSchemaFormat
67
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[]
77
+ // Overload 5: V1 - With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]
71
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)
81
+ // Overload 6: V1 - With responseFormat as TypedToolStrategy
75
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
85
+ // Overload 7: V1 - With responseFormat as single ToolStrategy
79
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
89
+ // Overload 8: V1 - With responseFormat as ProviderStrategy
83
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
93
+ // Overload 9: V1 - Without responseFormat property at all
87
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>;
88
- // Overload 9: With responseFormat explicitly undefined
95
+ // Overload 10: V1 - With responseFormat explicitly undefined
89
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 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, 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
160
  export { createAgent };
98
161
  //# sourceMappingURL=index.d.cts.map