@langchain/classic 1.0.44 → 1.0.46
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.
- package/CHANGELOG.md +14 -0
- package/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/agents/agent.cjs.map +1 -1
- package/dist/agents/chat/index.cjs +2 -1
- package/dist/agents/chat/index.cjs.map +1 -1
- package/dist/agents/chat/index.js +2 -1
- package/dist/agents/chat/index.js.map +1 -1
- package/dist/agents/chat_convo/index.cjs +7 -5
- package/dist/agents/chat_convo/index.cjs.map +1 -1
- package/dist/agents/chat_convo/index.js +7 -5
- package/dist/agents/chat_convo/index.js.map +1 -1
- package/dist/agents/chat_convo/outputParser.cjs.map +1 -1
- package/dist/agents/executor.cjs +22 -19
- package/dist/agents/executor.cjs.map +1 -1
- package/dist/agents/executor.js +22 -19
- package/dist/agents/executor.js.map +1 -1
- package/dist/agents/format_scratchpad/log_to_message.cjs.map +1 -1
- package/dist/agents/format_scratchpad/openai_functions.cjs.map +1 -1
- package/dist/agents/mrkl/index.cjs +9 -6
- package/dist/agents/mrkl/index.cjs.map +1 -1
- package/dist/agents/mrkl/index.js +9 -6
- package/dist/agents/mrkl/index.js.map +1 -1
- package/dist/agents/mrkl/outputParser.d.cts +1 -1
- package/dist/agents/openai_functions/index.cjs +2 -1
- package/dist/agents/openai_functions/index.cjs.map +1 -1
- package/dist/agents/openai_functions/index.js +2 -1
- package/dist/agents/openai_functions/index.js.map +1 -1
- package/dist/agents/openai_functions/output_parser.cjs.map +1 -1
- package/dist/agents/openai_tools/index.cjs.map +1 -1
- package/dist/agents/openai_tools/output_parser.cjs.map +1 -1
- package/dist/agents/react/output_parser.cjs.map +1 -1
- package/dist/agents/structured_chat/index.cjs +6 -5
- package/dist/agents/structured_chat/index.cjs.map +1 -1
- package/dist/agents/structured_chat/index.js +6 -5
- package/dist/agents/structured_chat/index.js.map +1 -1
- package/dist/agents/structured_chat/outputParser.cjs.map +1 -1
- package/dist/agents/tool_calling/output_parser.cjs.map +1 -1
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.cjs.map +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs.map +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js +2 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js.map +1 -1
- package/dist/agents/toolkits/json/json.cjs +10 -8
- package/dist/agents/toolkits/json/json.cjs.map +1 -1
- package/dist/agents/toolkits/json/json.js +10 -8
- package/dist/agents/toolkits/json/json.js.map +1 -1
- package/dist/agents/toolkits/openapi/openapi.cjs +12 -9
- package/dist/agents/toolkits/openapi/openapi.cjs.map +1 -1
- package/dist/agents/toolkits/openapi/openapi.js +12 -9
- package/dist/agents/toolkits/openapi/openapi.js.map +1 -1
- package/dist/agents/toolkits/sql/sql.cjs +10 -8
- package/dist/agents/toolkits/sql/sql.cjs.map +1 -1
- package/dist/agents/toolkits/sql/sql.js +10 -8
- package/dist/agents/toolkits/sql/sql.js.map +1 -1
- package/dist/agents/toolkits/vectorstore/vectorstore.cjs +20 -16
- package/dist/agents/toolkits/vectorstore/vectorstore.cjs.map +1 -1
- package/dist/agents/toolkits/vectorstore/vectorstore.js +20 -16
- package/dist/agents/toolkits/vectorstore/vectorstore.js.map +1 -1
- package/dist/agents/xml/index.cjs +2 -1
- package/dist/agents/xml/index.cjs.map +1 -1
- package/dist/agents/xml/index.js +2 -1
- package/dist/agents/xml/index.js.map +1 -1
- package/dist/chains/base.cjs.map +1 -1
- package/dist/chains/chat_vector_db_chain.cjs +2 -1
- package/dist/chains/chat_vector_db_chain.cjs.map +1 -1
- package/dist/chains/chat_vector_db_chain.js +2 -1
- package/dist/chains/chat_vector_db_chain.js.map +1 -1
- package/dist/chains/conversational_retrieval_chain.cjs +2 -1
- package/dist/chains/conversational_retrieval_chain.cjs.map +1 -1
- package/dist/chains/conversational_retrieval_chain.js +2 -1
- package/dist/chains/conversational_retrieval_chain.js.map +1 -1
- package/dist/chains/openai_functions/base.cjs.map +1 -1
- package/dist/chains/openai_functions/extraction.cjs.map +1 -1
- package/dist/chains/openai_functions/openapi.cjs +9 -8
- package/dist/chains/openai_functions/openapi.cjs.map +1 -1
- package/dist/chains/openai_functions/openapi.js +9 -8
- package/dist/chains/openai_functions/openapi.js.map +1 -1
- package/dist/chains/openai_functions/tagging.cjs.map +1 -1
- package/dist/chains/openai_moderation.cjs.map +1 -1
- package/dist/chains/query_constructor/index.cjs +15 -9
- package/dist/chains/query_constructor/index.cjs.map +1 -1
- package/dist/chains/query_constructor/index.js +15 -9
- package/dist/chains/query_constructor/index.js.map +1 -1
- package/dist/chains/query_constructor/parser.cjs +12 -6
- package/dist/chains/query_constructor/parser.cjs.map +1 -1
- package/dist/chains/query_constructor/parser.js +12 -6
- package/dist/chains/query_constructor/parser.js.map +1 -1
- package/dist/chains/question_answering/load.cjs +35 -29
- package/dist/chains/question_answering/load.cjs.map +1 -1
- package/dist/chains/question_answering/load.js +35 -29
- package/dist/chains/question_answering/load.js.map +1 -1
- package/dist/chains/router/multi_prompt.cjs +5 -3
- package/dist/chains/router/multi_prompt.cjs.map +1 -1
- package/dist/chains/router/multi_prompt.js +5 -3
- package/dist/chains/router/multi_prompt.js.map +1 -1
- package/dist/chains/router/multi_retrieval_qa.cjs +18 -11
- package/dist/chains/router/multi_retrieval_qa.cjs.map +1 -1
- package/dist/chains/router/multi_retrieval_qa.js +18 -11
- package/dist/chains/router/multi_retrieval_qa.js.map +1 -1
- package/dist/chains/sequential_chain.cjs +6 -5
- package/dist/chains/sequential_chain.cjs.map +1 -1
- package/dist/chains/sequential_chain.js +6 -5
- package/dist/chains/sequential_chain.js.map +1 -1
- package/dist/chains/sql_db/sql_db_chain.cjs +2 -1
- package/dist/chains/sql_db/sql_db_chain.cjs.map +1 -1
- package/dist/chains/sql_db/sql_db_chain.js +2 -1
- package/dist/chains/sql_db/sql_db_chain.js.map +1 -1
- package/dist/chains/summarization/load.cjs +35 -29
- package/dist/chains/summarization/load.cjs.map +1 -1
- package/dist/chains/summarization/load.js +35 -29
- package/dist/chains/summarization/load.js.map +1 -1
- package/dist/chat_models/universal.cjs +12 -10
- package/dist/chat_models/universal.cjs.map +1 -1
- package/dist/chat_models/universal.js +12 -10
- package/dist/chat_models/universal.js.map +1 -1
- package/dist/document_loaders/fs/buffer.cjs.map +1 -1
- package/dist/document_loaders/fs/directory.cjs.map +1 -1
- package/dist/document_loaders/fs/multi_file.cjs.map +1 -1
- package/dist/document_loaders/fs/text.cjs.map +1 -1
- package/dist/document_transformers/openai_functions.cjs.map +1 -1
- package/dist/embeddings/cache_backed.cjs.map +1 -1
- package/dist/evaluation/comparison/pairwise.cjs +4 -2
- package/dist/evaluation/comparison/pairwise.cjs.map +1 -1
- package/dist/evaluation/comparison/pairwise.js +4 -2
- package/dist/evaluation/comparison/pairwise.js.map +1 -1
- package/dist/evaluation/criteria/criteria.cjs +4 -2
- package/dist/evaluation/criteria/criteria.cjs.map +1 -1
- package/dist/evaluation/criteria/criteria.js +4 -2
- package/dist/evaluation/criteria/criteria.js.map +1 -1
- package/dist/experimental/autogpt/agent.cjs +8 -7
- package/dist/experimental/autogpt/agent.cjs.map +1 -1
- package/dist/experimental/autogpt/agent.js +8 -7
- package/dist/experimental/autogpt/agent.js.map +1 -1
- package/dist/experimental/autogpt/prompt.cjs +2 -1
- package/dist/experimental/autogpt/prompt.cjs.map +1 -1
- package/dist/experimental/autogpt/prompt.js +2 -1
- package/dist/experimental/autogpt/prompt.js.map +1 -1
- package/dist/experimental/autogpt/prompt_generator.cjs.map +1 -1
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.cjs.map +1 -1
- package/dist/experimental/openai_assistant/index.cjs.map +1 -1
- package/dist/experimental/plan_and_execute/agent_executor.cjs +3 -2
- package/dist/experimental/plan_and_execute/agent_executor.cjs.map +1 -1
- package/dist/experimental/plan_and_execute/agent_executor.js +3 -2
- package/dist/experimental/plan_and_execute/agent_executor.js.map +1 -1
- package/dist/hub/base.cjs.map +1 -1
- package/dist/hub/base.js.map +1 -1
- package/dist/hub/index.cjs +2 -1
- package/dist/hub/index.cjs.map +1 -1
- package/dist/hub/index.js +2 -1
- package/dist/hub/index.js.map +1 -1
- package/dist/hub/node.cjs +4 -2
- package/dist/hub/node.cjs.map +1 -1
- package/dist/hub/node.js +4 -2
- package/dist/hub/node.js.map +1 -1
- package/dist/load/index.cjs.map +1 -1
- package/dist/memory/buffer_memory.cjs.map +1 -1
- package/dist/memory/buffer_token_memory.cjs.map +1 -1
- package/dist/memory/buffer_window_memory.cjs.map +1 -1
- package/dist/memory/chat_memory.cjs.map +1 -1
- package/dist/memory/entity_memory.cjs +2 -1
- package/dist/memory/entity_memory.cjs.map +1 -1
- package/dist/memory/entity_memory.js +2 -1
- package/dist/memory/entity_memory.js.map +1 -1
- package/dist/memory/summary.cjs.map +1 -1
- package/dist/memory/summary_buffer.cjs.map +1 -1
- package/dist/memory/vector_store.cjs.map +1 -1
- package/dist/output_parsers/fix.cjs +2 -1
- package/dist/output_parsers/fix.cjs.map +1 -1
- package/dist/output_parsers/fix.js +2 -1
- package/dist/output_parsers/fix.js.map +1 -1
- package/dist/output_parsers/openai_functions.cjs.map +1 -1
- package/dist/output_parsers/structured.cjs.map +1 -1
- package/dist/retrievers/document_compressors/chain_extract.cjs +2 -1
- package/dist/retrievers/document_compressors/chain_extract.cjs.map +1 -1
- package/dist/retrievers/document_compressors/chain_extract.js +2 -1
- package/dist/retrievers/document_compressors/chain_extract.js.map +1 -1
- package/dist/retrievers/matryoshka_retriever.cjs.map +1 -1
- package/dist/retrievers/multi_query.cjs +2 -1
- package/dist/retrievers/multi_query.cjs.map +1 -1
- package/dist/retrievers/multi_query.js +2 -1
- package/dist/retrievers/multi_query.js.map +1 -1
- package/dist/smith/runner_utils.cjs.map +1 -1
- package/dist/stores/file/node.cjs.map +1 -1
- package/dist/tools/render.cjs.map +1 -1
- package/dist/tools/retriever.cjs +2 -1
- package/dist/tools/retriever.cjs.map +1 -1
- package/dist/tools/retriever.js +2 -1
- package/dist/tools/retriever.js.map +1 -1
- package/dist/tools/webbrowser.cjs +2 -1
- package/dist/tools/webbrowser.cjs.map +1 -1
- package/dist/tools/webbrowser.js +2 -1
- package/dist/tools/webbrowser.js.map +1 -1
- package/dist/util/hub.cjs.map +1 -1
- package/dist/vectorstores/memory.cjs +2 -1
- package/dist/vectorstores/memory.cjs.map +1 -1
- package/dist/vectorstores/memory.js +2 -1
- package/dist/vectorstores/memory.js.map +1 -1
- package/package.json +23 -23
|
@@ -4,7 +4,8 @@ let zod = require("zod");
|
|
|
4
4
|
//#region src/agents/toolkits/conversational_retrieval/tool.ts
|
|
5
5
|
function createRetrieverTool(retriever, input) {
|
|
6
6
|
const func = async ({ input }, runManager) => {
|
|
7
|
-
|
|
7
|
+
const docs = await retriever.invoke(input, runManager?.getChild("retriever"));
|
|
8
|
+
return require_util_document.formatDocumentsAsString(docs);
|
|
8
9
|
};
|
|
9
10
|
const schema = zod.z.object({ input: zod.z.string().describe("Natural language query used as input to the retriever") });
|
|
10
11
|
return new _langchain_core_tools.DynamicStructuredTool({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.cjs","names":["formatDocumentsAsString","z","DynamicStructuredTool"],"sources":["../../../../src/agents/toolkits/conversational_retrieval/tool.ts"],"sourcesContent":["import type { BaseRetrieverInterface } from \"@langchain/core/retrievers\";\nimport { z } from \"zod\";\nimport { CallbackManagerForToolRun } from \"@langchain/core/callbacks/manager\";\nimport {\n DynamicStructuredTool,\n DynamicStructuredToolInput,\n} from \"@langchain/core/tools\";\nimport { formatDocumentsAsString } from \"../../../util/document.js\";\n\nexport function createRetrieverTool(\n retriever: BaseRetrieverInterface,\n input: Omit<DynamicStructuredToolInput, \"func\" | \"schema\">\n) {\n const func = async (\n { input }: { input: string },\n runManager?: CallbackManagerForToolRun\n ) => {\n const docs = await retriever.invoke(\n input,\n runManager?.getChild(\"retriever\")\n );\n return formatDocumentsAsString(docs);\n };\n const schema = z.object({\n input: z\n .string()\n .describe(\"Natural language query used as input to the retriever\"),\n });\n return new DynamicStructuredTool({ ...input, func, schema });\n}\n"],"mappings":";;;;AASA,SAAgB,oBACd,WACA,OACA;CACA,MAAM,OAAO,OACX,EAAE,SACF,eACG;
|
|
1
|
+
{"version":3,"file":"tool.cjs","names":["formatDocumentsAsString","z","DynamicStructuredTool"],"sources":["../../../../src/agents/toolkits/conversational_retrieval/tool.ts"],"sourcesContent":["import type { BaseRetrieverInterface } from \"@langchain/core/retrievers\";\nimport { z } from \"zod\";\nimport { CallbackManagerForToolRun } from \"@langchain/core/callbacks/manager\";\nimport {\n DynamicStructuredTool,\n DynamicStructuredToolInput,\n} from \"@langchain/core/tools\";\nimport { formatDocumentsAsString } from \"../../../util/document.js\";\n\nexport function createRetrieverTool(\n retriever: BaseRetrieverInterface,\n input: Omit<DynamicStructuredToolInput, \"func\" | \"schema\">\n) {\n const func = async (\n { input }: { input: string },\n runManager?: CallbackManagerForToolRun\n ) => {\n const docs = await retriever.invoke(\n input,\n runManager?.getChild(\"retriever\")\n );\n return formatDocumentsAsString(docs);\n };\n const schema = z.object({\n input: z\n .string()\n .describe(\"Natural language query used as input to the retriever\"),\n });\n return new DynamicStructuredTool({ ...input, func, schema });\n}\n"],"mappings":";;;;AASA,SAAgB,oBACd,WACA,OACA;CACA,MAAM,OAAO,OACX,EAAE,SACF,eACG;EACH,MAAM,OAAO,MAAM,UAAU,OAC3B,OACA,YAAY,SAAS,WAAW,CAClC;EACA,OAAOA,sBAAAA,wBAAwB,IAAI;CACrC;CACA,MAAM,SAASC,IAAAA,EAAE,OAAO,EACtB,OAAOA,IAAAA,EACJ,OAAO,CAAC,CACR,SAAS,uDAAuD,EACrE,CAAC;CACD,OAAO,IAAIC,sBAAAA,sBAAsB;EAAE,GAAG;EAAO;EAAM;CAAO,CAAC;AAC7D"}
|
|
@@ -4,7 +4,8 @@ import { z } from "zod";
|
|
|
4
4
|
//#region src/agents/toolkits/conversational_retrieval/tool.ts
|
|
5
5
|
function createRetrieverTool(retriever, input) {
|
|
6
6
|
const func = async ({ input }, runManager) => {
|
|
7
|
-
|
|
7
|
+
const docs = await retriever.invoke(input, runManager?.getChild("retriever"));
|
|
8
|
+
return formatDocumentsAsString(docs);
|
|
8
9
|
};
|
|
9
10
|
const schema = z.object({ input: z.string().describe("Natural language query used as input to the retriever") });
|
|
10
11
|
return new DynamicStructuredTool({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","names":[],"sources":["../../../../src/agents/toolkits/conversational_retrieval/tool.ts"],"sourcesContent":["import type { BaseRetrieverInterface } from \"@langchain/core/retrievers\";\nimport { z } from \"zod\";\nimport { CallbackManagerForToolRun } from \"@langchain/core/callbacks/manager\";\nimport {\n DynamicStructuredTool,\n DynamicStructuredToolInput,\n} from \"@langchain/core/tools\";\nimport { formatDocumentsAsString } from \"../../../util/document.js\";\n\nexport function createRetrieverTool(\n retriever: BaseRetrieverInterface,\n input: Omit<DynamicStructuredToolInput, \"func\" | \"schema\">\n) {\n const func = async (\n { input }: { input: string },\n runManager?: CallbackManagerForToolRun\n ) => {\n const docs = await retriever.invoke(\n input,\n runManager?.getChild(\"retriever\")\n );\n return formatDocumentsAsString(docs);\n };\n const schema = z.object({\n input: z\n .string()\n .describe(\"Natural language query used as input to the retriever\"),\n });\n return new DynamicStructuredTool({ ...input, func, schema });\n}\n"],"mappings":";;;;AASA,SAAgB,oBACd,WACA,OACA;CACA,MAAM,OAAO,OACX,EAAE,SACF,eACG;
|
|
1
|
+
{"version":3,"file":"tool.js","names":[],"sources":["../../../../src/agents/toolkits/conversational_retrieval/tool.ts"],"sourcesContent":["import type { BaseRetrieverInterface } from \"@langchain/core/retrievers\";\nimport { z } from \"zod\";\nimport { CallbackManagerForToolRun } from \"@langchain/core/callbacks/manager\";\nimport {\n DynamicStructuredTool,\n DynamicStructuredToolInput,\n} from \"@langchain/core/tools\";\nimport { formatDocumentsAsString } from \"../../../util/document.js\";\n\nexport function createRetrieverTool(\n retriever: BaseRetrieverInterface,\n input: Omit<DynamicStructuredToolInput, \"func\" | \"schema\">\n) {\n const func = async (\n { input }: { input: string },\n runManager?: CallbackManagerForToolRun\n ) => {\n const docs = await retriever.invoke(\n input,\n runManager?.getChild(\"retriever\")\n );\n return formatDocumentsAsString(docs);\n };\n const schema = z.object({\n input: z\n .string()\n .describe(\"Natural language query used as input to the retriever\"),\n });\n return new DynamicStructuredTool({ ...input, func, schema });\n}\n"],"mappings":";;;;AASA,SAAgB,oBACd,WACA,OACA;CACA,MAAM,OAAO,OACX,EAAE,SACF,eACG;EACH,MAAM,OAAO,MAAM,UAAU,OAC3B,OACA,YAAY,SAAS,WAAW,CAClC;EACA,OAAO,wBAAwB,IAAI;CACrC;CACA,MAAM,SAAS,EAAE,OAAO,EACtB,OAAO,EACJ,OAAO,CAAC,CACR,SAAS,uDAAuD,EACrE,CAAC;CACD,OAAO,IAAI,sBAAsB;EAAE,GAAG;EAAO;EAAM;CAAO,CAAC;AAC7D"}
|
|
@@ -40,15 +40,17 @@ var JsonToolkit = class extends _langchain_core_tools.BaseToolkit {
|
|
|
40
40
|
function createJsonAgent(llm, toolkit, args) {
|
|
41
41
|
const { prefix = require_prompt.JSON_PREFIX, suffix = require_prompt.JSON_SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
42
42
|
const { tools } = toolkit;
|
|
43
|
+
const prompt = require_index.ZeroShotAgent.createPrompt(tools, {
|
|
44
|
+
prefix,
|
|
45
|
+
suffix,
|
|
46
|
+
inputVariables
|
|
47
|
+
});
|
|
48
|
+
const chain = new require_llm_chain.LLMChain({
|
|
49
|
+
prompt,
|
|
50
|
+
llm
|
|
51
|
+
});
|
|
43
52
|
const agent = new require_index.ZeroShotAgent({
|
|
44
|
-
llmChain:
|
|
45
|
-
prompt: require_index.ZeroShotAgent.createPrompt(tools, {
|
|
46
|
-
prefix,
|
|
47
|
-
suffix,
|
|
48
|
-
inputVariables
|
|
49
|
-
}),
|
|
50
|
-
llm
|
|
51
|
-
}),
|
|
53
|
+
llmChain: chain,
|
|
52
54
|
allowedTools: tools.map((t) => t.name)
|
|
53
55
|
});
|
|
54
56
|
return require_executor.AgentExecutor.fromAgentAndTools({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.cjs","names":["BaseToolkit","JsonListKeysTool","JsonGetValueTool","JSON_PREFIX","JSON_SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/json/json.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport {\n JsonGetValueTool,\n JsonListKeysTool,\n JsonSpec,\n} from \"../../../tools/json.js\";\nimport { JSON_PREFIX, JSON_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Represents a toolkit for working with JSON data. It initializes the\n * JSON tools based on the provided JSON specification.\n * @example\n * ```typescript\n * const toolkit = new JsonToolkit(new JsonSpec());\n * const executor = createJsonAgent(model, toolkit);\n * const result = await executor.invoke({\n * input: 'What are the required parameters in the request body to the /completions endpoint?'\n * });\n * ```\n */\nexport class JsonToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(public jsonSpec: JsonSpec) {\n super();\n this.tools = [\n new JsonListKeysTool(jsonSpec),\n new JsonGetValueTool(jsonSpec),\n ];\n }\n}\n\n/**\n * Creates a JSON agent using a language model, a JSON toolkit, and\n * optional prompt arguments. It creates a prompt for the agent using the\n * JSON tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the JSON tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model used to create the JSON agent.\n * @param toolkit The JSON toolkit used to create the JSON agent.\n * @param args Optional prompt arguments used to create the JSON agent.\n * @returns An AgentExecutor for executing the created JSON agent with the tools.\n */\nexport function createJsonAgent(\n llm: BaseLanguageModelInterface,\n toolkit: JsonToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = JSON_PREFIX,\n suffix = JSON_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,IAAa,cAAb,cAAiCA,sBAAAA,YAAY;CAGxB;CAFnB;CAEA,YAAY,UAA2B;EACrC,MAAM;EADW,KAAA,WAAA;EAEjB,KAAK,QAAQ,CACX,IAAIC,aAAAA,iBAAiB,QAAQ,GAC7B,IAAIC,aAAAA,iBAAiB,QAAQ,CAC/B;CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,gBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,aACT,SAASC,eAAAA,aACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"json.cjs","names":["BaseToolkit","JsonListKeysTool","JsonGetValueTool","JSON_PREFIX","JSON_SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/json/json.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport {\n JsonGetValueTool,\n JsonListKeysTool,\n JsonSpec,\n} from \"../../../tools/json.js\";\nimport { JSON_PREFIX, JSON_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Represents a toolkit for working with JSON data. It initializes the\n * JSON tools based on the provided JSON specification.\n * @example\n * ```typescript\n * const toolkit = new JsonToolkit(new JsonSpec());\n * const executor = createJsonAgent(model, toolkit);\n * const result = await executor.invoke({\n * input: 'What are the required parameters in the request body to the /completions endpoint?'\n * });\n * ```\n */\nexport class JsonToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(public jsonSpec: JsonSpec) {\n super();\n this.tools = [\n new JsonListKeysTool(jsonSpec),\n new JsonGetValueTool(jsonSpec),\n ];\n }\n}\n\n/**\n * Creates a JSON agent using a language model, a JSON toolkit, and\n * optional prompt arguments. It creates a prompt for the agent using the\n * JSON tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the JSON tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model used to create the JSON agent.\n * @param toolkit The JSON toolkit used to create the JSON agent.\n * @param args Optional prompt arguments used to create the JSON agent.\n * @returns An AgentExecutor for executing the created JSON agent with the tools.\n */\nexport function createJsonAgent(\n llm: BaseLanguageModelInterface,\n toolkit: JsonToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = JSON_PREFIX,\n suffix = JSON_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,IAAa,cAAb,cAAiCA,sBAAAA,YAAY;CAGxB;CAFnB;CAEA,YAAY,UAA2B;EACrC,MAAM;EADW,KAAA,WAAA;EAEjB,KAAK,QAAQ,CACX,IAAIC,aAAAA,iBAAiB,QAAQ,GAC7B,IAAIC,aAAAA,iBAAiB,QAAQ,CAC/B;CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,gBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,aACT,SAASC,eAAAA,aACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,SAASC,cAAAA,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAIC,kBAAAA,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAID,cAAAA,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAOE,iBAAAA,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -40,15 +40,17 @@ var JsonToolkit = class extends BaseToolkit {
|
|
|
40
40
|
function createJsonAgent(llm, toolkit, args) {
|
|
41
41
|
const { prefix = JSON_PREFIX, suffix = JSON_SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
42
42
|
const { tools } = toolkit;
|
|
43
|
+
const prompt = ZeroShotAgent.createPrompt(tools, {
|
|
44
|
+
prefix,
|
|
45
|
+
suffix,
|
|
46
|
+
inputVariables
|
|
47
|
+
});
|
|
48
|
+
const chain = new LLMChain({
|
|
49
|
+
prompt,
|
|
50
|
+
llm
|
|
51
|
+
});
|
|
43
52
|
const agent = new ZeroShotAgent({
|
|
44
|
-
llmChain:
|
|
45
|
-
prompt: ZeroShotAgent.createPrompt(tools, {
|
|
46
|
-
prefix,
|
|
47
|
-
suffix,
|
|
48
|
-
inputVariables
|
|
49
|
-
}),
|
|
50
|
-
llm
|
|
51
|
-
}),
|
|
53
|
+
llmChain: chain,
|
|
52
54
|
allowedTools: tools.map((t) => t.name)
|
|
53
55
|
});
|
|
54
56
|
return AgentExecutor.fromAgentAndTools({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","names":[],"sources":["../../../../src/agents/toolkits/json/json.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport {\n JsonGetValueTool,\n JsonListKeysTool,\n JsonSpec,\n} from \"../../../tools/json.js\";\nimport { JSON_PREFIX, JSON_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Represents a toolkit for working with JSON data. It initializes the\n * JSON tools based on the provided JSON specification.\n * @example\n * ```typescript\n * const toolkit = new JsonToolkit(new JsonSpec());\n * const executor = createJsonAgent(model, toolkit);\n * const result = await executor.invoke({\n * input: 'What are the required parameters in the request body to the /completions endpoint?'\n * });\n * ```\n */\nexport class JsonToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(public jsonSpec: JsonSpec) {\n super();\n this.tools = [\n new JsonListKeysTool(jsonSpec),\n new JsonGetValueTool(jsonSpec),\n ];\n }\n}\n\n/**\n * Creates a JSON agent using a language model, a JSON toolkit, and\n * optional prompt arguments. It creates a prompt for the agent using the\n * JSON tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the JSON tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model used to create the JSON agent.\n * @param toolkit The JSON toolkit used to create the JSON agent.\n * @param args Optional prompt arguments used to create the JSON agent.\n * @returns An AgentExecutor for executing the created JSON agent with the tools.\n */\nexport function createJsonAgent(\n llm: BaseLanguageModelInterface,\n toolkit: JsonToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = JSON_PREFIX,\n suffix = JSON_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,IAAa,cAAb,cAAiC,YAAY;CAGxB;CAFnB;CAEA,YAAY,UAA2B;EACrC,MAAM;EADW,KAAA,WAAA;EAEjB,KAAK,QAAQ,CACX,IAAI,iBAAiB,QAAQ,GAC7B,IAAI,iBAAiB,QAAQ,CAC/B;CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,gBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,aACT,SAAS,aACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"json.js","names":[],"sources":["../../../../src/agents/toolkits/json/json.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport {\n JsonGetValueTool,\n JsonListKeysTool,\n JsonSpec,\n} from \"../../../tools/json.js\";\nimport { JSON_PREFIX, JSON_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Represents a toolkit for working with JSON data. It initializes the\n * JSON tools based on the provided JSON specification.\n * @example\n * ```typescript\n * const toolkit = new JsonToolkit(new JsonSpec());\n * const executor = createJsonAgent(model, toolkit);\n * const result = await executor.invoke({\n * input: 'What are the required parameters in the request body to the /completions endpoint?'\n * });\n * ```\n */\nexport class JsonToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(public jsonSpec: JsonSpec) {\n super();\n this.tools = [\n new JsonListKeysTool(jsonSpec),\n new JsonGetValueTool(jsonSpec),\n ];\n }\n}\n\n/**\n * Creates a JSON agent using a language model, a JSON toolkit, and\n * optional prompt arguments. It creates a prompt for the agent using the\n * JSON tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the JSON tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model used to create the JSON agent.\n * @param toolkit The JSON toolkit used to create the JSON agent.\n * @param args Optional prompt arguments used to create the JSON agent.\n * @returns An AgentExecutor for executing the created JSON agent with the tools.\n */\nexport function createJsonAgent(\n llm: BaseLanguageModelInterface,\n toolkit: JsonToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = JSON_PREFIX,\n suffix = JSON_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,IAAa,cAAb,cAAiC,YAAY;CAGxB;CAFnB;CAEA,YAAY,UAA2B;EACrC,MAAM;EADW,KAAA,WAAA;EAEjB,KAAK,QAAQ,CACX,IAAI,iBAAiB,QAAQ,GAC7B,IAAI,iBAAiB,QAAQ,CAC/B;CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,gBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,aACT,SAAS,aACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,SAAS,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAI,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAO,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -76,16 +76,19 @@ var OpenApiToolkit = class extends RequestsToolkit {
|
|
|
76
76
|
function createOpenApiAgent(llm, openApiToolkit, args) {
|
|
77
77
|
const { prefix = require_prompt.OPENAPI_PREFIX, suffix = require_prompt.OPENAPI_SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
78
78
|
const { tools } = openApiToolkit;
|
|
79
|
+
const prompt = require_index.ZeroShotAgent.createPrompt(tools, {
|
|
80
|
+
prefix,
|
|
81
|
+
suffix,
|
|
82
|
+
inputVariables
|
|
83
|
+
});
|
|
84
|
+
const chain = new require_llm_chain.LLMChain({
|
|
85
|
+
prompt,
|
|
86
|
+
llm
|
|
87
|
+
});
|
|
88
|
+
const toolNames = tools.map((tool) => tool.name);
|
|
79
89
|
const agent = new require_index.ZeroShotAgent({
|
|
80
|
-
llmChain:
|
|
81
|
-
|
|
82
|
-
prefix,
|
|
83
|
-
suffix,
|
|
84
|
-
inputVariables
|
|
85
|
-
}),
|
|
86
|
-
llm
|
|
87
|
-
}),
|
|
88
|
-
allowedTools: tools.map((tool) => tool.name)
|
|
90
|
+
llmChain: chain,
|
|
91
|
+
allowedTools: toolNames
|
|
89
92
|
});
|
|
90
93
|
return require_executor.AgentExecutor.fromAgentAndTools({
|
|
91
94
|
agent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.cjs","names":["BaseToolkit","RequestsGetTool","RequestsPostTool","createJsonAgent","JsonToolkit","DynamicTool","JSON_EXPLORER_DESCRIPTION","OPENAPI_PREFIX","OPENAPI_SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/openapi/openapi.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport { DynamicTool, BaseToolkit } from \"@langchain/core/tools\";\nimport { JsonSpec } from \"../../../tools/json.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport {\n OPENAPI_PREFIX,\n OPENAPI_SUFFIX,\n JSON_EXPLORER_DESCRIPTION,\n} from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport {\n Headers,\n RequestsGetTool,\n RequestsPostTool,\n} from \"../../../tools/requests.js\";\nimport { createJsonAgent, JsonToolkit } from \"../json/json.js\";\n\n/**\n * Represents a toolkit for making HTTP requests. It initializes the\n * request tools based on the provided headers.\n */\nexport class RequestsToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(headers?: Headers) {\n super();\n this.tools = [new RequestsGetTool(headers), new RequestsPostTool(headers)];\n }\n}\n\n/**\n * Extends the `RequestsToolkit` class and adds a dynamic tool for\n * exploring JSON data. It creates a JSON agent using the `JsonToolkit`\n * and the provided language model, and adds the JSON explorer tool to the\n * toolkit.\n * @example\n * ```typescript\n * const toolkit = new OpenApiToolkit(\n * new JsonSpec({\n * }),\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * {\n * \"Content-Type\": \"application/json\",\n * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n * },\n * );\n *\n * const result = await toolkit.invoke({\n * input:\n * \"Make a POST request to openai /completions. The prompt should be 'tell me a joke.'\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class OpenApiToolkit extends RequestsToolkit {\n constructor(\n jsonSpec: JsonSpec,\n llm: BaseLanguageModelInterface,\n headers?: Headers\n ) {\n super(headers);\n const jsonAgent = createJsonAgent(llm, new JsonToolkit(jsonSpec));\n this.tools = [\n ...this.tools,\n new DynamicTool({\n name: \"json_explorer\",\n func: async (input: string) => {\n const result = await jsonAgent.call({ input });\n return result.output as string;\n },\n description: JSON_EXPLORER_DESCRIPTION,\n }),\n ];\n }\n}\n\n/**\n * Creates an OpenAPI agent using a language model, an OpenAPI toolkit,\n * and optional prompt arguments. It creates a prompt for the agent using\n * the OpenAPI tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the OpenAPI tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model to use.\n * @param openApiToolkit The OpenAPI toolkit to use.\n * @param args Optional arguments for creating the prompt.\n * @returns An AgentExecutor for executing the agent with the tools.\n *\n * @security **Security Notice** This agent provides access to external APIs.\n * Use with caution as this agent can make API calls with arbitrary headers.\n * Exposing this agent to users could lead to security vulnerabilities. Consider\n * limiting access to what endpoints it can hit, what actions can be taken, and\n * more.\n *\n * @link See https://js.langchain.com/docs/security for more information.\n */\nexport function createOpenApiAgent(\n llm: BaseLanguageModelInterface,\n openApiToolkit: OpenApiToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = OPENAPI_PREFIX,\n suffix = OPENAPI_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n\n const { tools } = openApiToolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({\n prompt,\n llm,\n });\n const toolNames = tools.map((tool) => tool.name);\n const agent = new ZeroShotAgent({ llmChain: chain, allowedTools: toolNames });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,IAAa,kBAAb,cAAqCA,sBAAAA,YAAY;CAC/C;CAEA,YAAY,SAAmB;EAC7B,MAAM;EACN,KAAK,QAAQ,CAAC,IAAIC,iBAAAA,gBAAgB,OAAO,GAAG,IAAIC,iBAAAA,iBAAiB,OAAO,CAAC;CAC3E;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,iBAAb,cAAoC,gBAAgB;CAClD,YACE,UACA,KACA,SACA;EACA,MAAM,OAAO;EACb,MAAM,YAAYC,aAAAA,gBAAgB,KAAK,IAAIC,aAAAA,YAAY,QAAQ,CAAC;EAChE,KAAK,QAAQ,CACX,GAAG,KAAK,OACR,IAAIC,sBAAAA,YAAY;GACd,MAAM;GACN,MAAM,OAAO,UAAkB;IAE7B,QAAO,MADc,UAAU,KAAK,EAAE,MAAM,CAAC,EAAA,CAC/B;GAChB;GACA,aAAaC,eAAAA;EACf,CAAC,CACH;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBACd,KACA,gBACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,gBACT,SAASC,eAAAA,gBACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CAEb,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"openapi.cjs","names":["BaseToolkit","RequestsGetTool","RequestsPostTool","createJsonAgent","JsonToolkit","DynamicTool","JSON_EXPLORER_DESCRIPTION","OPENAPI_PREFIX","OPENAPI_SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/openapi/openapi.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport { DynamicTool, BaseToolkit } from \"@langchain/core/tools\";\nimport { JsonSpec } from \"../../../tools/json.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport {\n OPENAPI_PREFIX,\n OPENAPI_SUFFIX,\n JSON_EXPLORER_DESCRIPTION,\n} from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport {\n Headers,\n RequestsGetTool,\n RequestsPostTool,\n} from \"../../../tools/requests.js\";\nimport { createJsonAgent, JsonToolkit } from \"../json/json.js\";\n\n/**\n * Represents a toolkit for making HTTP requests. It initializes the\n * request tools based on the provided headers.\n */\nexport class RequestsToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(headers?: Headers) {\n super();\n this.tools = [new RequestsGetTool(headers), new RequestsPostTool(headers)];\n }\n}\n\n/**\n * Extends the `RequestsToolkit` class and adds a dynamic tool for\n * exploring JSON data. It creates a JSON agent using the `JsonToolkit`\n * and the provided language model, and adds the JSON explorer tool to the\n * toolkit.\n * @example\n * ```typescript\n * const toolkit = new OpenApiToolkit(\n * new JsonSpec({\n * }),\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * {\n * \"Content-Type\": \"application/json\",\n * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n * },\n * );\n *\n * const result = await toolkit.invoke({\n * input:\n * \"Make a POST request to openai /completions. The prompt should be 'tell me a joke.'\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class OpenApiToolkit extends RequestsToolkit {\n constructor(\n jsonSpec: JsonSpec,\n llm: BaseLanguageModelInterface,\n headers?: Headers\n ) {\n super(headers);\n const jsonAgent = createJsonAgent(llm, new JsonToolkit(jsonSpec));\n this.tools = [\n ...this.tools,\n new DynamicTool({\n name: \"json_explorer\",\n func: async (input: string) => {\n const result = await jsonAgent.call({ input });\n return result.output as string;\n },\n description: JSON_EXPLORER_DESCRIPTION,\n }),\n ];\n }\n}\n\n/**\n * Creates an OpenAPI agent using a language model, an OpenAPI toolkit,\n * and optional prompt arguments. It creates a prompt for the agent using\n * the OpenAPI tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the OpenAPI tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model to use.\n * @param openApiToolkit The OpenAPI toolkit to use.\n * @param args Optional arguments for creating the prompt.\n * @returns An AgentExecutor for executing the agent with the tools.\n *\n * @security **Security Notice** This agent provides access to external APIs.\n * Use with caution as this agent can make API calls with arbitrary headers.\n * Exposing this agent to users could lead to security vulnerabilities. Consider\n * limiting access to what endpoints it can hit, what actions can be taken, and\n * more.\n *\n * @link See https://js.langchain.com/docs/security for more information.\n */\nexport function createOpenApiAgent(\n llm: BaseLanguageModelInterface,\n openApiToolkit: OpenApiToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = OPENAPI_PREFIX,\n suffix = OPENAPI_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n\n const { tools } = openApiToolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({\n prompt,\n llm,\n });\n const toolNames = tools.map((tool) => tool.name);\n const agent = new ZeroShotAgent({ llmChain: chain, allowedTools: toolNames });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,IAAa,kBAAb,cAAqCA,sBAAAA,YAAY;CAC/C;CAEA,YAAY,SAAmB;EAC7B,MAAM;EACN,KAAK,QAAQ,CAAC,IAAIC,iBAAAA,gBAAgB,OAAO,GAAG,IAAIC,iBAAAA,iBAAiB,OAAO,CAAC;CAC3E;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,iBAAb,cAAoC,gBAAgB;CAClD,YACE,UACA,KACA,SACA;EACA,MAAM,OAAO;EACb,MAAM,YAAYC,aAAAA,gBAAgB,KAAK,IAAIC,aAAAA,YAAY,QAAQ,CAAC;EAChE,KAAK,QAAQ,CACX,GAAG,KAAK,OACR,IAAIC,sBAAAA,YAAY;GACd,MAAM;GACN,MAAM,OAAO,UAAkB;IAE7B,QAAO,MADc,UAAU,KAAK,EAAE,MAAM,CAAC,EAAA,CAC/B;GAChB;GACA,aAAaC,eAAAA;EACf,CAAC,CACH;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBACd,KACA,gBACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,gBACT,SAASC,eAAAA,gBACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CAEb,MAAM,EAAE,UAAU;CAClB,MAAM,SAASC,cAAAA,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAIC,kBAAAA,SAAS;EACzB;EACA;CACF,CAAC;CACD,MAAM,YAAY,MAAM,KAAK,SAAS,KAAK,IAAI;CAC/C,MAAM,QAAQ,IAAID,cAAAA,cAAc;EAAE,UAAU;EAAO,cAAc;CAAU,CAAC;CAC5E,OAAOE,iBAAAA,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -76,16 +76,19 @@ var OpenApiToolkit = class extends RequestsToolkit {
|
|
|
76
76
|
function createOpenApiAgent(llm, openApiToolkit, args) {
|
|
77
77
|
const { prefix = OPENAPI_PREFIX, suffix = OPENAPI_SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
78
78
|
const { tools } = openApiToolkit;
|
|
79
|
+
const prompt = ZeroShotAgent.createPrompt(tools, {
|
|
80
|
+
prefix,
|
|
81
|
+
suffix,
|
|
82
|
+
inputVariables
|
|
83
|
+
});
|
|
84
|
+
const chain = new LLMChain({
|
|
85
|
+
prompt,
|
|
86
|
+
llm
|
|
87
|
+
});
|
|
88
|
+
const toolNames = tools.map((tool) => tool.name);
|
|
79
89
|
const agent = new ZeroShotAgent({
|
|
80
|
-
llmChain:
|
|
81
|
-
|
|
82
|
-
prefix,
|
|
83
|
-
suffix,
|
|
84
|
-
inputVariables
|
|
85
|
-
}),
|
|
86
|
-
llm
|
|
87
|
-
}),
|
|
88
|
-
allowedTools: tools.map((tool) => tool.name)
|
|
90
|
+
llmChain: chain,
|
|
91
|
+
allowedTools: toolNames
|
|
89
92
|
});
|
|
90
93
|
return AgentExecutor.fromAgentAndTools({
|
|
91
94
|
agent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","names":[],"sources":["../../../../src/agents/toolkits/openapi/openapi.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport { DynamicTool, BaseToolkit } from \"@langchain/core/tools\";\nimport { JsonSpec } from \"../../../tools/json.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport {\n OPENAPI_PREFIX,\n OPENAPI_SUFFIX,\n JSON_EXPLORER_DESCRIPTION,\n} from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport {\n Headers,\n RequestsGetTool,\n RequestsPostTool,\n} from \"../../../tools/requests.js\";\nimport { createJsonAgent, JsonToolkit } from \"../json/json.js\";\n\n/**\n * Represents a toolkit for making HTTP requests. It initializes the\n * request tools based on the provided headers.\n */\nexport class RequestsToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(headers?: Headers) {\n super();\n this.tools = [new RequestsGetTool(headers), new RequestsPostTool(headers)];\n }\n}\n\n/**\n * Extends the `RequestsToolkit` class and adds a dynamic tool for\n * exploring JSON data. It creates a JSON agent using the `JsonToolkit`\n * and the provided language model, and adds the JSON explorer tool to the\n * toolkit.\n * @example\n * ```typescript\n * const toolkit = new OpenApiToolkit(\n * new JsonSpec({\n * }),\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * {\n * \"Content-Type\": \"application/json\",\n * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n * },\n * );\n *\n * const result = await toolkit.invoke({\n * input:\n * \"Make a POST request to openai /completions. The prompt should be 'tell me a joke.'\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class OpenApiToolkit extends RequestsToolkit {\n constructor(\n jsonSpec: JsonSpec,\n llm: BaseLanguageModelInterface,\n headers?: Headers\n ) {\n super(headers);\n const jsonAgent = createJsonAgent(llm, new JsonToolkit(jsonSpec));\n this.tools = [\n ...this.tools,\n new DynamicTool({\n name: \"json_explorer\",\n func: async (input: string) => {\n const result = await jsonAgent.call({ input });\n return result.output as string;\n },\n description: JSON_EXPLORER_DESCRIPTION,\n }),\n ];\n }\n}\n\n/**\n * Creates an OpenAPI agent using a language model, an OpenAPI toolkit,\n * and optional prompt arguments. It creates a prompt for the agent using\n * the OpenAPI tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the OpenAPI tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model to use.\n * @param openApiToolkit The OpenAPI toolkit to use.\n * @param args Optional arguments for creating the prompt.\n * @returns An AgentExecutor for executing the agent with the tools.\n *\n * @security **Security Notice** This agent provides access to external APIs.\n * Use with caution as this agent can make API calls with arbitrary headers.\n * Exposing this agent to users could lead to security vulnerabilities. Consider\n * limiting access to what endpoints it can hit, what actions can be taken, and\n * more.\n *\n * @link See https://js.langchain.com/docs/security for more information.\n */\nexport function createOpenApiAgent(\n llm: BaseLanguageModelInterface,\n openApiToolkit: OpenApiToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = OPENAPI_PREFIX,\n suffix = OPENAPI_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n\n const { tools } = openApiToolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({\n prompt,\n llm,\n });\n const toolNames = tools.map((tool) => tool.name);\n const agent = new ZeroShotAgent({ llmChain: chain, allowedTools: toolNames });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,IAAa,kBAAb,cAAqC,YAAY;CAC/C;CAEA,YAAY,SAAmB;EAC7B,MAAM;EACN,KAAK,QAAQ,CAAC,IAAI,gBAAgB,OAAO,GAAG,IAAI,iBAAiB,OAAO,CAAC;CAC3E;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,iBAAb,cAAoC,gBAAgB;CAClD,YACE,UACA,KACA,SACA;EACA,MAAM,OAAO;EACb,MAAM,YAAY,gBAAgB,KAAK,IAAI,YAAY,QAAQ,CAAC;EAChE,KAAK,QAAQ,CACX,GAAG,KAAK,OACR,IAAI,YAAY;GACd,MAAM;GACN,MAAM,OAAO,UAAkB;IAE7B,QAAO,MADc,UAAU,KAAK,EAAE,MAAM,CAAC,EAAA,CAC/B;GAChB;GACA,aAAa;EACf,CAAC,CACH;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBACd,KACA,gBACA,MACA;CACA,MAAM,EACJ,SAAS,gBACT,SAAS,gBACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CAEb,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"openapi.js","names":[],"sources":["../../../../src/agents/toolkits/openapi/openapi.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport { DynamicTool, BaseToolkit } from \"@langchain/core/tools\";\nimport { JsonSpec } from \"../../../tools/json.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport {\n OPENAPI_PREFIX,\n OPENAPI_SUFFIX,\n JSON_EXPLORER_DESCRIPTION,\n} from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport {\n Headers,\n RequestsGetTool,\n RequestsPostTool,\n} from \"../../../tools/requests.js\";\nimport { createJsonAgent, JsonToolkit } from \"../json/json.js\";\n\n/**\n * Represents a toolkit for making HTTP requests. It initializes the\n * request tools based on the provided headers.\n */\nexport class RequestsToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n constructor(headers?: Headers) {\n super();\n this.tools = [new RequestsGetTool(headers), new RequestsPostTool(headers)];\n }\n}\n\n/**\n * Extends the `RequestsToolkit` class and adds a dynamic tool for\n * exploring JSON data. It creates a JSON agent using the `JsonToolkit`\n * and the provided language model, and adds the JSON explorer tool to the\n * toolkit.\n * @example\n * ```typescript\n * const toolkit = new OpenApiToolkit(\n * new JsonSpec({\n * }),\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * {\n * \"Content-Type\": \"application/json\",\n * Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n * },\n * );\n *\n * const result = await toolkit.invoke({\n * input:\n * \"Make a POST request to openai /completions. The prompt should be 'tell me a joke.'\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class OpenApiToolkit extends RequestsToolkit {\n constructor(\n jsonSpec: JsonSpec,\n llm: BaseLanguageModelInterface,\n headers?: Headers\n ) {\n super(headers);\n const jsonAgent = createJsonAgent(llm, new JsonToolkit(jsonSpec));\n this.tools = [\n ...this.tools,\n new DynamicTool({\n name: \"json_explorer\",\n func: async (input: string) => {\n const result = await jsonAgent.call({ input });\n return result.output as string;\n },\n description: JSON_EXPLORER_DESCRIPTION,\n }),\n ];\n }\n}\n\n/**\n * Creates an OpenAPI agent using a language model, an OpenAPI toolkit,\n * and optional prompt arguments. It creates a prompt for the agent using\n * the OpenAPI tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the OpenAPI tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model to use.\n * @param openApiToolkit The OpenAPI toolkit to use.\n * @param args Optional arguments for creating the prompt.\n * @returns An AgentExecutor for executing the agent with the tools.\n *\n * @security **Security Notice** This agent provides access to external APIs.\n * Use with caution as this agent can make API calls with arbitrary headers.\n * Exposing this agent to users could lead to security vulnerabilities. Consider\n * limiting access to what endpoints it can hit, what actions can be taken, and\n * more.\n *\n * @link See https://js.langchain.com/docs/security for more information.\n */\nexport function createOpenApiAgent(\n llm: BaseLanguageModelInterface,\n openApiToolkit: OpenApiToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = OPENAPI_PREFIX,\n suffix = OPENAPI_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n\n const { tools } = openApiToolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({\n prompt,\n llm,\n });\n const toolNames = tools.map((tool) => tool.name);\n const agent = new ZeroShotAgent({ llmChain: chain, allowedTools: toolNames });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,IAAa,kBAAb,cAAqC,YAAY;CAC/C;CAEA,YAAY,SAAmB;EAC7B,MAAM;EACN,KAAK,QAAQ,CAAC,IAAI,gBAAgB,OAAO,GAAG,IAAI,iBAAiB,OAAO,CAAC;CAC3E;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,iBAAb,cAAoC,gBAAgB;CAClD,YACE,UACA,KACA,SACA;EACA,MAAM,OAAO;EACb,MAAM,YAAY,gBAAgB,KAAK,IAAI,YAAY,QAAQ,CAAC;EAChE,KAAK,QAAQ,CACX,GAAG,KAAK,OACR,IAAI,YAAY;GACd,MAAM;GACN,MAAM,OAAO,UAAkB;IAE7B,QAAO,MADc,UAAU,KAAK,EAAE,MAAM,CAAC,EAAA,CAC/B;GAChB;GACA,aAAa;EACf,CAAC,CACH;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBACd,KACA,gBACA,MACA;CACA,MAAM,EACJ,SAAS,gBACT,SAAS,gBACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CAEb,MAAM,EAAE,UAAU;CAClB,MAAM,SAAS,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,SAAS;EACzB;EACA;CACF,CAAC;CACD,MAAM,YAAY,MAAM,KAAK,SAAS,KAAK,IAAI;CAC/C,MAAM,QAAQ,IAAI,cAAc;EAAE,UAAU;EAAO,cAAc;CAAU,CAAC;CAC5E,OAAO,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -40,15 +40,17 @@ function createSqlAgent(llm, toolkit, args) {
|
|
|
40
40
|
dialect: toolkit.dialect,
|
|
41
41
|
top_k: topK
|
|
42
42
|
});
|
|
43
|
+
const prompt = require_index.ZeroShotAgent.createPrompt(tools, {
|
|
44
|
+
prefix: formattedPrefix,
|
|
45
|
+
suffix,
|
|
46
|
+
inputVariables
|
|
47
|
+
});
|
|
48
|
+
const chain = new require_llm_chain.LLMChain({
|
|
49
|
+
prompt,
|
|
50
|
+
llm
|
|
51
|
+
});
|
|
43
52
|
const agent = new require_index.ZeroShotAgent({
|
|
44
|
-
llmChain:
|
|
45
|
-
prompt: require_index.ZeroShotAgent.createPrompt(tools, {
|
|
46
|
-
prefix: formattedPrefix,
|
|
47
|
-
suffix,
|
|
48
|
-
inputVariables
|
|
49
|
-
}),
|
|
50
|
-
llm
|
|
51
|
-
}),
|
|
53
|
+
llmChain: chain,
|
|
52
54
|
allowedTools: tools.map((t) => t.name)
|
|
53
55
|
});
|
|
54
56
|
return require_executor.AgentExecutor.fromAgentAndTools({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.cjs","names":["BaseToolkit","QuerySqlTool","InfoSqlTool","ListTablesSqlTool","QueryCheckerTool","SQL_PREFIX","SQL_SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/sql/sql.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { renderTemplate } from \"@langchain/core/prompts\";\nimport {\n InfoSqlTool,\n ListTablesSqlTool,\n QueryCheckerTool,\n QuerySqlTool,\n} from \"../../../tools/sql.js\";\nimport { SQL_PREFIX, SQL_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotAgent, ZeroShotCreatePromptArgs } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport { SqlDatabase } from \"../../../sql_db.js\";\n\n/**\n * Interface that extends ZeroShotCreatePromptArgs and adds an optional\n * topK parameter for specifying the number of results to return.\n */\nexport interface SqlCreatePromptArgs extends ZeroShotCreatePromptArgs {\n /** Number of results to return. */\n topK?: number;\n}\n\n/**\n * Class that represents a toolkit for working with SQL databases. It\n * initializes SQL tools based on the provided SQL database.\n * @example\n * ```typescript\n * const model = new ChatOpenAI({ model: \"gpt-4o-mini\" });\n * const toolkit = new SqlToolkit(sqlDb, model);\n * const executor = createSqlAgent(model, toolkit);\n * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class SqlToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n db: SqlDatabase;\n\n dialect = \"sqlite\";\n\n constructor(db: SqlDatabase, llm: BaseLanguageModelInterface) {\n super();\n this.db = db;\n this.tools = [\n new QuerySqlTool(db),\n new InfoSqlTool(db),\n new ListTablesSqlTool(db),\n new QueryCheckerTool({ llm }),\n ];\n }\n}\n\nexport function createSqlAgent(\n llm: BaseLanguageModelInterface,\n toolkit: SqlToolkit,\n args?: SqlCreatePromptArgs\n) {\n const {\n prefix = SQL_PREFIX,\n suffix = SQL_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n topK = 10,\n } = args ?? {};\n const { tools } = toolkit;\n const formattedPrefix = renderTemplate(prefix, \"f-string\", {\n dialect: toolkit.dialect,\n top_k: topK,\n });\n\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix: formattedPrefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,aAAb,cAAgCA,sBAAAA,YAAY;CAC1C;CAEA;CAEA,UAAU;CAEV,YAAY,IAAiB,KAAiC;EAC5D,MAAM;EACN,KAAK,KAAK;EACV,KAAK,QAAQ;GACX,IAAIC,kBAAAA,aAAa,EAAE;GACnB,IAAIC,kBAAAA,YAAY,EAAE;GAClB,IAAIC,kBAAAA,kBAAkB,EAAE;GACxB,IAAIC,kBAAAA,iBAAiB,EAAE,IAAI,CAAC;EAC9B;CACF;AACF;AAEA,SAAgB,eACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,YACT,SAASC,eAAAA,YACT,iBAAiB,CAAC,SAAS,kBAAkB,GAC7C,OAAO,OACL,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,mBAAA,
|
|
1
|
+
{"version":3,"file":"sql.cjs","names":["BaseToolkit","QuerySqlTool","InfoSqlTool","ListTablesSqlTool","QueryCheckerTool","SQL_PREFIX","SQL_SUFFIX","renderTemplate","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/sql/sql.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { renderTemplate } from \"@langchain/core/prompts\";\nimport {\n InfoSqlTool,\n ListTablesSqlTool,\n QueryCheckerTool,\n QuerySqlTool,\n} from \"../../../tools/sql.js\";\nimport { SQL_PREFIX, SQL_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotAgent, ZeroShotCreatePromptArgs } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport { SqlDatabase } from \"../../../sql_db.js\";\n\n/**\n * Interface that extends ZeroShotCreatePromptArgs and adds an optional\n * topK parameter for specifying the number of results to return.\n */\nexport interface SqlCreatePromptArgs extends ZeroShotCreatePromptArgs {\n /** Number of results to return. */\n topK?: number;\n}\n\n/**\n * Class that represents a toolkit for working with SQL databases. It\n * initializes SQL tools based on the provided SQL database.\n * @example\n * ```typescript\n * const model = new ChatOpenAI({ model: \"gpt-4o-mini\" });\n * const toolkit = new SqlToolkit(sqlDb, model);\n * const executor = createSqlAgent(model, toolkit);\n * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class SqlToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n db: SqlDatabase;\n\n dialect = \"sqlite\";\n\n constructor(db: SqlDatabase, llm: BaseLanguageModelInterface) {\n super();\n this.db = db;\n this.tools = [\n new QuerySqlTool(db),\n new InfoSqlTool(db),\n new ListTablesSqlTool(db),\n new QueryCheckerTool({ llm }),\n ];\n }\n}\n\nexport function createSqlAgent(\n llm: BaseLanguageModelInterface,\n toolkit: SqlToolkit,\n args?: SqlCreatePromptArgs\n) {\n const {\n prefix = SQL_PREFIX,\n suffix = SQL_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n topK = 10,\n } = args ?? {};\n const { tools } = toolkit;\n const formattedPrefix = renderTemplate(prefix, \"f-string\", {\n dialect: toolkit.dialect,\n top_k: topK,\n });\n\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix: formattedPrefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,aAAb,cAAgCA,sBAAAA,YAAY;CAC1C;CAEA;CAEA,UAAU;CAEV,YAAY,IAAiB,KAAiC;EAC5D,MAAM;EACN,KAAK,KAAK;EACV,KAAK,QAAQ;GACX,IAAIC,kBAAAA,aAAa,EAAE;GACnB,IAAIC,kBAAAA,YAAY,EAAE;GAClB,IAAIC,kBAAAA,kBAAkB,EAAE;GACxB,IAAIC,kBAAAA,iBAAiB,EAAE,IAAI,CAAC;EAC9B;CACF;AACF;AAEA,SAAgB,eACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,YACT,SAASC,eAAAA,YACT,iBAAiB,CAAC,SAAS,kBAAkB,GAC7C,OAAO,OACL,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,mBAAA,GAAkBC,wBAAAA,eAAAA,CAAe,QAAQ,YAAY;EACzD,SAAS,QAAQ;EACjB,OAAO;CACT,CAAC;CAED,MAAM,SAASC,cAAAA,cAAc,aAAa,OAAO;EAC/C,QAAQ;EACR;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAIC,kBAAAA,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAID,cAAAA,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAOE,iBAAAA,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -40,15 +40,17 @@ function createSqlAgent(llm, toolkit, args) {
|
|
|
40
40
|
dialect: toolkit.dialect,
|
|
41
41
|
top_k: topK
|
|
42
42
|
});
|
|
43
|
+
const prompt = ZeroShotAgent.createPrompt(tools, {
|
|
44
|
+
prefix: formattedPrefix,
|
|
45
|
+
suffix,
|
|
46
|
+
inputVariables
|
|
47
|
+
});
|
|
48
|
+
const chain = new LLMChain({
|
|
49
|
+
prompt,
|
|
50
|
+
llm
|
|
51
|
+
});
|
|
43
52
|
const agent = new ZeroShotAgent({
|
|
44
|
-
llmChain:
|
|
45
|
-
prompt: ZeroShotAgent.createPrompt(tools, {
|
|
46
|
-
prefix: formattedPrefix,
|
|
47
|
-
suffix,
|
|
48
|
-
inputVariables
|
|
49
|
-
}),
|
|
50
|
-
llm
|
|
51
|
-
}),
|
|
53
|
+
llmChain: chain,
|
|
52
54
|
allowedTools: tools.map((t) => t.name)
|
|
53
55
|
});
|
|
54
56
|
return AgentExecutor.fromAgentAndTools({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.js","names":[],"sources":["../../../../src/agents/toolkits/sql/sql.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { renderTemplate } from \"@langchain/core/prompts\";\nimport {\n InfoSqlTool,\n ListTablesSqlTool,\n QueryCheckerTool,\n QuerySqlTool,\n} from \"../../../tools/sql.js\";\nimport { SQL_PREFIX, SQL_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotAgent, ZeroShotCreatePromptArgs } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport { SqlDatabase } from \"../../../sql_db.js\";\n\n/**\n * Interface that extends ZeroShotCreatePromptArgs and adds an optional\n * topK parameter for specifying the number of results to return.\n */\nexport interface SqlCreatePromptArgs extends ZeroShotCreatePromptArgs {\n /** Number of results to return. */\n topK?: number;\n}\n\n/**\n * Class that represents a toolkit for working with SQL databases. It\n * initializes SQL tools based on the provided SQL database.\n * @example\n * ```typescript\n * const model = new ChatOpenAI({ model: \"gpt-4o-mini\" });\n * const toolkit = new SqlToolkit(sqlDb, model);\n * const executor = createSqlAgent(model, toolkit);\n * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class SqlToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n db: SqlDatabase;\n\n dialect = \"sqlite\";\n\n constructor(db: SqlDatabase, llm: BaseLanguageModelInterface) {\n super();\n this.db = db;\n this.tools = [\n new QuerySqlTool(db),\n new InfoSqlTool(db),\n new ListTablesSqlTool(db),\n new QueryCheckerTool({ llm }),\n ];\n }\n}\n\nexport function createSqlAgent(\n llm: BaseLanguageModelInterface,\n toolkit: SqlToolkit,\n args?: SqlCreatePromptArgs\n) {\n const {\n prefix = SQL_PREFIX,\n suffix = SQL_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n topK = 10,\n } = args ?? {};\n const { tools } = toolkit;\n const formattedPrefix = renderTemplate(prefix, \"f-string\", {\n dialect: toolkit.dialect,\n top_k: topK,\n });\n\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix: formattedPrefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,aAAb,cAAgC,YAAY;CAC1C;CAEA;CAEA,UAAU;CAEV,YAAY,IAAiB,KAAiC;EAC5D,MAAM;EACN,KAAK,KAAK;EACV,KAAK,QAAQ;GACX,IAAI,aAAa,EAAE;GACnB,IAAI,YAAY,EAAE;GAClB,IAAI,kBAAkB,EAAE;GACxB,IAAI,iBAAiB,EAAE,IAAI,CAAC;EAC9B;CACF;AACF;AAEA,SAAgB,eACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,YACT,SAAS,YACT,iBAAiB,CAAC,SAAS,kBAAkB,GAC7C,OAAO,OACL,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,kBAAkB,eAAe,QAAQ,YAAY;EACzD,SAAS,QAAQ;EACjB,OAAO;CACT,CAAC;
|
|
1
|
+
{"version":3,"file":"sql.js","names":[],"sources":["../../../../src/agents/toolkits/sql/sql.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { renderTemplate } from \"@langchain/core/prompts\";\nimport {\n InfoSqlTool,\n ListTablesSqlTool,\n QueryCheckerTool,\n QuerySqlTool,\n} from \"../../../tools/sql.js\";\nimport { SQL_PREFIX, SQL_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotAgent, ZeroShotCreatePromptArgs } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\nimport { SqlDatabase } from \"../../../sql_db.js\";\n\n/**\n * Interface that extends ZeroShotCreatePromptArgs and adds an optional\n * topK parameter for specifying the number of results to return.\n */\nexport interface SqlCreatePromptArgs extends ZeroShotCreatePromptArgs {\n /** Number of results to return. */\n topK?: number;\n}\n\n/**\n * Class that represents a toolkit for working with SQL databases. It\n * initializes SQL tools based on the provided SQL database.\n * @example\n * ```typescript\n * const model = new ChatOpenAI({ model: \"gpt-4o-mini\" });\n * const toolkit = new SqlToolkit(sqlDb, model);\n * const executor = createSqlAgent(model, toolkit);\n * const result = await executor.invoke({ input: 'List the total sales per country. Which country's customers spent the most?' });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class SqlToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n db: SqlDatabase;\n\n dialect = \"sqlite\";\n\n constructor(db: SqlDatabase, llm: BaseLanguageModelInterface) {\n super();\n this.db = db;\n this.tools = [\n new QuerySqlTool(db),\n new InfoSqlTool(db),\n new ListTablesSqlTool(db),\n new QueryCheckerTool({ llm }),\n ];\n }\n}\n\nexport function createSqlAgent(\n llm: BaseLanguageModelInterface,\n toolkit: SqlToolkit,\n args?: SqlCreatePromptArgs\n) {\n const {\n prefix = SQL_PREFIX,\n suffix = SQL_SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n topK = 10,\n } = args ?? {};\n const { tools } = toolkit;\n const formattedPrefix = renderTemplate(prefix, \"f-string\", {\n dialect: toolkit.dialect,\n top_k: topK,\n });\n\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix: formattedPrefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,aAAb,cAAgC,YAAY;CAC1C;CAEA;CAEA,UAAU;CAEV,YAAY,IAAiB,KAAiC;EAC5D,MAAM;EACN,KAAK,KAAK;EACV,KAAK,QAAQ;GACX,IAAI,aAAa,EAAE;GACnB,IAAI,YAAY,EAAE;GAClB,IAAI,kBAAkB,EAAE;GACxB,IAAI,iBAAiB,EAAE,IAAI,CAAC;EAC9B;CACF;AACF;AAEA,SAAgB,eACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,YACT,SAAS,YACT,iBAAiB,CAAC,SAAS,kBAAkB,GAC7C,OAAO,OACL,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,kBAAkB,eAAe,QAAQ,YAAY;EACzD,SAAS,QAAQ;EACjB,OAAO;CACT,CAAC;CAED,MAAM,SAAS,cAAc,aAAa,OAAO;EAC/C,QAAQ;EACR;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAI,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAO,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -65,15 +65,17 @@ var VectorStoreRouterToolkit = class extends _langchain_core_tools.BaseToolkit {
|
|
|
65
65
|
function createVectorStoreAgent(llm, toolkit, args) {
|
|
66
66
|
const { prefix = require_prompt$1.VECTOR_PREFIX, suffix = require_prompt.SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
67
67
|
const { tools } = toolkit;
|
|
68
|
+
const prompt = require_index.ZeroShotAgent.createPrompt(tools, {
|
|
69
|
+
prefix,
|
|
70
|
+
suffix,
|
|
71
|
+
inputVariables
|
|
72
|
+
});
|
|
73
|
+
const chain = new require_llm_chain.LLMChain({
|
|
74
|
+
prompt,
|
|
75
|
+
llm
|
|
76
|
+
});
|
|
68
77
|
const agent = new require_index.ZeroShotAgent({
|
|
69
|
-
llmChain:
|
|
70
|
-
prompt: require_index.ZeroShotAgent.createPrompt(tools, {
|
|
71
|
-
prefix,
|
|
72
|
-
suffix,
|
|
73
|
-
inputVariables
|
|
74
|
-
}),
|
|
75
|
-
llm
|
|
76
|
-
}),
|
|
78
|
+
llmChain: chain,
|
|
77
79
|
allowedTools: tools.map((t) => t.name)
|
|
78
80
|
});
|
|
79
81
|
return require_executor.AgentExecutor.fromAgentAndTools({
|
|
@@ -85,15 +87,17 @@ function createVectorStoreAgent(llm, toolkit, args) {
|
|
|
85
87
|
function createVectorStoreRouterAgent(llm, toolkit, args) {
|
|
86
88
|
const { prefix = require_prompt$1.VECTOR_ROUTER_PREFIX, suffix = require_prompt.SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
87
89
|
const { tools } = toolkit;
|
|
90
|
+
const prompt = require_index.ZeroShotAgent.createPrompt(tools, {
|
|
91
|
+
prefix,
|
|
92
|
+
suffix,
|
|
93
|
+
inputVariables
|
|
94
|
+
});
|
|
95
|
+
const chain = new require_llm_chain.LLMChain({
|
|
96
|
+
prompt,
|
|
97
|
+
llm
|
|
98
|
+
});
|
|
88
99
|
const agent = new require_index.ZeroShotAgent({
|
|
89
|
-
llmChain:
|
|
90
|
-
prompt: require_index.ZeroShotAgent.createPrompt(tools, {
|
|
91
|
-
prefix,
|
|
92
|
-
suffix,
|
|
93
|
-
inputVariables
|
|
94
|
-
}),
|
|
95
|
-
llm
|
|
96
|
-
}),
|
|
100
|
+
llmChain: chain,
|
|
97
101
|
allowedTools: tools.map((t) => t.name)
|
|
98
102
|
});
|
|
99
103
|
return require_executor.AgentExecutor.fromAgentAndTools({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectorstore.cjs","names":["BaseToolkit","VectorStoreQATool","VECTOR_PREFIX","SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor","VECTOR_ROUTER_PREFIX"],"sources":["../../../../src/agents/toolkits/vectorstore/vectorstore.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { VectorStoreInterface } from \"@langchain/core/vectorstores\";\nimport { ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { VectorStoreQATool } from \"../../../tools/vectorstore.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { VECTOR_PREFIX, VECTOR_ROUTER_PREFIX } from \"./prompt.js\";\nimport { SUFFIX } from \"../../mrkl/prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Interface that defines the information about a vector store, including\n * the vector store itself, its name, and description.\n */\nexport interface VectorStoreInfo {\n vectorStore: VectorStoreInterface;\n name: string;\n description: string;\n}\n\n/**\n * Class representing a toolkit for working with a single vector store. It\n * initializes the vector store QA tool based on the provided vector store\n * information and language model.\n * @example\n * ```typescript\n * const toolkit = new VectorStoreToolkit(\n * {\n * name: \"state_of_union_address\",\n * description: \"the most recent state of the Union address\",\n * vectorStore: new HNSWLib(),\n * },\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * );\n * const result = await toolkit.invoke({\n * input:\n * \"What did biden say about Ketanji Brown Jackson in the state of the union address?\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class VectorStoreToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfo: VectorStoreInfo,\n llm: BaseLanguageModelInterface\n ) {\n super();\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n this.llm = llm;\n this.tools = [\n new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n }),\n ];\n }\n}\n\n/**\n * Class representing a toolkit for working with multiple vector stores.\n * It initializes multiple vector store QA tools based on the provided\n * vector store information and language model.\n */\nexport class VectorStoreRouterToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n vectorStoreInfos: VectorStoreInfo[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfos: VectorStoreInfo[],\n llm: BaseLanguageModelInterface\n ) {\n super();\n this.llm = llm;\n this.vectorStoreInfos = vectorStoreInfos;\n this.tools = vectorStoreInfos.map((vectorStoreInfo) => {\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n return new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n });\n });\n }\n}\n\nexport function createVectorStoreAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n\nexport function createVectorStoreRouterAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreRouterToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_ROUTER_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,qBAAb,cAAwCA,sBAAAA,YAAY;CAClD;CAEA;CAEA,YACE,iBACA,KACA;EACA,MAAM;EACN,MAAM,cAAcC,oBAAAA,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;EACA,KAAK,MAAM;EACX,KAAK,QAAQ,CACX,IAAIA,oBAAAA,kBAAkB,gBAAgB,MAAM,aAAa;GACvD,aAAa,gBAAgB;GAC7B,KAAK,KAAK;EACZ,CAAC,CACH;CACF;AACF;;;;;;AAOA,IAAa,2BAAb,cAA8CD,sBAAAA,YAAY;CACxD;CAEA;CAEA;CAEA,YACE,kBACA,KACA;EACA,MAAM;EACN,KAAK,MAAM;EACX,KAAK,mBAAmB;EACxB,KAAK,QAAQ,iBAAiB,KAAK,oBAAoB;GACrD,MAAM,cAAcC,oBAAAA,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;GACA,OAAO,IAAIA,oBAAAA,kBAAkB,gBAAgB,MAAM,aAAa;IAC9D,aAAa,gBAAgB;IAC7B,KAAK,KAAK;GACZ,CAAC;EACH,CAAC;CACH;AACF;AAEA,SAAgB,uBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,iBAAAA,eACT,SAASC,eAAAA,QACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"vectorstore.cjs","names":["BaseToolkit","VectorStoreQATool","VECTOR_PREFIX","SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor","VECTOR_ROUTER_PREFIX"],"sources":["../../../../src/agents/toolkits/vectorstore/vectorstore.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { VectorStoreInterface } from \"@langchain/core/vectorstores\";\nimport { ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { VectorStoreQATool } from \"../../../tools/vectorstore.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { VECTOR_PREFIX, VECTOR_ROUTER_PREFIX } from \"./prompt.js\";\nimport { SUFFIX } from \"../../mrkl/prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Interface that defines the information about a vector store, including\n * the vector store itself, its name, and description.\n */\nexport interface VectorStoreInfo {\n vectorStore: VectorStoreInterface;\n name: string;\n description: string;\n}\n\n/**\n * Class representing a toolkit for working with a single vector store. It\n * initializes the vector store QA tool based on the provided vector store\n * information and language model.\n * @example\n * ```typescript\n * const toolkit = new VectorStoreToolkit(\n * {\n * name: \"state_of_union_address\",\n * description: \"the most recent state of the Union address\",\n * vectorStore: new HNSWLib(),\n * },\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * );\n * const result = await toolkit.invoke({\n * input:\n * \"What did biden say about Ketanji Brown Jackson in the state of the union address?\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class VectorStoreToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfo: VectorStoreInfo,\n llm: BaseLanguageModelInterface\n ) {\n super();\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n this.llm = llm;\n this.tools = [\n new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n }),\n ];\n }\n}\n\n/**\n * Class representing a toolkit for working with multiple vector stores.\n * It initializes multiple vector store QA tools based on the provided\n * vector store information and language model.\n */\nexport class VectorStoreRouterToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n vectorStoreInfos: VectorStoreInfo[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfos: VectorStoreInfo[],\n llm: BaseLanguageModelInterface\n ) {\n super();\n this.llm = llm;\n this.vectorStoreInfos = vectorStoreInfos;\n this.tools = vectorStoreInfos.map((vectorStoreInfo) => {\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n return new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n });\n });\n }\n}\n\nexport function createVectorStoreAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n\nexport function createVectorStoreRouterAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreRouterToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_ROUTER_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,qBAAb,cAAwCA,sBAAAA,YAAY;CAClD;CAEA;CAEA,YACE,iBACA,KACA;EACA,MAAM;EACN,MAAM,cAAcC,oBAAAA,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;EACA,KAAK,MAAM;EACX,KAAK,QAAQ,CACX,IAAIA,oBAAAA,kBAAkB,gBAAgB,MAAM,aAAa;GACvD,aAAa,gBAAgB;GAC7B,KAAK,KAAK;EACZ,CAAC,CACH;CACF;AACF;;;;;;AAOA,IAAa,2BAAb,cAA8CD,sBAAAA,YAAY;CACxD;CAEA;CAEA;CAEA,YACE,kBACA,KACA;EACA,MAAM;EACN,KAAK,MAAM;EACX,KAAK,mBAAmB;EACxB,KAAK,QAAQ,iBAAiB,KAAK,oBAAoB;GACrD,MAAM,cAAcC,oBAAAA,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;GACA,OAAO,IAAIA,oBAAAA,kBAAkB,gBAAgB,MAAM,aAAa;IAC9D,aAAa,gBAAgB;IAC7B,KAAK,KAAK;GACZ,CAAC;EACH,CAAC;CACH;AACF;AAEA,SAAgB,uBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,iBAAAA,eACT,SAASC,eAAAA,QACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,SAASC,cAAAA,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAIC,kBAAAA,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAID,cAAAA,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAOE,iBAAAA,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH;AAEA,SAAgB,6BACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,iBAAAA,sBACT,SAASJ,eAAAA,QACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,SAASC,cAAAA,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAIC,kBAAAA,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAID,cAAAA,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAOE,iBAAAA,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -65,15 +65,17 @@ var VectorStoreRouterToolkit = class extends BaseToolkit {
|
|
|
65
65
|
function createVectorStoreAgent(llm, toolkit, args) {
|
|
66
66
|
const { prefix = VECTOR_PREFIX, suffix = SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
67
67
|
const { tools } = toolkit;
|
|
68
|
+
const prompt = ZeroShotAgent.createPrompt(tools, {
|
|
69
|
+
prefix,
|
|
70
|
+
suffix,
|
|
71
|
+
inputVariables
|
|
72
|
+
});
|
|
73
|
+
const chain = new LLMChain({
|
|
74
|
+
prompt,
|
|
75
|
+
llm
|
|
76
|
+
});
|
|
68
77
|
const agent = new ZeroShotAgent({
|
|
69
|
-
llmChain:
|
|
70
|
-
prompt: ZeroShotAgent.createPrompt(tools, {
|
|
71
|
-
prefix,
|
|
72
|
-
suffix,
|
|
73
|
-
inputVariables
|
|
74
|
-
}),
|
|
75
|
-
llm
|
|
76
|
-
}),
|
|
78
|
+
llmChain: chain,
|
|
77
79
|
allowedTools: tools.map((t) => t.name)
|
|
78
80
|
});
|
|
79
81
|
return AgentExecutor.fromAgentAndTools({
|
|
@@ -85,15 +87,17 @@ function createVectorStoreAgent(llm, toolkit, args) {
|
|
|
85
87
|
function createVectorStoreRouterAgent(llm, toolkit, args) {
|
|
86
88
|
const { prefix = VECTOR_ROUTER_PREFIX, suffix = SUFFIX, inputVariables = ["input", "agent_scratchpad"] } = args ?? {};
|
|
87
89
|
const { tools } = toolkit;
|
|
90
|
+
const prompt = ZeroShotAgent.createPrompt(tools, {
|
|
91
|
+
prefix,
|
|
92
|
+
suffix,
|
|
93
|
+
inputVariables
|
|
94
|
+
});
|
|
95
|
+
const chain = new LLMChain({
|
|
96
|
+
prompt,
|
|
97
|
+
llm
|
|
98
|
+
});
|
|
88
99
|
const agent = new ZeroShotAgent({
|
|
89
|
-
llmChain:
|
|
90
|
-
prompt: ZeroShotAgent.createPrompt(tools, {
|
|
91
|
-
prefix,
|
|
92
|
-
suffix,
|
|
93
|
-
inputVariables
|
|
94
|
-
}),
|
|
95
|
-
llm
|
|
96
|
-
}),
|
|
100
|
+
llmChain: chain,
|
|
97
101
|
allowedTools: tools.map((t) => t.name)
|
|
98
102
|
});
|
|
99
103
|
return AgentExecutor.fromAgentAndTools({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectorstore.js","names":[],"sources":["../../../../src/agents/toolkits/vectorstore/vectorstore.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { VectorStoreInterface } from \"@langchain/core/vectorstores\";\nimport { ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { VectorStoreQATool } from \"../../../tools/vectorstore.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { VECTOR_PREFIX, VECTOR_ROUTER_PREFIX } from \"./prompt.js\";\nimport { SUFFIX } from \"../../mrkl/prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Interface that defines the information about a vector store, including\n * the vector store itself, its name, and description.\n */\nexport interface VectorStoreInfo {\n vectorStore: VectorStoreInterface;\n name: string;\n description: string;\n}\n\n/**\n * Class representing a toolkit for working with a single vector store. It\n * initializes the vector store QA tool based on the provided vector store\n * information and language model.\n * @example\n * ```typescript\n * const toolkit = new VectorStoreToolkit(\n * {\n * name: \"state_of_union_address\",\n * description: \"the most recent state of the Union address\",\n * vectorStore: new HNSWLib(),\n * },\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * );\n * const result = await toolkit.invoke({\n * input:\n * \"What did biden say about Ketanji Brown Jackson in the state of the union address?\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class VectorStoreToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfo: VectorStoreInfo,\n llm: BaseLanguageModelInterface\n ) {\n super();\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n this.llm = llm;\n this.tools = [\n new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n }),\n ];\n }\n}\n\n/**\n * Class representing a toolkit for working with multiple vector stores.\n * It initializes multiple vector store QA tools based on the provided\n * vector store information and language model.\n */\nexport class VectorStoreRouterToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n vectorStoreInfos: VectorStoreInfo[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfos: VectorStoreInfo[],\n llm: BaseLanguageModelInterface\n ) {\n super();\n this.llm = llm;\n this.vectorStoreInfos = vectorStoreInfos;\n this.tools = vectorStoreInfos.map((vectorStoreInfo) => {\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n return new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n });\n });\n }\n}\n\nexport function createVectorStoreAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n\nexport function createVectorStoreRouterAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreRouterToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_ROUTER_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,qBAAb,cAAwC,YAAY;CAClD;CAEA;CAEA,YACE,iBACA,KACA;EACA,MAAM;EACN,MAAM,cAAc,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;EACA,KAAK,MAAM;EACX,KAAK,QAAQ,CACX,IAAI,kBAAkB,gBAAgB,MAAM,aAAa;GACvD,aAAa,gBAAgB;GAC7B,KAAK,KAAK;EACZ,CAAC,CACH;CACF;AACF;;;;;;AAOA,IAAa,2BAAb,cAA8C,YAAY;CACxD;CAEA;CAEA;CAEA,YACE,kBACA,KACA;EACA,MAAM;EACN,KAAK,MAAM;EACX,KAAK,mBAAmB;EACxB,KAAK,QAAQ,iBAAiB,KAAK,oBAAoB;GACrD,MAAM,cAAc,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;GACA,OAAO,IAAI,kBAAkB,gBAAgB,MAAM,aAAa;IAC9D,aAAa,gBAAgB;IAC7B,KAAK,KAAK;GACZ,CAAC;EACH,CAAC;CACH;AACF;AAEA,SAAgB,uBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,eACT,SAAS,QACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"vectorstore.js","names":[],"sources":["../../../../src/agents/toolkits/vectorstore/vectorstore.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport type { VectorStoreInterface } from \"@langchain/core/vectorstores\";\nimport { ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport { VectorStoreQATool } from \"../../../tools/vectorstore.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { VECTOR_PREFIX, VECTOR_ROUTER_PREFIX } from \"./prompt.js\";\nimport { SUFFIX } from \"../../mrkl/prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Interface that defines the information about a vector store, including\n * the vector store itself, its name, and description.\n */\nexport interface VectorStoreInfo {\n vectorStore: VectorStoreInterface;\n name: string;\n description: string;\n}\n\n/**\n * Class representing a toolkit for working with a single vector store. It\n * initializes the vector store QA tool based on the provided vector store\n * information and language model.\n * @example\n * ```typescript\n * const toolkit = new VectorStoreToolkit(\n * {\n * name: \"state_of_union_address\",\n * description: \"the most recent state of the Union address\",\n * vectorStore: new HNSWLib(),\n * },\n * new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * );\n * const result = await toolkit.invoke({\n * input:\n * \"What did biden say about Ketanji Brown Jackson in the state of the union address?\",\n * });\n * console.log(`Got output ${result.output}`);\n * ```\n */\nexport class VectorStoreToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfo: VectorStoreInfo,\n llm: BaseLanguageModelInterface\n ) {\n super();\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n this.llm = llm;\n this.tools = [\n new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n }),\n ];\n }\n}\n\n/**\n * Class representing a toolkit for working with multiple vector stores.\n * It initializes multiple vector store QA tools based on the provided\n * vector store information and language model.\n */\nexport class VectorStoreRouterToolkit extends BaseToolkit {\n tools: ToolInterface[];\n\n vectorStoreInfos: VectorStoreInfo[];\n\n llm: BaseLanguageModelInterface;\n\n constructor(\n vectorStoreInfos: VectorStoreInfo[],\n llm: BaseLanguageModelInterface\n ) {\n super();\n this.llm = llm;\n this.vectorStoreInfos = vectorStoreInfos;\n this.tools = vectorStoreInfos.map((vectorStoreInfo) => {\n const description = VectorStoreQATool.getDescription(\n vectorStoreInfo.name,\n vectorStoreInfo.description\n );\n return new VectorStoreQATool(vectorStoreInfo.name, description, {\n vectorStore: vectorStoreInfo.vectorStore,\n llm: this.llm,\n });\n });\n }\n}\n\nexport function createVectorStoreAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n\nexport function createVectorStoreRouterAgent(\n llm: BaseLanguageModelInterface,\n toolkit: VectorStoreRouterToolkit,\n args?: ZeroShotCreatePromptArgs\n) {\n const {\n prefix = VECTOR_ROUTER_PREFIX,\n suffix = SUFFIX,\n inputVariables = [\"input\", \"agent_scratchpad\"],\n } = args ?? {};\n const { tools } = toolkit;\n const prompt = ZeroShotAgent.createPrompt(tools, {\n prefix,\n suffix,\n inputVariables,\n });\n const chain = new LLMChain({ prompt, llm });\n const agent = new ZeroShotAgent({\n llmChain: chain,\n allowedTools: tools.map((t) => t.name),\n });\n return AgentExecutor.fromAgentAndTools({\n agent,\n tools,\n returnIntermediateSteps: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,qBAAb,cAAwC,YAAY;CAClD;CAEA;CAEA,YACE,iBACA,KACA;EACA,MAAM;EACN,MAAM,cAAc,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;EACA,KAAK,MAAM;EACX,KAAK,QAAQ,CACX,IAAI,kBAAkB,gBAAgB,MAAM,aAAa;GACvD,aAAa,gBAAgB;GAC7B,KAAK,KAAK;EACZ,CAAC,CACH;CACF;AACF;;;;;;AAOA,IAAa,2BAAb,cAA8C,YAAY;CACxD;CAEA;CAEA;CAEA,YACE,kBACA,KACA;EACA,MAAM;EACN,KAAK,MAAM;EACX,KAAK,mBAAmB;EACxB,KAAK,QAAQ,iBAAiB,KAAK,oBAAoB;GACrD,MAAM,cAAc,kBAAkB,eACpC,gBAAgB,MAChB,gBAAgB,WAClB;GACA,OAAO,IAAI,kBAAkB,gBAAgB,MAAM,aAAa;IAC9D,aAAa,gBAAgB;IAC7B,KAAK,KAAK;GACZ,CAAC;EACH,CAAC;CACH;AACF;AAEA,SAAgB,uBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,eACT,SAAS,QACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,SAAS,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAI,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAO,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH;AAEA,SAAgB,6BACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAAS,sBACT,SAAS,QACT,iBAAiB,CAAC,SAAS,kBAAkB,MAC3C,QAAQ,CAAC;CACb,MAAM,EAAE,UAAU;CAClB,MAAM,SAAS,cAAc,aAAa,OAAO;EAC/C;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,SAAS;EAAE;EAAQ;CAAI,CAAC;CAC1C,MAAM,QAAQ,IAAI,cAAc;EAC9B,UAAU;EACV,cAAc,MAAM,KAAK,MAAM,EAAE,IAAI;CACvC,CAAC;CACD,OAAO,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;CAC3B,CAAC;AACH"}
|
|
@@ -66,8 +66,9 @@ var XMLAgent = class XMLAgent extends require_agent.BaseSingleActionAgent {
|
|
|
66
66
|
* @returns An instance of XMLAgent.
|
|
67
67
|
*/
|
|
68
68
|
static fromLLMAndTools(llm, tools, args) {
|
|
69
|
+
const prompt = XMLAgent.createPrompt();
|
|
69
70
|
const chain = new require_llm_chain.LLMChain({
|
|
70
|
-
prompt
|
|
71
|
+
prompt,
|
|
71
72
|
llm,
|
|
72
73
|
callbacks: args?.callbacks
|
|
73
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["BaseSingleActionAgent","XMLAgentOutputParser","ChatPromptTemplate","HumanMessagePromptTemplate","AGENT_INSTRUCTIONS","AIMessagePromptTemplate","LLMChain","renderTextDescription","AgentRunnableSequence","RunnablePassthrough","formatXml"],"sources":["../../../src/agents/xml/index.ts"],"sourcesContent":["import type {\n BaseLanguageModel,\n BaseLanguageModelInterface,\n} from \"@langchain/core/language_models/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport { RunnablePassthrough } from \"@langchain/core/runnables\";\nimport type { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { AgentStep, AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { ChainValues } from \"@langchain/core/utils/types\";\nimport {\n AIMessagePromptTemplate,\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n} from \"@langchain/core/prompts\";\nimport { CallbackManager } from \"@langchain/core/callbacks/manager\";\nimport { LLMChain } from \"../../chains/llm_chain.js\";\nimport {\n AgentArgs,\n AgentRunnableSequence,\n BaseSingleActionAgent,\n} from \"../agent.js\";\nimport { AGENT_INSTRUCTIONS } from \"./prompt.js\";\nimport { XMLAgentOutputParser } from \"./output_parser.js\";\nimport { renderTextDescription } from \"../../tools/render.js\";\nimport { formatXml } from \"../format_scratchpad/xml.js\";\n\n/**\n * Interface for the input to the XMLAgent class.\n */\nexport interface XMLAgentInput {\n tools: ToolInterface[];\n llmChain: LLMChain;\n}\n\n/**\n * Class that represents an agent that uses XML tags.\n */\nexport class XMLAgent extends BaseSingleActionAgent implements XMLAgentInput {\n static lc_name() {\n return \"XMLAgent\";\n }\n\n lc_namespace = [\"langchain\", \"agents\", \"xml\"];\n\n tools: ToolInterface[];\n\n llmChain: LLMChain;\n\n outputParser: XMLAgentOutputParser = new XMLAgentOutputParser();\n\n _agentType() {\n return \"xml\" as const;\n }\n\n constructor(fields: XMLAgentInput) {\n super(fields);\n this.tools = fields.tools;\n this.llmChain = fields.llmChain;\n }\n\n get inputKeys() {\n return [\"input\"];\n }\n\n static createPrompt() {\n return ChatPromptTemplate.fromMessages([\n HumanMessagePromptTemplate.fromTemplate(AGENT_INSTRUCTIONS),\n AIMessagePromptTemplate.fromTemplate(\"{intermediate_steps}\"),\n ]);\n }\n\n /**\n * Plans the next action or finish state of the agent based on the\n * provided steps, inputs, and optional callback manager.\n * @param steps The steps to consider in planning.\n * @param inputs The inputs to consider in planning.\n * @param callbackManager Optional CallbackManager to use in planning.\n * @returns A Promise that resolves to an AgentAction or AgentFinish object representing the planned action or finish state.\n */\n async plan(\n steps: AgentStep[],\n inputs: ChainValues,\n callbackManager?: CallbackManager\n ): Promise<AgentAction | AgentFinish> {\n let log = \"\";\n for (const { action, observation } of steps) {\n log += `<tool>${action.tool}</tool><tool_input>${action.toolInput}</tool_input><observation>${observation}</observation>`;\n }\n let tools = \"\";\n for (const tool of this.tools) {\n tools += `${tool.name}: ${tool.description}\\n`;\n }\n const _inputs = {\n intermediate_steps: log,\n tools,\n question: inputs.input,\n stop: [\"</tool_input>\", \"</final_answer>\"],\n };\n const response = await this.llmChain.call(_inputs, callbackManager);\n return this.outputParser.parse(response[this.llmChain.outputKey]);\n }\n\n /**\n * Creates an XMLAgent from a BaseLanguageModel and a list of tools.\n * @param llm The BaseLanguageModel to use.\n * @param tools The tools to be used by the agent.\n * @param args Optional arguments for creating the agent.\n * @returns An instance of XMLAgent.\n */\n static fromLLMAndTools(\n llm: BaseLanguageModelInterface,\n tools: ToolInterface[],\n args?: XMLAgentInput & Pick<AgentArgs, \"callbacks\">\n ) {\n const prompt = XMLAgent.createPrompt();\n const chain = new LLMChain({\n prompt,\n llm,\n callbacks: args?.callbacks,\n });\n return new XMLAgent({\n llmChain: chain,\n tools,\n });\n }\n}\n\n/**\n * Params used by the createXmlAgent function.\n */\nexport type CreateXmlAgentParams = {\n /** LLM to use for the agent. */\n llm: BaseLanguageModelInterface;\n /** Tools this agent has access to. */\n tools: ToolInterface[];\n /**\n * The prompt to use. Must have input keys for\n * `tools` and `agent_scratchpad`.\n */\n prompt: BasePromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n\n/**\n * Create an agent that uses XML to format its logic.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n *\n * @example\n * ```typescript\n * import { AgentExecutor, createXmlAgent } from \"langchain/agents\";\n * import { pull } from \"langchain/hub\";\n * import type { PromptTemplate } from \"@langchain/core/prompts\";\n *\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * // Get the prompt to use - you can modify this!\n * // If you want to see the prompt in full, you can at:\n * // https://smith.langchain.com/hub/hwchase17/xml-agent-convo\n * const prompt = await pull<PromptTemplate>(\"hwchase17/xml-agent-convo\");\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * });\n *\n * const agent = await createXmlAgent({\n * llm,\n * tools,\n * prompt,\n * });\n *\n * const agentExecutor = new AgentExecutor({\n * agent,\n * tools,\n * });\n *\n * const result = await agentExecutor.invoke({\n * input: \"what is LangChain?\",\n * });\n *\n * // With chat history\n * const result2 = await agentExecutor.invoke({\n * input: \"what's my name?\",\n * // Notice that chat_history is a string, since this prompt is aimed at LLMs, not chat models\n * chat_history: \"Human: Hi! My name is Cob\\nAI: Hello Cob! Nice to meet you\",\n * });\n * ```\n */\nexport async function createXmlAgent({\n llm,\n tools,\n prompt,\n streamRunnable,\n}: CreateXmlAgentParams) {\n const missingVariables = [\"tools\", \"agent_scratchpad\"].filter(\n (v) => !prompt.inputVariables.includes(v)\n );\n if (missingVariables.length > 0) {\n throw new Error(\n `Provided prompt is missing required input variables: ${JSON.stringify(\n missingVariables\n )}`\n );\n }\n const partialedPrompt = await prompt.partial({\n tools: renderTextDescription(tools),\n });\n // TODO: Add .bind to core runnable interface.\n const llmWithStop = (llm as BaseLanguageModel).withConfig({\n stop: [\"</tool_input>\", \"</final_answer>\"],\n });\n const agent = AgentRunnableSequence.fromRunnables(\n [\n RunnablePassthrough.assign({\n agent_scratchpad: (input: { steps: AgentStep[] }) =>\n formatXml(input.steps),\n }),\n partialedPrompt,\n llmWithStop,\n new XMLAgentOutputParser(),\n ],\n {\n name: \"XMLAgent\",\n streamRunnable,\n singleAction: true,\n }\n );\n return agent;\n}\n"],"mappings":";;;;;;;;;;;;AAqCA,IAAa,WAAb,MAAa,iBAAiBA,cAAAA,sBAA+C;CAC3E,OAAO,UAAU;EACf,OAAO;CACT;CAEA,eAAe;EAAC;EAAa;EAAU;CAAK;CAE5C;CAEA;CAEA,eAAqC,IAAIC,iCAAAA,qBAAqB;CAE9D,aAAa;EACX,OAAO;CACT;CAEA,YAAY,QAAuB;EACjC,MAAM,MAAM;EACZ,KAAK,QAAQ,OAAO;EACpB,KAAK,WAAW,OAAO;CACzB;CAEA,IAAI,YAAY;EACd,OAAO,CAAC,OAAO;CACjB;CAEA,OAAO,eAAe;EACpB,OAAOC,wBAAAA,mBAAmB,aAAa,CACrCC,wBAAAA,2BAA2B,aAAaC,eAAAA,kBAAkB,GAC1DC,wBAAAA,wBAAwB,aAAa,sBAAsB,CAC7D,CAAC;CACH;;;;;;;;;CAUA,MAAM,KACJ,OACA,QACA,iBACoC;EACpC,IAAI,MAAM;EACV,KAAK,MAAM,EAAE,QAAQ,iBAAiB,OACpC,OAAO,SAAS,OAAO,KAAK,qBAAqB,OAAO,UAAU,4BAA4B,YAAY;EAE5G,IAAI,QAAQ;EACZ,KAAK,MAAM,QAAQ,KAAK,OACtB,SAAS,GAAG,KAAK,KAAK,IAAI,KAAK,YAAY;EAE7C,MAAM,UAAU;GACd,oBAAoB;GACpB;GACA,UAAU,OAAO;GACjB,MAAM,CAAC,iBAAiB,iBAAiB;EAC3C;EACA,MAAM,WAAW,MAAM,KAAK,SAAS,KAAK,SAAS,eAAe;EAClE,OAAO,KAAK,aAAa,MAAM,SAAS,KAAK,SAAS,UAAU;CAClE;;;;;;;;CASA,OAAO,gBACL,KACA,OACA,MACA;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["BaseSingleActionAgent","XMLAgentOutputParser","ChatPromptTemplate","HumanMessagePromptTemplate","AGENT_INSTRUCTIONS","AIMessagePromptTemplate","LLMChain","renderTextDescription","AgentRunnableSequence","RunnablePassthrough","formatXml"],"sources":["../../../src/agents/xml/index.ts"],"sourcesContent":["import type {\n BaseLanguageModel,\n BaseLanguageModelInterface,\n} from \"@langchain/core/language_models/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport { RunnablePassthrough } from \"@langchain/core/runnables\";\nimport type { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { AgentStep, AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { ChainValues } from \"@langchain/core/utils/types\";\nimport {\n AIMessagePromptTemplate,\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n} from \"@langchain/core/prompts\";\nimport { CallbackManager } from \"@langchain/core/callbacks/manager\";\nimport { LLMChain } from \"../../chains/llm_chain.js\";\nimport {\n AgentArgs,\n AgentRunnableSequence,\n BaseSingleActionAgent,\n} from \"../agent.js\";\nimport { AGENT_INSTRUCTIONS } from \"./prompt.js\";\nimport { XMLAgentOutputParser } from \"./output_parser.js\";\nimport { renderTextDescription } from \"../../tools/render.js\";\nimport { formatXml } from \"../format_scratchpad/xml.js\";\n\n/**\n * Interface for the input to the XMLAgent class.\n */\nexport interface XMLAgentInput {\n tools: ToolInterface[];\n llmChain: LLMChain;\n}\n\n/**\n * Class that represents an agent that uses XML tags.\n */\nexport class XMLAgent extends BaseSingleActionAgent implements XMLAgentInput {\n static lc_name() {\n return \"XMLAgent\";\n }\n\n lc_namespace = [\"langchain\", \"agents\", \"xml\"];\n\n tools: ToolInterface[];\n\n llmChain: LLMChain;\n\n outputParser: XMLAgentOutputParser = new XMLAgentOutputParser();\n\n _agentType() {\n return \"xml\" as const;\n }\n\n constructor(fields: XMLAgentInput) {\n super(fields);\n this.tools = fields.tools;\n this.llmChain = fields.llmChain;\n }\n\n get inputKeys() {\n return [\"input\"];\n }\n\n static createPrompt() {\n return ChatPromptTemplate.fromMessages([\n HumanMessagePromptTemplate.fromTemplate(AGENT_INSTRUCTIONS),\n AIMessagePromptTemplate.fromTemplate(\"{intermediate_steps}\"),\n ]);\n }\n\n /**\n * Plans the next action or finish state of the agent based on the\n * provided steps, inputs, and optional callback manager.\n * @param steps The steps to consider in planning.\n * @param inputs The inputs to consider in planning.\n * @param callbackManager Optional CallbackManager to use in planning.\n * @returns A Promise that resolves to an AgentAction or AgentFinish object representing the planned action or finish state.\n */\n async plan(\n steps: AgentStep[],\n inputs: ChainValues,\n callbackManager?: CallbackManager\n ): Promise<AgentAction | AgentFinish> {\n let log = \"\";\n for (const { action, observation } of steps) {\n log += `<tool>${action.tool}</tool><tool_input>${action.toolInput}</tool_input><observation>${observation}</observation>`;\n }\n let tools = \"\";\n for (const tool of this.tools) {\n tools += `${tool.name}: ${tool.description}\\n`;\n }\n const _inputs = {\n intermediate_steps: log,\n tools,\n question: inputs.input,\n stop: [\"</tool_input>\", \"</final_answer>\"],\n };\n const response = await this.llmChain.call(_inputs, callbackManager);\n return this.outputParser.parse(response[this.llmChain.outputKey]);\n }\n\n /**\n * Creates an XMLAgent from a BaseLanguageModel and a list of tools.\n * @param llm The BaseLanguageModel to use.\n * @param tools The tools to be used by the agent.\n * @param args Optional arguments for creating the agent.\n * @returns An instance of XMLAgent.\n */\n static fromLLMAndTools(\n llm: BaseLanguageModelInterface,\n tools: ToolInterface[],\n args?: XMLAgentInput & Pick<AgentArgs, \"callbacks\">\n ) {\n const prompt = XMLAgent.createPrompt();\n const chain = new LLMChain({\n prompt,\n llm,\n callbacks: args?.callbacks,\n });\n return new XMLAgent({\n llmChain: chain,\n tools,\n });\n }\n}\n\n/**\n * Params used by the createXmlAgent function.\n */\nexport type CreateXmlAgentParams = {\n /** LLM to use for the agent. */\n llm: BaseLanguageModelInterface;\n /** Tools this agent has access to. */\n tools: ToolInterface[];\n /**\n * The prompt to use. Must have input keys for\n * `tools` and `agent_scratchpad`.\n */\n prompt: BasePromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n\n/**\n * Create an agent that uses XML to format its logic.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n *\n * @example\n * ```typescript\n * import { AgentExecutor, createXmlAgent } from \"langchain/agents\";\n * import { pull } from \"langchain/hub\";\n * import type { PromptTemplate } from \"@langchain/core/prompts\";\n *\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * // Get the prompt to use - you can modify this!\n * // If you want to see the prompt in full, you can at:\n * // https://smith.langchain.com/hub/hwchase17/xml-agent-convo\n * const prompt = await pull<PromptTemplate>(\"hwchase17/xml-agent-convo\");\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * });\n *\n * const agent = await createXmlAgent({\n * llm,\n * tools,\n * prompt,\n * });\n *\n * const agentExecutor = new AgentExecutor({\n * agent,\n * tools,\n * });\n *\n * const result = await agentExecutor.invoke({\n * input: \"what is LangChain?\",\n * });\n *\n * // With chat history\n * const result2 = await agentExecutor.invoke({\n * input: \"what's my name?\",\n * // Notice that chat_history is a string, since this prompt is aimed at LLMs, not chat models\n * chat_history: \"Human: Hi! My name is Cob\\nAI: Hello Cob! Nice to meet you\",\n * });\n * ```\n */\nexport async function createXmlAgent({\n llm,\n tools,\n prompt,\n streamRunnable,\n}: CreateXmlAgentParams) {\n const missingVariables = [\"tools\", \"agent_scratchpad\"].filter(\n (v) => !prompt.inputVariables.includes(v)\n );\n if (missingVariables.length > 0) {\n throw new Error(\n `Provided prompt is missing required input variables: ${JSON.stringify(\n missingVariables\n )}`\n );\n }\n const partialedPrompt = await prompt.partial({\n tools: renderTextDescription(tools),\n });\n // TODO: Add .bind to core runnable interface.\n const llmWithStop = (llm as BaseLanguageModel).withConfig({\n stop: [\"</tool_input>\", \"</final_answer>\"],\n });\n const agent = AgentRunnableSequence.fromRunnables(\n [\n RunnablePassthrough.assign({\n agent_scratchpad: (input: { steps: AgentStep[] }) =>\n formatXml(input.steps),\n }),\n partialedPrompt,\n llmWithStop,\n new XMLAgentOutputParser(),\n ],\n {\n name: \"XMLAgent\",\n streamRunnable,\n singleAction: true,\n }\n );\n return agent;\n}\n"],"mappings":";;;;;;;;;;;;AAqCA,IAAa,WAAb,MAAa,iBAAiBA,cAAAA,sBAA+C;CAC3E,OAAO,UAAU;EACf,OAAO;CACT;CAEA,eAAe;EAAC;EAAa;EAAU;CAAK;CAE5C;CAEA;CAEA,eAAqC,IAAIC,iCAAAA,qBAAqB;CAE9D,aAAa;EACX,OAAO;CACT;CAEA,YAAY,QAAuB;EACjC,MAAM,MAAM;EACZ,KAAK,QAAQ,OAAO;EACpB,KAAK,WAAW,OAAO;CACzB;CAEA,IAAI,YAAY;EACd,OAAO,CAAC,OAAO;CACjB;CAEA,OAAO,eAAe;EACpB,OAAOC,wBAAAA,mBAAmB,aAAa,CACrCC,wBAAAA,2BAA2B,aAAaC,eAAAA,kBAAkB,GAC1DC,wBAAAA,wBAAwB,aAAa,sBAAsB,CAC7D,CAAC;CACH;;;;;;;;;CAUA,MAAM,KACJ,OACA,QACA,iBACoC;EACpC,IAAI,MAAM;EACV,KAAK,MAAM,EAAE,QAAQ,iBAAiB,OACpC,OAAO,SAAS,OAAO,KAAK,qBAAqB,OAAO,UAAU,4BAA4B,YAAY;EAE5G,IAAI,QAAQ;EACZ,KAAK,MAAM,QAAQ,KAAK,OACtB,SAAS,GAAG,KAAK,KAAK,IAAI,KAAK,YAAY;EAE7C,MAAM,UAAU;GACd,oBAAoB;GACpB;GACA,UAAU,OAAO;GACjB,MAAM,CAAC,iBAAiB,iBAAiB;EAC3C;EACA,MAAM,WAAW,MAAM,KAAK,SAAS,KAAK,SAAS,eAAe;EAClE,OAAO,KAAK,aAAa,MAAM,SAAS,KAAK,SAAS,UAAU;CAClE;;;;;;;;CASA,OAAO,gBACL,KACA,OACA,MACA;EACA,MAAM,SAAS,SAAS,aAAa;EACrC,MAAM,QAAQ,IAAIC,kBAAAA,SAAS;GACzB;GACA;GACA,WAAW,MAAM;EACnB,CAAC;EACD,OAAO,IAAI,SAAS;GAClB,UAAU;GACV;EACF,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,eAAsB,eAAe,EACnC,KACA,OACA,QACA,kBACuB;CACvB,MAAM,mBAAmB,CAAC,SAAS,kBAAkB,CAAC,CAAC,QACpD,MAAM,CAAC,OAAO,eAAe,SAAS,CAAC,CAC1C;CACA,IAAI,iBAAiB,SAAS,GAC5B,MAAM,IAAI,MACR,wDAAwD,KAAK,UAC3D,gBACF,GACF;CAEF,MAAM,kBAAkB,MAAM,OAAO,QAAQ,EAC3C,OAAOC,qBAAAA,sBAAsB,KAAK,EACpC,CAAC;CAED,MAAM,cAAe,IAA0B,WAAW,EACxD,MAAM,CAAC,iBAAiB,iBAAiB,EAC3C,CAAC;CAiBD,OAhBcC,cAAAA,sBAAsB,cAClC;EACEC,0BAAAA,oBAAoB,OAAO,EACzB,mBAAmB,UACjBC,qCAAAA,UAAU,MAAM,KAAK,EACzB,CAAC;EACD;EACA;EACA,IAAIT,iCAAAA,qBAAqB;CAC3B,GACA;EACE,MAAM;EACN;EACA,cAAc;CAChB,CAES;AACb"}
|
package/dist/agents/xml/index.js
CHANGED
|
@@ -66,8 +66,9 @@ var XMLAgent = class XMLAgent extends BaseSingleActionAgent {
|
|
|
66
66
|
* @returns An instance of XMLAgent.
|
|
67
67
|
*/
|
|
68
68
|
static fromLLMAndTools(llm, tools, args) {
|
|
69
|
+
const prompt = XMLAgent.createPrompt();
|
|
69
70
|
const chain = new LLMChain({
|
|
70
|
-
prompt
|
|
71
|
+
prompt,
|
|
71
72
|
llm,
|
|
72
73
|
callbacks: args?.callbacks
|
|
73
74
|
});
|