langchain 0.2.7 → 0.2.8
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/dist/agents/openai_tools/index.d.ts +2 -1
- package/dist/agents/structured_chat/index.cjs +12 -1
- package/dist/agents/structured_chat/index.d.ts +2 -2
- package/dist/agents/structured_chat/index.js +12 -1
- package/dist/agents/tool_calling/index.d.ts +2 -1
- package/dist/experimental/chrome_ai/app/dist/bundle.cjs +1250 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.d.ts +1 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.js +1249 -0
- package/dist/tools/render.cjs +14 -1
- package/dist/tools/render.d.ts +3 -2
- package/dist/tools/render.js +14 -1
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
|
2
2
|
import type { BaseChatModel, BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";
|
|
3
3
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
4
4
|
import { OpenAIClient } from "@langchain/openai";
|
|
5
|
+
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
5
6
|
import { OpenAIToolsAgentOutputParser, type ToolsAgentStep } from "./output_parser.js";
|
|
6
7
|
import { AgentRunnableSequence } from "../agent.js";
|
|
7
8
|
export { OpenAIToolsAgentOutputParser, type ToolsAgentStep };
|
|
@@ -18,7 +19,7 @@ export type CreateOpenAIToolsAgentParams = {
|
|
|
18
19
|
tools?: StructuredToolInterface[] | OpenAIClient.ChatCompletionTool[] | any[];
|
|
19
20
|
}>;
|
|
20
21
|
/** Tools this agent has access to. */
|
|
21
|
-
tools: StructuredToolInterface[];
|
|
22
|
+
tools: StructuredToolInterface[] | ToolDefinition[];
|
|
22
23
|
/** The prompt to use, must have an input key of `agent_scratchpad`. */
|
|
23
24
|
prompt: ChatPromptTemplate;
|
|
24
25
|
/**
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStructuredChatAgent = exports.StructuredChatAgent = void 0;
|
|
4
4
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
|
+
const base_1 = require("@langchain/core/language_models/base");
|
|
5
6
|
const runnables_1 = require("@langchain/core/runnables");
|
|
6
7
|
const prompts_1 = require("@langchain/core/prompts");
|
|
8
|
+
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
7
9
|
const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
|
|
8
10
|
const agent_js_1 = require("../agent.cjs");
|
|
9
11
|
const outputParser_js_1 = require("./outputParser.cjs");
|
|
@@ -215,7 +217,16 @@ async function createStructuredChatAgent({ llm, tools, prompt, streamRunnable, }
|
|
|
215
217
|
if (missingVariables.length > 0) {
|
|
216
218
|
throw new Error(`Provided prompt is missing required input variables: ${JSON.stringify(missingVariables)}`);
|
|
217
219
|
}
|
|
218
|
-
|
|
220
|
+
let toolNames = [];
|
|
221
|
+
if (tools.every(base_1.isOpenAITool)) {
|
|
222
|
+
toolNames = tools.map((tool) => tool.function.name);
|
|
223
|
+
}
|
|
224
|
+
else if (tools.every(function_calling_1.isStructuredTool)) {
|
|
225
|
+
toolNames = tools.map((tool) => tool.name);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
throw new Error("All tools must be either OpenAI or Structured tools, not a mix.");
|
|
229
|
+
}
|
|
219
230
|
const partialedPrompt = await prompt.partial({
|
|
220
231
|
tools: (0, render_js_1.renderTextDescriptionAndArgs)(tools),
|
|
221
232
|
tool_names: toolNames.join(", "),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
2
|
-
import type
|
|
2
|
+
import { type BaseLanguageModelInterface, type ToolDefinition } from "@langchain/core/language_models/base";
|
|
3
3
|
import type { BasePromptTemplate } from "@langchain/core/prompts";
|
|
4
4
|
import { BaseMessagePromptTemplate, ChatPromptTemplate } from "@langchain/core/prompts";
|
|
5
5
|
import { AgentStep } from "@langchain/core/agents";
|
|
@@ -99,7 +99,7 @@ export type CreateStructuredChatAgentParams = {
|
|
|
99
99
|
/** LLM to use as the agent. */
|
|
100
100
|
llm: BaseLanguageModelInterface;
|
|
101
101
|
/** Tools this agent has access to. */
|
|
102
|
-
tools: StructuredToolInterface[];
|
|
102
|
+
tools: (StructuredToolInterface | ToolDefinition)[];
|
|
103
103
|
/**
|
|
104
104
|
* The prompt to use. Must have input keys for
|
|
105
105
|
* `tools`, `tool_names`, and `agent_scratchpad`.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
+
import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
2
3
|
import { RunnablePassthrough } from "@langchain/core/runnables";
|
|
3
4
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, PromptTemplate, } from "@langchain/core/prompts";
|
|
5
|
+
import { isStructuredTool } from "@langchain/core/utils/function_calling";
|
|
4
6
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
5
7
|
import { Agent, AgentRunnableSequence, } from "../agent.js";
|
|
6
8
|
import { StructuredChatOutputParserWithRetries } from "./outputParser.js";
|
|
@@ -211,7 +213,16 @@ export async function createStructuredChatAgent({ llm, tools, prompt, streamRunn
|
|
|
211
213
|
if (missingVariables.length > 0) {
|
|
212
214
|
throw new Error(`Provided prompt is missing required input variables: ${JSON.stringify(missingVariables)}`);
|
|
213
215
|
}
|
|
214
|
-
|
|
216
|
+
let toolNames = [];
|
|
217
|
+
if (tools.every(isOpenAITool)) {
|
|
218
|
+
toolNames = tools.map((tool) => tool.function.name);
|
|
219
|
+
}
|
|
220
|
+
else if (tools.every(isStructuredTool)) {
|
|
221
|
+
toolNames = tools.map((tool) => tool.name);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
throw new Error("All tools must be either OpenAI or Structured tools, not a mix.");
|
|
225
|
+
}
|
|
215
226
|
const partialedPrompt = await prompt.partial({
|
|
216
227
|
tools: renderTextDescriptionAndArgs(tools),
|
|
217
228
|
tool_names: toolNames.join(", "),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
2
2
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
3
3
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
4
|
+
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
4
5
|
import { AgentRunnableSequence } from "../agent.js";
|
|
5
6
|
import { ToolsAgentStep } from "./output_parser.js";
|
|
6
7
|
/**
|
|
@@ -14,7 +15,7 @@ export type CreateToolCallingAgentParams = {
|
|
|
14
15
|
*/
|
|
15
16
|
llm: BaseChatModel;
|
|
16
17
|
/** Tools this agent has access to. */
|
|
17
|
-
tools: StructuredToolInterface[];
|
|
18
|
+
tools: StructuredToolInterface[] | ToolDefinition[];
|
|
18
19
|
/** The prompt to use, must have an input key of `agent_scratchpad`. */
|
|
19
20
|
prompt: ChatPromptTemplate;
|
|
20
21
|
/**
|