langchain 0.0.212 → 0.0.214

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 (138) hide show
  1. package/README.md +1 -1
  2. package/chains/combine_documents.cjs +1 -0
  3. package/chains/combine_documents.d.ts +1 -0
  4. package/chains/combine_documents.js +1 -0
  5. package/chains/history_aware_retriever.cjs +1 -0
  6. package/chains/history_aware_retriever.d.ts +1 -0
  7. package/chains/history_aware_retriever.js +1 -0
  8. package/chains/retrieval.cjs +1 -0
  9. package/chains/retrieval.d.ts +1 -0
  10. package/chains/retrieval.js +1 -0
  11. package/dist/agents/agent.cjs +1 -0
  12. package/dist/agents/agent.js +1 -0
  13. package/dist/agents/executor.cjs +21 -3
  14. package/dist/agents/executor.d.ts +1 -0
  15. package/dist/agents/executor.js +21 -3
  16. package/dist/agents/format_scratchpad/openai_functions.cjs +22 -1
  17. package/dist/agents/format_scratchpad/openai_functions.d.ts +10 -0
  18. package/dist/agents/format_scratchpad/openai_functions.js +21 -1
  19. package/dist/agents/index.cjs +11 -4
  20. package/dist/agents/index.d.ts +6 -3
  21. package/dist/agents/index.js +5 -3
  22. package/dist/agents/initialize.cjs +1 -1
  23. package/dist/agents/initialize.d.ts +1 -1
  24. package/dist/agents/initialize.js +1 -1
  25. package/dist/agents/openai/output_parser.cjs +20 -196
  26. package/dist/agents/openai/output_parser.d.ts +2 -111
  27. package/dist/agents/openai/output_parser.js +6 -193
  28. package/dist/agents/{openai → openai_functions}/index.cjs +80 -2
  29. package/dist/agents/{openai → openai_functions}/index.d.ts +77 -3
  30. package/dist/agents/{openai → openai_functions}/index.js +78 -1
  31. package/dist/agents/openai_functions/output_parser.cjs +102 -0
  32. package/dist/agents/openai_functions/output_parser.d.ts +56 -0
  33. package/dist/agents/openai_functions/output_parser.js +98 -0
  34. package/dist/agents/openai_tools/index.cjs +83 -0
  35. package/dist/agents/openai_tools/index.d.ts +82 -0
  36. package/dist/agents/openai_tools/index.js +79 -0
  37. package/dist/agents/openai_tools/output_parser.cjs +102 -0
  38. package/dist/agents/openai_tools/output_parser.d.ts +57 -0
  39. package/dist/agents/openai_tools/output_parser.js +98 -0
  40. package/dist/agents/react/index.cjs +77 -0
  41. package/dist/agents/react/index.d.ts +62 -0
  42. package/dist/agents/react/index.js +73 -0
  43. package/dist/agents/react/output_parser.cjs +0 -1
  44. package/dist/agents/react/output_parser.d.ts +0 -1
  45. package/dist/agents/react/output_parser.js +0 -1
  46. package/dist/agents/structured_chat/index.cjs +87 -1
  47. package/dist/agents/structured_chat/index.d.ts +73 -0
  48. package/dist/agents/structured_chat/index.js +85 -0
  49. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.cjs +1 -1
  50. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.js +1 -1
  51. package/dist/agents/toolkits/conversational_retrieval/tool.cjs +1 -0
  52. package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +1 -0
  53. package/dist/agents/toolkits/conversational_retrieval/tool.js +1 -0
  54. package/dist/agents/toolkits/json/json.cjs +2 -0
  55. package/dist/agents/toolkits/json/json.d.ts +2 -0
  56. package/dist/agents/toolkits/json/json.js +2 -0
  57. package/dist/agents/toolkits/openapi/openapi.cjs +2 -0
  58. package/dist/agents/toolkits/openapi/openapi.d.ts +2 -0
  59. package/dist/agents/toolkits/openapi/openapi.js +2 -0
  60. package/dist/agents/toolkits/vectorstore/vectorstore.cjs +2 -0
  61. package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +2 -0
  62. package/dist/agents/toolkits/vectorstore/vectorstore.js +2 -0
  63. package/dist/agents/xml/index.cjs +77 -1
  64. package/dist/agents/xml/index.d.ts +67 -0
  65. package/dist/agents/xml/index.js +75 -0
  66. package/dist/callbacks/index.cjs +1 -4
  67. package/dist/callbacks/index.d.ts +1 -2
  68. package/dist/callbacks/index.js +1 -2
  69. package/dist/chains/combine_documents/base.cjs +16 -0
  70. package/dist/chains/combine_documents/base.d.ts +13 -0
  71. package/dist/chains/combine_documents/base.js +12 -0
  72. package/dist/chains/combine_documents/index.cjs +5 -0
  73. package/dist/chains/combine_documents/index.d.ts +1 -0
  74. package/dist/chains/combine_documents/index.js +1 -0
  75. package/dist/chains/combine_documents/reduce.cjs +5 -2
  76. package/dist/chains/combine_documents/reduce.js +4 -1
  77. package/dist/chains/combine_documents/stuff.cjs +42 -0
  78. package/dist/chains/combine_documents/stuff.d.ts +28 -0
  79. package/dist/chains/combine_documents/stuff.js +38 -0
  80. package/dist/chains/conversational_retrieval_chain.cjs +3 -3
  81. package/dist/chains/conversational_retrieval_chain.js +1 -1
  82. package/dist/chains/history_aware_retriever.cjs +55 -0
  83. package/dist/chains/history_aware_retriever.d.ts +55 -0
  84. package/dist/chains/history_aware_retriever.js +51 -0
  85. package/dist/chains/openai_functions/structured_output.cjs +63 -21
  86. package/dist/chains/openai_functions/structured_output.d.ts +25 -17
  87. package/dist/chains/openai_functions/structured_output.js +62 -20
  88. package/dist/chains/retrieval.cjs +60 -0
  89. package/dist/chains/retrieval.d.ts +65 -0
  90. package/dist/chains/retrieval.js +56 -0
  91. package/dist/experimental/autogpt/prompt.cjs +1 -1
  92. package/dist/experimental/autogpt/prompt.d.ts +1 -1
  93. package/dist/experimental/autogpt/prompt.js +1 -1
  94. package/dist/load/import_map.cjs +7 -3
  95. package/dist/load/import_map.d.ts +4 -0
  96. package/dist/load/import_map.js +4 -0
  97. package/dist/output_parsers/json.cjs +2 -78
  98. package/dist/output_parsers/json.d.ts +1 -1
  99. package/dist/output_parsers/json.js +1 -77
  100. package/dist/output_parsers/openai_functions.d.ts +1 -1
  101. package/dist/retrievers/multi_vector.cjs +11 -2
  102. package/dist/retrievers/multi_vector.d.ts +5 -3
  103. package/dist/retrievers/multi_vector.js +11 -2
  104. package/dist/retrievers/parent_document.cjs +1 -2
  105. package/dist/retrievers/parent_document.d.ts +1 -1
  106. package/dist/retrievers/parent_document.js +1 -2
  107. package/dist/retrievers/remote/chatgpt-plugin.cjs +5 -4
  108. package/dist/retrievers/remote/chatgpt-plugin.d.ts +5 -2
  109. package/dist/retrievers/remote/chatgpt-plugin.js +3 -2
  110. package/dist/retrievers/remote/index.cjs +2 -2
  111. package/dist/retrievers/remote/index.d.ts +1 -1
  112. package/dist/retrievers/remote/index.js +1 -1
  113. package/dist/retrievers/remote/remote-retriever.cjs +3 -2
  114. package/dist/retrievers/remote/remote-retriever.d.ts +3 -1
  115. package/dist/retrievers/remote/remote-retriever.js +2 -1
  116. package/dist/retrievers/vespa.cjs +15 -78
  117. package/dist/retrievers/vespa.d.ts +1 -54
  118. package/dist/retrievers/vespa.js +1 -76
  119. package/dist/schema/runnable/config.d.ts +1 -1
  120. package/dist/tools/retriever.cjs +17 -0
  121. package/dist/tools/retriever.d.ts +10 -0
  122. package/dist/tools/retriever.js +13 -0
  123. package/dist/util/entrypoint_deprecation.cjs +18 -0
  124. package/dist/util/entrypoint_deprecation.d.ts +5 -0
  125. package/dist/util/entrypoint_deprecation.js +14 -0
  126. package/package.json +36 -4
  127. package/tools/retriever.cjs +1 -0
  128. package/tools/retriever.d.ts +1 -0
  129. package/tools/retriever.js +1 -0
  130. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +0 -17
  131. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +0 -1
  132. package/dist/callbacks/handlers/tracer_langchain_v1.js +0 -1
  133. package/dist/retrievers/remote/base.cjs +0 -68
  134. package/dist/retrievers/remote/base.d.ts +0 -60
  135. package/dist/retrievers/remote/base.js +0 -64
  136. /package/dist/agents/{openai → openai_functions}/prompt.cjs +0 -0
  137. /package/dist/agents/{openai → openai_functions}/prompt.d.ts +0 -0
  138. /package/dist/agents/{openai → openai_functions}/prompt.js +0 -0
