langchain 0.0.170 → 0.0.172

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 (102) hide show
  1. package/agents/format_scratchpad/log.cjs +1 -0
  2. package/agents/format_scratchpad/log.d.ts +1 -0
  3. package/agents/format_scratchpad/log.js +1 -0
  4. package/agents/format_scratchpad/log_to_message.cjs +1 -0
  5. package/agents/format_scratchpad/log_to_message.d.ts +1 -0
  6. package/agents/format_scratchpad/log_to_message.js +1 -0
  7. package/agents/format_scratchpad/xml.cjs +1 -0
  8. package/agents/format_scratchpad/xml.d.ts +1 -0
  9. package/agents/format_scratchpad/xml.js +1 -0
  10. package/agents/format_scratchpad.cjs +1 -1
  11. package/agents/format_scratchpad.d.ts +1 -1
  12. package/agents/format_scratchpad.js +1 -1
  13. package/agents/react/output_parser.cjs +1 -0
  14. package/agents/react/output_parser.d.ts +1 -0
  15. package/agents/react/output_parser.js +1 -0
  16. package/chat_models/llama_cpp.cjs +1 -0
  17. package/chat_models/llama_cpp.d.ts +1 -0
  18. package/chat_models/llama_cpp.js +1 -0
  19. package/dist/agents/format_scratchpad/log.cjs +16 -0
  20. package/dist/agents/format_scratchpad/log.d.ts +9 -0
  21. package/dist/agents/format_scratchpad/log.js +12 -0
  22. package/dist/agents/format_scratchpad/log_to_message.cjs +22 -0
  23. package/dist/agents/format_scratchpad/log_to_message.d.ts +2 -0
  24. package/dist/agents/format_scratchpad/log_to_message.js +18 -0
  25. package/dist/agents/{format_scratchpad.cjs → format_scratchpad/openai_functions.cjs} +3 -3
  26. package/dist/agents/{format_scratchpad.d.ts → format_scratchpad/openai_functions.d.ts} +1 -1
  27. package/dist/agents/{format_scratchpad.js → format_scratchpad/openai_functions.js} +3 -3
  28. package/dist/agents/format_scratchpad/xml.cjs +12 -0
  29. package/dist/agents/format_scratchpad/xml.d.ts +2 -0
  30. package/dist/agents/format_scratchpad/xml.js +8 -0
  31. package/dist/agents/react/output_parser.cjs +96 -0
  32. package/dist/agents/react/output_parser.d.ts +47 -0
  33. package/dist/agents/react/output_parser.js +92 -0
  34. package/dist/agents/react/prompt.cjs +13 -0
  35. package/dist/agents/react/prompt.d.ts +1 -0
  36. package/dist/agents/react/prompt.js +10 -0
  37. package/dist/agents/toolkits/openapi/openapi.cjs +1 -1
  38. package/dist/agents/toolkits/openapi/openapi.d.ts +1 -1
  39. package/dist/agents/toolkits/openapi/openapi.js +1 -1
  40. package/dist/chains/sql_db/sql_db_chain.cjs +2 -0
  41. package/dist/chains/sql_db/sql_db_chain.d.ts +2 -0
  42. package/dist/chains/sql_db/sql_db_chain.js +2 -0
  43. package/dist/chat_models/llama_cpp.cjs +243 -0
  44. package/dist/chat_models/llama_cpp.d.ts +94 -0
  45. package/dist/chat_models/llama_cpp.js +239 -0
  46. package/dist/document_loaders/web/pdf.cjs +23 -5
  47. package/dist/document_loaders/web/pdf.d.ts +9 -1
  48. package/dist/document_loaders/web/pdf.js +20 -2
  49. package/dist/embeddings/openai.cjs +11 -0
  50. package/dist/embeddings/openai.d.ts +2 -0
  51. package/dist/embeddings/openai.js +11 -0
  52. package/dist/graphs/neo4j_graph.cjs +14 -0
  53. package/dist/graphs/neo4j_graph.d.ts +14 -0
  54. package/dist/graphs/neo4j_graph.js +14 -0
  55. package/dist/llms/googlepalm.cjs +3 -0
  56. package/dist/llms/googlepalm.js +3 -0
  57. package/dist/load/import_constants.cjs +2 -0
  58. package/dist/load/import_constants.js +2 -0
  59. package/dist/load/import_map.cjs +8 -3
  60. package/dist/load/import_map.d.ts +6 -1
  61. package/dist/load/import_map.js +6 -1
  62. package/dist/retrievers/parent_document.cjs +22 -2
  63. package/dist/retrievers/parent_document.d.ts +8 -1
  64. package/dist/retrievers/parent_document.js +22 -2
  65. package/dist/schema/runnable/passthrough.cjs +3 -1
  66. package/dist/schema/runnable/passthrough.js +3 -1
  67. package/dist/sql_db.cjs +2 -0
  68. package/dist/sql_db.d.ts +2 -0
  69. package/dist/sql_db.js +2 -0
  70. package/dist/storage/file_system.cjs +147 -0
  71. package/dist/storage/file_system.d.ts +60 -0
  72. package/dist/storage/file_system.js +140 -0
  73. package/dist/tools/render.cjs +18 -0
  74. package/dist/tools/render.d.ts +13 -0
  75. package/dist/tools/render.js +14 -0
  76. package/dist/util/stream.cjs +3 -0
  77. package/dist/util/stream.js +3 -0
  78. package/dist/vectorstores/analyticdb.cjs +7 -3
  79. package/dist/vectorstores/analyticdb.d.ts +1 -1
  80. package/dist/vectorstores/analyticdb.js +7 -3
  81. package/dist/vectorstores/cassandra.cjs +25 -4
  82. package/dist/vectorstores/cassandra.d.ts +11 -1
  83. package/dist/vectorstores/cassandra.js +25 -4
  84. package/dist/vectorstores/momento_vector_index.cjs +3 -15
  85. package/dist/vectorstores/momento_vector_index.d.ts +0 -8
  86. package/dist/vectorstores/momento_vector_index.js +3 -15
  87. package/dist/vectorstores/neo4j_vector.cjs +14 -0
  88. package/dist/vectorstores/neo4j_vector.d.ts +14 -0
  89. package/dist/vectorstores/neo4j_vector.js +14 -0
  90. package/dist/vectorstores/qdrant.cjs +19 -11
  91. package/dist/vectorstores/qdrant.d.ts +1 -1
  92. package/dist/vectorstores/qdrant.js +19 -11
  93. package/dist/vectorstores/redis.cjs +4 -1
  94. package/dist/vectorstores/redis.d.ts +1 -1
  95. package/dist/vectorstores/redis.js +4 -1
  96. package/package.json +63 -7
  97. package/storage/file_system.cjs +1 -0
  98. package/storage/file_system.d.ts +1 -0
  99. package/storage/file_system.js +1 -0
  100. package/tools/render.cjs +1 -0
  101. package/tools/render.d.ts +1 -0
  102. package/tools/render.js +1 -0
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/agents/format_scratchpad/log.cjs');
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/format_scratchpad/log.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/format_scratchpad/log.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/agents/format_scratchpad/log_to_message.cjs');
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/format_scratchpad/log_to_message.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/format_scratchpad/log_to_message.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/agents/format_scratchpad/xml.cjs');
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/format_scratchpad/xml.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/format_scratchpad/xml.js'
@@ -1 +1 @@
1
- module.exports = require('../dist/agents/format_scratchpad.cjs');
1
+ module.exports = require('../dist/agents/format_scratchpad/openai_functions.cjs');
@@ -1 +1 @@
1
- export * from '../dist/agents/format_scratchpad.js'
1
+ export * from '../dist/agents/format_scratchpad/openai_functions.js'
@@ -1 +1 @@
1
- export * from '../dist/agents/format_scratchpad.js'
1
+ export * from '../dist/agents/format_scratchpad/openai_functions.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/agents/react/output_parser.cjs');
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/react/output_parser.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/agents/react/output_parser.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/chat_models/llama_cpp.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/chat_models/llama_cpp.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/chat_models/llama_cpp.js'
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatLogToString = void 0;
4
+ /**
5
+ * Construct the scratchpad that lets the agent continue its thought process.
6
+ * @param intermediateSteps
7
+ * @param observationPrefix
8
+ * @param llmPrefix
9
+ * @returns a string with the formatted observations and agent logs
10
+ */
11
+ function formatLogToString(intermediateSteps, observationPrefix = "Observation: ", llmPrefix = "Thought: ") {
12
+ const formattedSteps = intermediateSteps.reduce((thoughts, { action, observation }) => thoughts +
13
+ [action.log, `\n${observationPrefix}${observation}`, llmPrefix].join("\n"), "");
14
+ return formattedSteps;
15
+ }
16
+ exports.formatLogToString = formatLogToString;
@@ -0,0 +1,9 @@
1
+ import { AgentStep } from "../../schema/index.js";
2
+ /**
3
+ * Construct the scratchpad that lets the agent continue its thought process.
4
+ * @param intermediateSteps
5
+ * @param observationPrefix
6
+ * @param llmPrefix
7
+ * @returns a string with the formatted observations and agent logs
8
+ */
9
+ export declare function formatLogToString(intermediateSteps: AgentStep[], observationPrefix?: string, llmPrefix?: string): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Construct the scratchpad that lets the agent continue its thought process.
3
+ * @param intermediateSteps
4
+ * @param observationPrefix
5
+ * @param llmPrefix
6
+ * @returns a string with the formatted observations and agent logs
7
+ */
8
+ export function formatLogToString(intermediateSteps, observationPrefix = "Observation: ", llmPrefix = "Thought: ") {
9
+ const formattedSteps = intermediateSteps.reduce((thoughts, { action, observation }) => thoughts +
10
+ [action.log, `\n${observationPrefix}${observation}`, llmPrefix].join("\n"), "");
11
+ return formattedSteps;
12
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatLogToMessage = void 0;
4
+ const template_js_1 = require("../../prompts/template.cjs");
5
+ const index_js_1 = require("../../schema/index.cjs");
6
+ function formatLogToMessage(intermediateSteps, templateToolResponse = "{observation}") {
7
+ // Get all input variables, if there is more than one, throw an error.
8
+ const matches = [...templateToolResponse.matchAll(/{([^}]*)}/g)];
9
+ const stringsInsideBrackets = matches.map((match) => match[1]);
10
+ if (stringsInsideBrackets.length > 1) {
11
+ throw new Error(`templateToolResponse must contain one input variable: ${templateToolResponse}`);
12
+ }
13
+ const thoughts = [];
14
+ for (const step of intermediateSteps) {
15
+ thoughts.push(new index_js_1.AIMessage(step.action.log));
16
+ thoughts.push(new index_js_1.HumanMessage((0, template_js_1.renderTemplate)(templateToolResponse, "f-string", {
17
+ [stringsInsideBrackets[0]]: step.observation,
18
+ })));
19
+ }
20
+ return thoughts;
21
+ }
22
+ exports.formatLogToMessage = formatLogToMessage;
@@ -0,0 +1,2 @@
1
+ import { AgentStep, BaseMessage } from "../../schema/index.js";
2
+ export declare function formatLogToMessage(intermediateSteps: AgentStep[], templateToolResponse?: string): BaseMessage[];
@@ -0,0 +1,18 @@
1
+ import { renderTemplate } from "../../prompts/template.js";
2
+ import { AIMessage, HumanMessage, } from "../../schema/index.js";
3
+ export function formatLogToMessage(intermediateSteps, templateToolResponse = "{observation}") {
4
+ // Get all input variables, if there is more than one, throw an error.
5
+ const matches = [...templateToolResponse.matchAll(/{([^}]*)}/g)];
6
+ const stringsInsideBrackets = matches.map((match) => match[1]);
7
+ if (stringsInsideBrackets.length > 1) {
8
+ throw new Error(`templateToolResponse must contain one input variable: ${templateToolResponse}`);
9
+ }
10
+ const thoughts = [];
11
+ for (const step of intermediateSteps) {
12
+ thoughts.push(new AIMessage(step.action.log));
13
+ thoughts.push(new HumanMessage(renderTemplate(templateToolResponse, "f-string", {
14
+ [stringsInsideBrackets[0]]: step.observation,
15
+ })));
16
+ }
17
+ return thoughts;
18
+ }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatForOpenAIFunctions = void 0;
4
- const template_js_1 = require("../prompts/template.cjs");
5
- const index_js_1 = require("../schema/index.cjs");
6
- const prompt_js_1 = require("./chat_convo/prompt.cjs");
4
+ const template_js_1 = require("../../prompts/template.cjs");
5
+ const index_js_1 = require("../../schema/index.cjs");
6
+ const prompt_js_1 = require("../chat_convo/prompt.cjs");
7
7
  /**
8
8
  * Format a list of AgentSteps into a list of BaseMessage instances for
9
9
  * agents that use OpenAI's API. Helpful for passing in previous agent
@@ -1,4 +1,4 @@
1
- import { AgentStep, BaseMessage } from "../schema/index.js";
1
+ import { AgentStep, BaseMessage } from "../../schema/index.js";
2
2
  /**
3
3
  * Format a list of AgentSteps into a list of BaseMessage instances for
4
4
  * agents that use OpenAI's API. Helpful for passing in previous agent
@@ -1,6 +1,6 @@
1
- import { renderTemplate } from "../prompts/template.js";
2
- import { AIMessage, HumanMessage, } from "../schema/index.js";
3
- import { TEMPLATE_TOOL_RESPONSE } from "./chat_convo/prompt.js";
1
+ import { renderTemplate } from "../../prompts/template.js";
2
+ import { AIMessage, HumanMessage, } from "../../schema/index.js";
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
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatXml = void 0;
4
+ function formatXml(intermediateSteps) {
5
+ let log = "";
6
+ for (const step of intermediateSteps) {
7
+ const { action, observation } = step;
8
+ log += `<tool>${action.tool}</tool><tool_input>${action.toolInput}\n</tool_input><observation>${observation}</observation>`;
9
+ }
10
+ return log;
11
+ }
12
+ exports.formatXml = formatXml;
@@ -0,0 +1,2 @@
1
+ import { AgentStep } from "../../schema/index.js";
2
+ export declare function formatXml(intermediateSteps: AgentStep[]): string;
@@ -0,0 +1,8 @@
1
+ export function formatXml(intermediateSteps) {
2
+ let log = "";
3
+ for (const step of intermediateSteps) {
4
+ const { action, observation } = step;
5
+ log += `<tool>${action.tool}</tool><tool_input>${action.toolInput}\n</tool_input><observation>${observation}</observation>`;
6
+ }
7
+ return log;
8
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReActSingleInputOutputParser = void 0;
4
+ const template_js_1 = require("../../prompts/template.cjs");
5
+ const types_js_1 = require("../types.cjs");
6
+ const prompt_js_1 = require("./prompt.cjs");
7
+ const FINAL_ANSWER_ACTION = "Final Answer:";
8
+ const FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE = "Parsing LLM output produced both a final answer and a parse-able action:";
9
+ /**
10
+ * Parses ReAct-style LLM calls that have a single tool input.
11
+ *
12
+ * Expects output to be in one of two formats.
13
+ *
14
+ * If the output signals that an action should be taken,
15
+ * should be in the below format. This will result in an AgentAction
16
+ * being returned.
17
+ *
18
+ * ```
19
+ * Thought: agent thought here
20
+ * Action: search
21
+ * Action Input: what is the temperature in SF?
22
+ * ```
23
+ *
24
+ * If the output signals that a final answer should be given,
25
+ * should be in the below format. This will result in an AgentFinish
26
+ * being returned.
27
+ *
28
+ * ```
29
+ * Thought: agent thought here
30
+ * Final Answer: The temperature is 100 degrees
31
+ * ```
32
+ */
33
+ class ReActSingleInputOutputParser extends types_js_1.AgentActionOutputParser {
34
+ constructor(fields) {
35
+ super(...arguments);
36
+ Object.defineProperty(this, "lc_namespace", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: ["langchain", "agents", "react"]
41
+ });
42
+ Object.defineProperty(this, "toolNames", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ this.toolNames = fields.toolNames;
49
+ }
50
+ /**
51
+ * Parses the given text into an AgentAction or AgentFinish object. If an
52
+ * output fixing parser is defined, uses it to parse the text.
53
+ * @param text Text to parse.
54
+ * @returns Promise that resolves to an AgentAction or AgentFinish object.
55
+ */
56
+ async parse(text) {
57
+ const includesAnswer = text.includes(FINAL_ANSWER_ACTION);
58
+ const regex = /Action\s*\d*\s*:[\s]*(.*?)[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)/;
59
+ const actionMatch = text.match(regex);
60
+ if (actionMatch) {
61
+ if (includesAnswer) {
62
+ throw new Error(`${FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE}: ${text}`);
63
+ }
64
+ const action = actionMatch[1];
65
+ const actionInput = actionMatch[2];
66
+ const toolInput = actionInput.trim().replace(/"/g, "");
67
+ return {
68
+ tool: action,
69
+ toolInput,
70
+ log: text,
71
+ };
72
+ }
73
+ if (includesAnswer) {
74
+ const finalAnswerText = text.split(FINAL_ANSWER_ACTION)[1].trim();
75
+ return {
76
+ returnValues: {
77
+ output: finalAnswerText,
78
+ },
79
+ log: text,
80
+ };
81
+ }
82
+ throw new Error(`Could not parse LLM output: ${text}`);
83
+ }
84
+ /**
85
+ * Returns the format instructions as a string. If the 'raw' option is
86
+ * true, returns the raw FORMAT_INSTRUCTIONS.
87
+ * @param options Options for getting the format instructions.
88
+ * @returns Format instructions as a string.
89
+ */
90
+ getFormatInstructions() {
91
+ return (0, template_js_1.renderTemplate)(prompt_js_1.FORMAT_INSTRUCTIONS, "f-string", {
92
+ tool_names: this.toolNames.join(", "),
93
+ });
94
+ }
95
+ }
96
+ exports.ReActSingleInputOutputParser = ReActSingleInputOutputParser;
@@ -0,0 +1,47 @@
1
+ import { AgentActionOutputParser } from "../types.js";
2
+ import { AgentAction, AgentFinish } from "../../schema/index.js";
3
+ /**
4
+ * Parses ReAct-style LLM calls that have a single tool input.
5
+ *
6
+ * Expects output to be in one of two formats.
7
+ *
8
+ * If the output signals that an action should be taken,
9
+ * should be in the below format. This will result in an AgentAction
10
+ * being returned.
11
+ *
12
+ * ```
13
+ * Thought: agent thought here
14
+ * Action: search
15
+ * Action Input: what is the temperature in SF?
16
+ * ```
17
+ *
18
+ * If the output signals that a final answer should be given,
19
+ * should be in the below format. This will result in an AgentFinish
20
+ * being returned.
21
+ *
22
+ * ```
23
+ * Thought: agent thought here
24
+ * Final Answer: The temperature is 100 degrees
25
+ * ```
26
+ */
27
+ export declare class ReActSingleInputOutputParser extends AgentActionOutputParser {
28
+ lc_namespace: string[];
29
+ private toolNames;
30
+ constructor(fields: {
31
+ toolNames: string[];
32
+ });
33
+ /**
34
+ * Parses the given text into an AgentAction or AgentFinish object. If an
35
+ * output fixing parser is defined, uses it to parse the text.
36
+ * @param text Text to parse.
37
+ * @returns Promise that resolves to an AgentAction or AgentFinish object.
38
+ */
39
+ parse(text: string): Promise<AgentAction | AgentFinish>;
40
+ /**
41
+ * Returns the format instructions as a string. If the 'raw' option is
42
+ * true, returns the raw FORMAT_INSTRUCTIONS.
43
+ * @param options Options for getting the format instructions.
44
+ * @returns Format instructions as a string.
45
+ */
46
+ getFormatInstructions(): string;
47
+ }
@@ -0,0 +1,92 @@
1
+ import { renderTemplate } from "../../prompts/template.js";
2
+ import { AgentActionOutputParser } from "../types.js";
3
+ import { FORMAT_INSTRUCTIONS } from "./prompt.js";
4
+ const FINAL_ANSWER_ACTION = "Final Answer:";
5
+ const FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE = "Parsing LLM output produced both a final answer and a parse-able action:";
6
+ /**
7
+ * Parses ReAct-style LLM calls that have a single tool input.
8
+ *
9
+ * Expects output to be in one of two formats.
10
+ *
11
+ * If the output signals that an action should be taken,
12
+ * should be in the below format. This will result in an AgentAction
13
+ * being returned.
14
+ *
15
+ * ```
16
+ * Thought: agent thought here
17
+ * Action: search
18
+ * Action Input: what is the temperature in SF?
19
+ * ```
20
+ *
21
+ * If the output signals that a final answer should be given,
22
+ * should be in the below format. This will result in an AgentFinish
23
+ * being returned.
24
+ *
25
+ * ```
26
+ * Thought: agent thought here
27
+ * Final Answer: The temperature is 100 degrees
28
+ * ```
29
+ */
30
+ export class ReActSingleInputOutputParser extends AgentActionOutputParser {
31
+ constructor(fields) {
32
+ super(...arguments);
33
+ Object.defineProperty(this, "lc_namespace", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: ["langchain", "agents", "react"]
38
+ });
39
+ Object.defineProperty(this, "toolNames", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ this.toolNames = fields.toolNames;
46
+ }
47
+ /**
48
+ * Parses the given text into an AgentAction or AgentFinish object. If an
49
+ * output fixing parser is defined, uses it to parse the text.
50
+ * @param text Text to parse.
51
+ * @returns Promise that resolves to an AgentAction or AgentFinish object.
52
+ */
53
+ async parse(text) {
54
+ const includesAnswer = text.includes(FINAL_ANSWER_ACTION);
55
+ const regex = /Action\s*\d*\s*:[\s]*(.*?)[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)/;
56
+ const actionMatch = text.match(regex);
57
+ if (actionMatch) {
58
+ if (includesAnswer) {
59
+ throw new Error(`${FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE}: ${text}`);
60
+ }
61
+ const action = actionMatch[1];
62
+ const actionInput = actionMatch[2];
63
+ const toolInput = actionInput.trim().replace(/"/g, "");
64
+ return {
65
+ tool: action,
66
+ toolInput,
67
+ log: text,
68
+ };
69
+ }
70
+ if (includesAnswer) {
71
+ const finalAnswerText = text.split(FINAL_ANSWER_ACTION)[1].trim();
72
+ return {
73
+ returnValues: {
74
+ output: finalAnswerText,
75
+ },
76
+ log: text,
77
+ };
78
+ }
79
+ throw new Error(`Could not parse LLM output: ${text}`);
80
+ }
81
+ /**
82
+ * Returns the format instructions as a string. If the 'raw' option is
83
+ * true, returns the raw FORMAT_INSTRUCTIONS.
84
+ * @param options Options for getting the format instructions.
85
+ * @returns Format instructions as a string.
86
+ */
87
+ getFormatInstructions() {
88
+ return renderTemplate(FORMAT_INSTRUCTIONS, "f-string", {
89
+ tool_names: this.toolNames.join(", "),
90
+ });
91
+ }
92
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORMAT_INSTRUCTIONS = void 0;
4
+ exports.FORMAT_INSTRUCTIONS /* #__PURE__ */ = `Use the following format:
5
+
6
+ Question: the input question you must answer
7
+ Thought: you should always think about what to do
8
+ Action: the action to take, should be one of [{tool_names}]
9
+ Action Input: the input to the action
10
+ Observation: the result of the action
11
+ ... (this Thought/Action/Action Input/Observation can repeat N times)
12
+ Thought: I now know the final answer
13
+ Final Answer: the final answer to the original input question`;
@@ -0,0 +1 @@
1
+ export declare const FORMAT_INSTRUCTIONS = "Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question";
@@ -0,0 +1,10 @@
1
+ export const FORMAT_INSTRUCTIONS /* #__PURE__ */ = `Use the following format:
2
+
3
+ Question: the input question you must answer
4
+ Thought: you should always think about what to do
5
+ Action: the action to take, should be one of [{tool_names}]
6
+ Action Input: the input to the action
7
+ Observation: the result of the action
8
+ ... (this Thought/Action/Action Input/Observation can repeat N times)
9
+ Thought: I now know the final answer
10
+ Final Answer: the final answer to the original input question`;
@@ -67,7 +67,7 @@ exports.OpenApiToolkit = OpenApiToolkit;
67
67
  * limiting access to what endpoints it can hit, what actions can be taken, and
68
68
  * more.
69
69
  *
70
- * See https://js.langchain.com/docs/security for more information.
70
+ * @link See https://js.langchain.com/docs/security for more information.
71
71
  */
72
72
  function createOpenApiAgent(llm, openApiToolkit, args) {
73
73
  const { prefix = prompt_js_1.OPENAPI_PREFIX, suffix = prompt_js_1.OPENAPI_SUFFIX, inputVariables = ["input", "agent_scratchpad"], } = args ?? {};
@@ -39,7 +39,7 @@ export declare class OpenApiToolkit extends RequestsToolkit {
39
39
  * limiting access to what endpoints it can hit, what actions can be taken, and
40
40
  * more.
41
41
  *
42
- * See https://js.langchain.com/docs/security for more information.
42
+ * @link See https://js.langchain.com/docs/security for more information.
43
43
  */
44
44
  export declare function createOpenApiAgent(llm: BaseLanguageModel, openApiToolkit: OpenApiToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor<import("../../../schema/index.js").ChainValues & {
45
45
  agent_scratchpad?: string | import("../../../schema/index.js").BaseMessage[] | undefined;
@@ -62,7 +62,7 @@ export class OpenApiToolkit extends RequestsToolkit {
62
62
  * limiting access to what endpoints it can hit, what actions can be taken, and
63
63
  * more.
64
64
  *
65
- * See https://js.langchain.com/docs/security for more information.
65
+ * @link See https://js.langchain.com/docs/security for more information.
66
66
  */
67
67
  export function createOpenApiAgent(llm, openApiToolkit, args) {
68
68
  const { prefix = OPENAPI_PREFIX, suffix = OPENAPI_SUFFIX, inputVariables = ["input", "agent_scratchpad"], } = args ?? {};
@@ -19,6 +19,8 @@ const sql_utils_js_1 = require("../../util/sql_utils.cjs");
19
19
  * to read and scope to the tables that are needed.
20
20
  * Optionally, use the includesTables or ignoreTables class parameters
21
21
  * to limit which tables can/cannot be accessed.
22
+ *
23
+ * @link See https://js.langchain.com/docs/security for more information.
22
24
  */
23
25
  class SqlDatabaseChain extends base_js_1.BaseChain {
24
26
  static lc_name() {
@@ -31,6 +31,8 @@ export interface SqlDatabaseChainInput extends ChainInputs {
31
31
  * to read and scope to the tables that are needed.
32
32
  * Optionally, use the includesTables or ignoreTables class parameters
33
33
  * to limit which tables can/cannot be accessed.
34
+ *
35
+ * @link See https://js.langchain.com/docs/security for more information.
34
36
  */
35
37
  export declare class SqlDatabaseChain extends BaseChain {
36
38
  static lc_name(): string;
@@ -16,6 +16,8 @@ import { getPromptTemplateFromDataSource } from "../../util/sql_utils.js";
16
16
  * to read and scope to the tables that are needed.
17
17
  * Optionally, use the includesTables or ignoreTables class parameters
18
18
  * to limit which tables can/cannot be accessed.
19
+ *
20
+ * @link See https://js.langchain.com/docs/security for more information.
19
21
  */
20
22
  export class SqlDatabaseChain extends BaseChain {
21
23
  static lc_name() {