package/README.md CHANGED
@@ -63,7 +63,7 @@ This library aims to assist in the development of those types of applications. C
63
63
 
64
64
  **💬 Chatbots**
65
65
 
66
- - [Documentation](https://js.langchain.com/docs/modules/model_io/models/chat/)
66
+ - [Documentation](https://js.langchain.com/docs/modules/models/chat/)
67
67
  - End-to-end Example: [Chat-LangChain](https://github.com/langchain-ai/chat-langchain)
68
68
 
69
69
  ## 🚀 How does LangChain help?
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/chains/combine_documents/index.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/chains/combine_documents/index.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/chains/combine_documents/index.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/chains/history_aware_retriever.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/chains/history_aware_retriever.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/chains/history_aware_retriever.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/chains/retrieval.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/chains/retrieval.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/chains/retrieval.js'
@@ -103,6 +103,7 @@ class RunnableAgent extends BaseMultiActionAgent {
103
103
  writable: true,
104
104
  value: ["langchain", "agents", "runnable"]
105
105
  });
106
+ // TODO: Rename input to "intermediate_steps"
106
107
  Object.defineProperty(this, "runnable", {
107
108
  enumerable: true,
108
109
  configurable: true,
@@ -97,6 +97,7 @@ export class RunnableAgent extends BaseMultiActionAgent {
97
97
  writable: true,
98
98
  value: ["langchain", "agents", "runnable"]
99
99
  });
100
+ // TODO: Rename input to "intermediate_steps"
100
101
  Object.defineProperty(this, "runnable", {
101
102
  enumerable: true,
102
103
  configurable: true,
@@ -269,8 +269,11 @@ class AgentExecutor extends base_js_1.BaseChain {
269
269
  }
270
270
  constructor(input) {
271
271
  let agent;
272
+ let returnOnlyOutputs = true;
272
273
  if (runnables_1.Runnable.isRunnable(input.agent)) {
273
274
  agent = new agent_js_1.RunnableAgent({ runnable: input.agent });
275
+ // TODO: Update BaseChain implementation on breaking change
276
+ returnOnlyOutputs = false;
274
277
  }
275
278
  else {
276
279
  agent = input.agent;
@@ -306,6 +309,13 @@ class AgentExecutor extends base_js_1.BaseChain {
306
309
  writable: true,
307
310
  value: "force"
308
311
  });
312
+ // TODO: Update BaseChain implementation on breaking change to include this
313
+ Object.defineProperty(this, "returnOnlyOutputs", {
314
+ enumerable: true,
315
+ configurable: true,
316
+ writable: true,
317
+ value: true
318
+ });
309
319
  /**
310
320
  * How to handle errors raised by the agent's output parser.
311
321
  Defaults to `False`, which raises the error.
@@ -326,6 +336,7 @@ class AgentExecutor extends base_js_1.BaseChain {
326
336
  this.tools = input.tools;
327
337
  this.handleParsingErrors =
328
338
  input.handleParsingErrors ?? this.handleParsingErrors;
339
+ this.returnOnlyOutputs = returnOnlyOutputs;
329
340
  if (this.agent._agentActionType() === "multi") {
330
341
  for (const tool of this.tools) {
331
342
  if (tool.returnDirect) {
@@ -363,11 +374,18 @@ class AgentExecutor extends base_js_1.BaseChain {
363
374
  const getOutput = async (finishStep) => {
364
375
  const { returnValues } = finishStep;
365
376
  const additional = await this.agent.prepareForOutput(returnValues, steps);
377
+ await runManager?.handleAgentEnd(finishStep);
378
+ let response;
366
379
  if (this.returnIntermediateSteps) {
367
- return { ...returnValues, intermediateSteps: steps, ...additional };
380
+ response = { ...returnValues, intermediateSteps: steps, ...additional };
368
381
  }
369
- await runManager?.handleAgentEnd(finishStep);
370
- return { ...returnValues, ...additional };
382
+ else {
383
+ response = { ...returnValues, ...additional };
384
+ }
385
+ if (!this.returnOnlyOutputs) {
386
+ response = { ...inputs, ...response };
387
+ }
388
+ return response;
371
389
  };
372
390
  while (this.shouldContinue(iterations)) {
373
391
  let output;
@@ -113,6 +113,7 @@ export declare class AgentExecutor extends BaseChain<ChainValues, AgentExecutorO
113
113
  returnIntermediateSteps: boolean;
114
114
  maxIterations?: number;
115
115
  earlyStoppingMethod: StoppingMethod;
116
+ returnOnlyOutputs: boolean;
116
117
  /**
117
118
  * How to handle errors raised by the agent's output parser.
118
119
  Defaults to `False`, which raises the error.
@@ -264,8 +264,11 @@ export class AgentExecutor extends BaseChain {
264
264
  }
265
265
  constructor(input) {
266
266
  let agent;
267
+ let returnOnlyOutputs = true;
267
268
  if (Runnable.isRunnable(input.agent)) {
268
269
  agent = new RunnableAgent({ runnable: input.agent });
270
+ // TODO: Update BaseChain implementation on breaking change
271
+ returnOnlyOutputs = false;
269
272
  }
270
273
  else {
271
274
  agent = input.agent;
@@ -301,6 +304,13 @@ export class AgentExecutor extends BaseChain {
301
304
  writable: true,
302
305
  value: "force"
303
306
  });
307
+ // TODO: Update BaseChain implementation on breaking change to include this
308
+ Object.defineProperty(this, "returnOnlyOutputs", {
309
+ enumerable: true,
310
+ configurable: true,
311
+ writable: true,
312
+ value: true
313
+ });
304
314
  /**
305
315
  * How to handle errors raised by the agent's output parser.
306
316
  Defaults to `False`, which raises the error.
@@ -321,6 +331,7 @@ export class AgentExecutor extends BaseChain {
321
331
  this.tools = input.tools;
322
332
  this.handleParsingErrors =
323
333
  input.handleParsingErrors ?? this.handleParsingErrors;
334
+ this.returnOnlyOutputs = returnOnlyOutputs;
324
335
  if (this.agent._agentActionType() === "multi") {
325
336
  for (const tool of this.tools) {
326
337
  if (tool.returnDirect) {
@@ -358,11 +369,18 @@ export class AgentExecutor extends BaseChain {
358
369
  const getOutput = async (finishStep) => {
359
370
  const { returnValues } = finishStep;
360
371
  const additional = await this.agent.prepareForOutput(returnValues, steps);
372
+ await runManager?.handleAgentEnd(finishStep);
373
+ let response;
361
374
  if (this.returnIntermediateSteps) {
362
- return { ...returnValues, intermediateSteps: steps, ...additional };
375
+ response = { ...returnValues, intermediateSteps: steps, ...additional };
363
376
  }
364
- await runManager?.handleAgentEnd(finishStep);
365
- return { ...returnValues, ...additional };
377
+ else {
378
+ response = { ...returnValues, ...additional };
379
+ }
380
+ if (!this.returnOnlyOutputs) {
381
+ response = { ...inputs, ...response };
382
+ }
383
+ return response;
366
384
  };
367
385
  while (this.shouldContinue(iterations)) {
368
386
  let output;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatForOpenAIFunctions = void 0;
3
+ exports.formatToOpenAIFunctionMessages = exports.formatForOpenAIFunctions = void 0;
4
4
  const template_js_1 = require("../../prompts/template.cjs");
5
5
  const index_js_1 = require("../../schema/index.cjs");
6
6
  const prompt_js_1 = require("../chat_convo/prompt.cjs");
@@ -9,6 +9,7 @@ const prompt_js_1 = require("../chat_convo/prompt.cjs");
9
9
  * agents that use OpenAI's API. Helpful for passing in previous agent
10
10
  * step context into new iterations.
11
11
  *
12
+ * @deprecated Use formatToOpenAIFunctionMessages instead.
12
13
  * @param steps A list of AgentSteps to format.
13
14
  * @returns A list of BaseMessages.
14
15
  */
@@ -23,3 +24,23 @@ function formatForOpenAIFunctions(steps) {
23
24
  return thoughts;
24
25
  }
25
26
  exports.formatForOpenAIFunctions = formatForOpenAIFunctions;
27
+ /**
28
+ * Format a list of AgentSteps into a list of BaseMessage instances for
29
+ * agents that use OpenAI's API. Helpful for passing in previous agent
30
+ * step context into new iterations.
31
+ *
32
+ * @param steps A list of AgentSteps to format.
33
+ * @returns A list of BaseMessages.
34
+ */
35
+ function formatToOpenAIFunctionMessages(steps) {
36
+ return steps.flatMap(({ action, observation }) => {
37
+ if ("messageLog" in action && action.messageLog !== undefined) {
38
+ const log = action.messageLog;
39
+ return log.concat(new index_js_1.FunctionMessage(observation, action.tool));
40
+ }
41
+ else {
42
+ return [new index_js_1.AIMessage(action.log)];
43
+ }
44
+ });
45
+ }
46
+ exports.formatToOpenAIFunctionMessages = formatToOpenAIFunctionMessages;
@@ -4,7 +4,17 @@ import { AgentStep, BaseMessage } from "../../schema/index.js";
4
4
  * agents that use OpenAI's API. Helpful for passing in previous agent
5
5
  * step context into new iterations.
6
6
  *
7
+ * @deprecated Use formatToOpenAIFunctionMessages instead.
7
8
  * @param steps A list of AgentSteps to format.
8
9
  * @returns A list of BaseMessages.
9
10
  */
10
11
  export declare function formatForOpenAIFunctions(steps: AgentStep[]): BaseMessage[];
12
+ /**
13
+ * Format a list of AgentSteps into a list of BaseMessage instances for
14
+ * agents that use OpenAI's API. Helpful for passing in previous agent
15
+ * step context into new iterations.
16
+ *
17
+ * @param steps A list of AgentSteps to format.
18
+ * @returns A list of BaseMessages.
19
+ */
20
+ export declare function formatToOpenAIFunctionMessages(steps: AgentStep[]): BaseMessage[];
@@ -1,11 +1,12 @@
1
1
  import { renderTemplate } from "../../prompts/template.js";
2
- import { AIMessage, HumanMessage, } from "../../schema/index.js";
2
+ import { AIMessage, HumanMessage, FunctionMessage, } from "../../schema/index.js";
3
3
  import { TEMPLATE_TOOL_RESPONSE } from "../chat_convo/prompt.js";
4
4
  /**
5
5
  * Format a list of AgentSteps into a list of BaseMessage instances for
6
6
  * agents that use OpenAI's API. Helpful for passing in previous agent
7
7
  * step context into new iterations.
8
8
  *
9
+ * @deprecated Use formatToOpenAIFunctionMessages instead.
9
10
  * @param steps A list of AgentSteps to format.
10
11
  * @returns A list of BaseMessages.
11
12
  */
@@ -19,3 +20,22 @@ export function formatForOpenAIFunctions(steps) {
19
20
  }
20
21
  return thoughts;
21
22
  }
23
+ /**
24
+ * Format a list of AgentSteps into a list of BaseMessage instances for
25
+ * agents that use OpenAI's API. Helpful for passing in previous agent
26
+ * step context into new iterations.
27
+ *
28
+ * @param steps A list of AgentSteps to format.
29
+ * @returns A list of BaseMessages.
30
+ */
31
+ export function formatToOpenAIFunctionMessages(steps) {
32
+ return steps.flatMap(({ action, observation }) => {
33
+ if ("messageLog" in action && action.messageLog !== undefined) {
34
+ const log = action.messageLog;
35
+ return log.concat(new FunctionMessage(observation, action.tool));
36
+ }
37
+ else {
38
+ return [new AIMessage(action.log)];
39
+ }
40
+ });
41
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.XMLAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
3
+ exports.createReactAgent = exports.createXmlAgent = exports.XMLAgent = exports.createOpenAIToolsAgent = exports.createOpenAIFunctionsAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.createStructuredChatAgent = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
4
4
  var agent_js_1 = require("./agent.cjs");
5
5
  Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_js_1.Agent; } });
6
6
  Object.defineProperty(exports, "BaseSingleActionAgent", { enumerable: true, get: function () { return agent_js_1.BaseSingleActionAgent; } });
@@ -42,10 +42,17 @@ var types_js_1 = require("./types.cjs");
42
42
  Object.defineProperty(exports, "AgentActionOutputParser", { enumerable: true, get: function () { return types_js_1.AgentActionOutputParser; } });
43
43
  var index_js_5 = require("./structured_chat/index.cjs");
44
44
  Object.defineProperty(exports, "StructuredChatAgent", { enumerable: true, get: function () { return index_js_5.StructuredChatAgent; } });
45
+ Object.defineProperty(exports, "createStructuredChatAgent", { enumerable: true, get: function () { return index_js_5.createStructuredChatAgent; } });
45
46
  var outputParser_js_4 = require("./structured_chat/outputParser.cjs");
46
47
  Object.defineProperty(exports, "StructuredChatOutputParser", { enumerable: true, get: function () { return outputParser_js_4.StructuredChatOutputParser; } });
47
48
  Object.defineProperty(exports, "StructuredChatOutputParserWithRetries", { enumerable: true, get: function () { return outputParser_js_4.StructuredChatOutputParserWithRetries; } });
48
- var index_js_6 = require("./openai/index.cjs");
49
+ var index_js_6 = require("./openai_functions/index.cjs");
49
50
  Object.defineProperty(exports, "OpenAIAgent", { enumerable: true, get: function () { return index_js_6.OpenAIAgent; } });
50
- var index_js_7 = require("./xml/index.cjs");
51
- Object.defineProperty(exports, "XMLAgent", { enumerable: true, get: function () { return index_js_7.XMLAgent; } });
51
+ Object.defineProperty(exports, "createOpenAIFunctionsAgent", { enumerable: true, get: function () { return index_js_6.createOpenAIFunctionsAgent; } });
52
+ var index_js_7 = require("./openai_tools/index.cjs");
53
+ Object.defineProperty(exports, "createOpenAIToolsAgent", { enumerable: true, get: function () { return index_js_7.createOpenAIToolsAgent; } });
54
+ var index_js_8 = require("./xml/index.cjs");
55
+ Object.defineProperty(exports, "XMLAgent", { enumerable: true, get: function () { return index_js_8.XMLAgent; } });
56
+ Object.defineProperty(exports, "createXmlAgent", { enumerable: true, get: function () { return index_js_8.createXmlAgent; } });
57
+ var index_js_9 = require("./react/index.cjs");
58
+ Object.defineProperty(exports, "createReactAgent", { enumerable: true, get: function () { return index_js_9.createReactAgent; } });
@@ -10,7 +10,10 @@ export { initializeAgentExecutor, initializeAgentExecutorWithOptions, type Initi
10
10
  export { ZeroShotAgent, type ZeroShotAgentInput, type ZeroShotCreatePromptArgs, } from "./mrkl/index.js";
11
11
  export { ZeroShotAgentOutputParser } from "./mrkl/outputParser.js";
12
12
  export { AgentActionOutputParser, type AgentInput, type SerializedAgent, type SerializedAgentT, type SerializedZeroShotAgent, type StoppingMethod, } from "./types.js";
13
- export { StructuredChatAgent, type StructuredChatAgentInput, type StructuredChatCreatePromptArgs, } from "./structured_chat/index.js";
13
+ export { StructuredChatAgent, type StructuredChatAgentInput, type StructuredChatCreatePromptArgs, type CreateStructuredChatAgentParams, createStructuredChatAgent, } from "./structured_chat/index.js";
14
14
  export { StructuredChatOutputParser, type StructuredChatOutputParserArgs, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
15
- export { OpenAIAgent, type OpenAIAgentInput, type OpenAIAgentCreatePromptArgs, } from "./openai/index.js";
16
- export { XMLAgent, type XMLAgentInput } from "./xml/index.js";
15
+ export { OpenAIAgent, type OpenAIAgentInput, type OpenAIAgentCreatePromptArgs, type CreateOpenAIFunctionsAgentParams, createOpenAIFunctionsAgent, } from "./openai_functions/index.js";
16
+ export { type CreateOpenAIToolsAgentParams, createOpenAIToolsAgent, } from "./openai_tools/index.js";
17
+ export { XMLAgent, type XMLAgentInput, type CreateXmlAgentParams, createXmlAgent, } from "./xml/index.js";
18
+ export { type CreateReactAgentParams, createReactAgent, } from "./react/index.js";
19
+ export type { AgentAction, AgentFinish, AgentStep } from "../schema/index.js";
@@ -10,7 +10,9 @@ export { initializeAgentExecutor, initializeAgentExecutorWithOptions, } from "./
10
10
  export { ZeroShotAgent, } from "./mrkl/index.js";
11
11
  export { ZeroShotAgentOutputParser } from "./mrkl/outputParser.js";
12
12
  export { AgentActionOutputParser, } from "./types.js";
13
- export { StructuredChatAgent, } from "./structured_chat/index.js";
13
+ export { StructuredChatAgent, createStructuredChatAgent, } from "./structured_chat/index.js";
14
14
  export { StructuredChatOutputParser, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
15
- export { OpenAIAgent, } from "./openai/index.js";
16
- export { XMLAgent } from "./xml/index.js";
15
+ export { OpenAIAgent, createOpenAIFunctionsAgent, } from "./openai_functions/index.js";
16
+ export { createOpenAIToolsAgent, } from "./openai_tools/index.js";
17
+ export { XMLAgent, createXmlAgent, } from "./xml/index.js";
18
+ export { createReactAgent, } from "./react/index.js";
@@ -7,7 +7,7 @@ const index_js_2 = require("./chat_convo/index.cjs");
7
7
  const index_js_3 = require("./structured_chat/index.cjs");
8
8
  const executor_js_1 = require("./executor.cjs");
9
9
  const index_js_4 = require("./mrkl/index.cjs");
10
- const index_js_5 = require("./openai/index.cjs");
10
+ const index_js_5 = require("./openai_functions/index.cjs");
11
11
  const index_js_6 = require("./xml/index.cjs");
12
12
  /**
13
13
  * @deprecated use initializeAgentExecutorWithOptions instead
@@ -6,7 +6,7 @@ import { ChatConversationalAgent } from "./chat_convo/index.js";
6
6
  import { StructuredChatAgent } from "./structured_chat/index.js";
7
7
  import { AgentExecutor, AgentExecutorInput } from "./executor.js";
8
8
  import { ZeroShotAgent } from "./mrkl/index.js";
9
- import { OpenAIAgent } from "./openai/index.js";
9
+ import { OpenAIAgent } from "./openai_functions/index.js";
10
10
  import { XMLAgent } from "./xml/index.js";
11
11
  /**
12
12
  * Represents the type of an agent in LangChain. It can be
@@ -4,7 +4,7 @@ import { ChatConversationalAgent } from "./chat_convo/index.js";
4
4
  import { StructuredChatAgent } from "./structured_chat/index.js";
5
5
  import { AgentExecutor } from "./executor.js";
6
6
  import { ZeroShotAgent } from "./mrkl/index.js";
7
- import { OpenAIAgent } from "./openai/index.js";
7
+ import { OpenAIAgent } from "./openai_functions/index.js";
8
8
  import { XMLAgent } from "./xml/index.js";
9
9
  /**
10
10
  * @deprecated use initializeAgentExecutorWithOptions instead
@@ -1,198 +1,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenAIToolsAgentOutputParser = exports.OpenAIFunctionsAgentOutputParser = void 0;
4
- const index_js_1 = require("../../schema/index.cjs");
5
- const types_js_1 = require("../types.cjs");
6
- const output_parser_js_1 = require("../../schema/output_parser.cjs");
7
- /**
8
- * @example
9
- * ```typescript
10
- *
11
- * const prompt = ChatPromptTemplate.fromMessages([
12
- * ["ai", "You are a helpful assistant"],
13
- * ["human", "{input}"],
14
- * new MessagesPlaceholder("agent_scratchpad"),
15
- * ]);
16
- *
17
- * const modelWithFunctions = new ChatOpenAI({
18
- * modelName: "gpt-4",
19
- * temperature: 0,
20
- * }).bind({
21
- * functions: tools.map((tool) => formatToOpenAIFunction(tool)),
22
- * });
23
- *
24
- * const runnableAgent = RunnableSequence.from([
25
- * {
26
- * input: (i) => i.input,
27
- * agent_scratchpad: (i) => formatAgentSteps(i.steps),
28
- * },
29
- * prompt,
30
- * modelWithFunctions,
31
- * new OpenAIFunctionsAgentOutputParser(),
32
- * ]);
33
- *
34
- * const result = await runnableAgent.invoke({
35
- * input: "What is the weather in New York?",
36
- * steps: agentSteps,
37
- * });
38
- *
39
- * ```
40
- */
41
- class OpenAIFunctionsAgentOutputParser extends types_js_1.AgentActionOutputParser {
42
- constructor() {
43
- super(...arguments);
44
- Object.defineProperty(this, "lc_namespace", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: ["langchain", "agents", "openai"]
49
- });
50
- }
51
- static lc_name() {
52
- return "OpenAIFunctionsAgentOutputParser";
53
- }
54
- async parse(text) {
55
- throw new Error(`OpenAIFunctionsAgentOutputParser can only parse messages.\nPassed input: ${text}`);
56
- }
57
- async parseResult(generations) {
58
- if ("message" in generations[0] && (0, index_js_1.isBaseMessage)(generations[0].message)) {
59
- return this.parseAIMessage(generations[0].message);
60
- }
61
- throw new Error("parseResult on OpenAIFunctionsAgentOutputParser only works on ChatGeneration output");
62
- }
63
- /**
64
- * Parses the output message into a FunctionsAgentAction or AgentFinish
65
- * object.
66
- * @param message The BaseMessage to parse.
67
- * @returns A FunctionsAgentAction or AgentFinish object.
68
- */
69
- parseAIMessage(message) {
70
- if (message.content && typeof message.content !== "string") {
71
- throw new Error("This agent cannot parse non-string model responses.");
72
- }
73
- if (message.additional_kwargs.function_call) {
74
- // eslint-disable-next-line prefer-destructuring
75
- const function_call = message.additional_kwargs.function_call;
76
- try {
77
- const toolInput = function_call.arguments
78
- ? JSON.parse(function_call.arguments)
79
- : {};
80
- return {
81
- tool: function_call.name,
82
- toolInput,
83
- log: `Invoking "${function_call.name}" with ${function_call.arguments ?? "{}"}\n${message.content}`,
84
- messageLog: [message],
85
- };
86
- }
87
- catch (error) {
88
- throw new output_parser_js_1.OutputParserException(`Failed to parse function arguments from chat model response. Text: "${function_call.arguments}". ${error}`);
89
- }
90
- }
91
- else {
92
- return {
93
- returnValues: { output: message.content },
94
- log: message.content,
95
- };
96
- }
97
- }
98
- getFormatInstructions() {
99
- throw new Error("getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.");
100
- }
101
- }
102
- exports.OpenAIFunctionsAgentOutputParser = OpenAIFunctionsAgentOutputParser;
103
- /**
104
- * @example
105
- * ```typescript
106
- *
107
- * const prompt = ChatPromptTemplate.fromMessages([
108
- * ["ai", "You are a helpful assistant"],
109
- * ["human", "{input}"],
110
- * new MessagesPlaceholder("agent_scratchpad"),
111
- * ]);
112
- *
113
- * const runnableAgent = RunnableSequence.from([
114
- * {
115
- * input: (i: { input: string; steps: ToolsAgentStep[] }) => i.input,
116
- * agent_scratchpad: (i: { input: string; steps: ToolsAgentStep[] }) =>
117
- * formatToOpenAIToolMessages(i.steps),
118
- * },
119
- * prompt,
120
- * new ChatOpenAI({
121
- * modelName: "gpt-3.5-turbo-1106",
122
- * temperature: 0,
123
- * }).bind({ tools: tools.map(formatToOpenAITool) }),
124
- * new OpenAIToolsAgentOutputParser(),
125
- * ]).withConfig({ runName: "OpenAIToolsAgent" });
126
- *
127
- * const result = await runnableAgent.invoke({
128
- * input:
129
- * "What is the sum of the current temperature in San Francisco, New York, and Tokyo?",
130
- * });
131
- *
132
- * ```
133
- */
134
- class OpenAIToolsAgentOutputParser extends types_js_1.AgentMultiActionOutputParser {
135
- constructor() {
136
- super(...arguments);
137
- Object.defineProperty(this, "lc_namespace", {
138
- enumerable: true,
139
- configurable: true,
140
- writable: true,
141
- value: ["langchain", "agents", "openai"]
142
- });
143
- }
144
- static lc_name() {
145
- return "OpenAIToolsAgentOutputParser";
146
- }
147
- async parse(text) {
148
- throw new Error(`OpenAIFunctionsAgentOutputParser can only parse messages.\nPassed input: ${text}`);
149
- }
150
- async parseResult(generations) {
151
- if ("message" in generations[0] && (0, index_js_1.isBaseMessage)(generations[0].message)) {
152
- return this.parseAIMessage(generations[0].message);
153
- }
154
- throw new Error("parseResult on OpenAIFunctionsAgentOutputParser only works on ChatGeneration output");
155
- }
156
- /**
157
- * Parses the output message into a ToolsAgentAction[] or AgentFinish
158
- * object.
159
- * @param message The BaseMessage to parse.
160
- * @returns A ToolsAgentAction[] or AgentFinish object.
161
- */
162
- parseAIMessage(message) {
163
- if (message.content && typeof message.content !== "string") {
164
- throw new Error("This agent cannot parse non-string model responses.");
165
- }
166
- if (message.additional_kwargs.tool_calls) {
167
- const toolCalls = message.additional_kwargs.tool_calls;
168
- try {
169
- return toolCalls.map((toolCall, i) => {
170
- const toolInput = toolCall.function.arguments
171
- ? JSON.parse(toolCall.function.arguments)
172
- : {};
173
- const messageLog = i === 0 ? [message] : [];
174
- return {
175
- tool: toolCall.function.name,
176
- toolInput,
177
- toolCallId: toolCall.id,
178
- log: `Invoking "${toolCall.function.name}" with ${toolCall.function.arguments ?? "{}"}\n${message.content}`,
179
- messageLog,
180
- };
181
- });
182
- }
183
- catch (error) {
184
- throw new output_parser_js_1.OutputParserException(`Failed to parse tool arguments from chat model response. Text: "${JSON.stringify(toolCalls)}". ${error}`);
185
- }
186
- }
187
- else {
188
- return {
189
- returnValues: { output: message.content },
190
- log: message.content,
191
- };
192
- }
193
- }
194
- getFormatInstructions() {
195
- throw new Error("getFormatInstructions not implemented inside OpenAIToolsAgentOutputParser.");
196
- }
197
- }
198
- exports.OpenAIToolsAgentOutputParser = OpenAIToolsAgentOutputParser;
17
+ // console.warn([
18
+ // `[WARNING]: The root "langchain/agents/openai/output_parser" entrypoint is deprecated.`,
19
+ // `Please use either "langchain/agents/openai/output_parser" specific entrypoint instead.`
20
+ // ].join("\n"));
21
+ __exportStar(require("../openai_functions/output_parser.cjs"), exports);
22
+ __exportStar(require("../openai_tools/output_parser.cjs"), exports);