langchain 0.1.32 → 0.1.33
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/agent.cjs +2 -1
- package/dist/agents/agent.js +2 -1
- package/dist/agents/format_scratchpad/openai_tools.cjs +2 -16
- package/dist/agents/format_scratchpad/openai_tools.d.ts +2 -3
- package/dist/agents/format_scratchpad/openai_tools.js +2 -15
- package/dist/agents/format_scratchpad/tool_calling.cjs +30 -0
- package/dist/agents/format_scratchpad/tool_calling.d.ts +10 -0
- package/dist/agents/format_scratchpad/tool_calling.js +25 -0
- package/dist/agents/index.cjs +8 -6
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +1 -0
- package/dist/agents/openai_tools/index.cjs +1 -1
- package/dist/agents/openai_tools/index.d.ts +1 -1
- package/dist/agents/openai_tools/index.js +1 -1
- package/dist/agents/openai_tools/output_parser.cjs +0 -2
- package/dist/agents/openai_tools/output_parser.d.ts +3 -13
- package/dist/agents/openai_tools/output_parser.js +0 -2
- package/dist/agents/tool_calling/index.cjs +83 -0
- package/dist/agents/tool_calling/index.d.ts +78 -0
- package/dist/agents/tool_calling/index.js +79 -0
- package/dist/agents/tool_calling/output_parser.cjs +75 -0
- package/dist/agents/tool_calling/output_parser.d.ts +22 -0
- package/dist/agents/tool_calling/output_parser.js +70 -0
- package/dist/chains/openai_functions/extraction.d.ts +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +2 -2
- package/dist/chains/openai_functions/tagging.d.ts +2 -2
- package/package.json +5 -5
package/dist/agents/agent.cjs
CHANGED
|
@@ -246,7 +246,8 @@ class RunnableMultiActionAgent extends BaseMultiActionAgent {
|
|
|
246
246
|
});
|
|
247
247
|
this.runnable = fields.runnable;
|
|
248
248
|
this.stop = fields.stop;
|
|
249
|
-
this.defaultRunName =
|
|
249
|
+
this.defaultRunName =
|
|
250
|
+
fields.defaultRunName ?? this.runnable.name ?? this.defaultRunName;
|
|
250
251
|
this.streamRunnable = fields.streamRunnable ?? this.streamRunnable;
|
|
251
252
|
}
|
|
252
253
|
async plan(steps, inputs, callbackManager, config) {
|
package/dist/agents/agent.js
CHANGED
|
@@ -237,7 +237,8 @@ export class RunnableMultiActionAgent extends BaseMultiActionAgent {
|
|
|
237
237
|
});
|
|
238
238
|
this.runnable = fields.runnable;
|
|
239
239
|
this.stop = fields.stop;
|
|
240
|
-
this.defaultRunName =
|
|
240
|
+
this.defaultRunName =
|
|
241
|
+
fields.defaultRunName ?? this.runnable.name ?? this.defaultRunName;
|
|
241
242
|
this.streamRunnable = fields.streamRunnable ?? this.streamRunnable;
|
|
242
243
|
}
|
|
243
244
|
async plan(steps, inputs, callbackManager, config) {
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatToOpenAIToolMessages = void 0;
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
return steps.flatMap(({ action, observation }) => {
|
|
7
|
-
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
8
|
-
const log = action.messageLog;
|
|
9
|
-
return log.concat(new messages_1.ToolMessage({
|
|
10
|
-
content: observation,
|
|
11
|
-
tool_call_id: action.toolCallId,
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return [new messages_1.AIMessage(action.log)];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
exports.formatToOpenAIToolMessages = formatToOpenAIToolMessages;
|
|
4
|
+
const tool_calling_js_1 = require("./tool_calling.cjs");
|
|
5
|
+
Object.defineProperty(exports, "formatToOpenAIToolMessages", { enumerable: true, get: function () { return tool_calling_js_1.formatToToolMessages; } });
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function formatToOpenAIToolMessages(steps: ToolsAgentStep[]): BaseMessage[];
|
|
1
|
+
import { formatToToolMessages as formatToOpenAIToolMessages } from "./tool_calling.js";
|
|
2
|
+
export { formatToOpenAIToolMessages };
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
return steps.flatMap(({ action, observation }) => {
|
|
4
|
-
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
5
|
-
const log = action.messageLog;
|
|
6
|
-
return log.concat(new ToolMessage({
|
|
7
|
-
content: observation,
|
|
8
|
-
tool_call_id: action.toolCallId,
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
return [new AIMessage(action.log)];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
1
|
+
import { formatToToolMessages as formatToOpenAIToolMessages } from "./tool_calling.js";
|
|
2
|
+
export { formatToOpenAIToolMessages };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatToToolMessages = exports._createToolMessage = void 0;
|
|
4
|
+
const messages_1 = require("@langchain/core/messages");
|
|
5
|
+
/**
|
|
6
|
+
* Convert agent action and observation into a function message.
|
|
7
|
+
* @param agentAction - The tool invocation request from the agent
|
|
8
|
+
* @param observation - The result of the tool invocation
|
|
9
|
+
* @returns FunctionMessage that corresponds to the original tool invocation
|
|
10
|
+
*/
|
|
11
|
+
function _createToolMessage(step) {
|
|
12
|
+
return new messages_1.ToolMessage({
|
|
13
|
+
tool_call_id: step.action.toolCallId,
|
|
14
|
+
content: step.observation,
|
|
15
|
+
additional_kwargs: { name: step.action.tool },
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports._createToolMessage = _createToolMessage;
|
|
19
|
+
function formatToToolMessages(steps) {
|
|
20
|
+
return steps.flatMap(({ action, observation }) => {
|
|
21
|
+
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
22
|
+
const log = action.messageLog;
|
|
23
|
+
return log.concat(_createToolMessage({ action, observation }));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return [new messages_1.AIMessage(action.log)];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.formatToToolMessages = formatToToolMessages;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseMessage, ToolMessage } from "@langchain/core/messages";
|
|
2
|
+
import { ToolsAgentStep } from "../tool_calling/output_parser.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert agent action and observation into a function message.
|
|
5
|
+
* @param agentAction - The tool invocation request from the agent
|
|
6
|
+
* @param observation - The result of the tool invocation
|
|
7
|
+
* @returns FunctionMessage that corresponds to the original tool invocation
|
|
8
|
+
*/
|
|
9
|
+
export declare function _createToolMessage(step: ToolsAgentStep): ToolMessage;
|
|
10
|
+
export declare function formatToToolMessages(steps: ToolsAgentStep[]): BaseMessage[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AIMessage, ToolMessage } from "@langchain/core/messages";
|
|
2
|
+
/**
|
|
3
|
+
* Convert agent action and observation into a function message.
|
|
4
|
+
* @param agentAction - The tool invocation request from the agent
|
|
5
|
+
* @param observation - The result of the tool invocation
|
|
6
|
+
* @returns FunctionMessage that corresponds to the original tool invocation
|
|
7
|
+
*/
|
|
8
|
+
export function _createToolMessage(step) {
|
|
9
|
+
return new ToolMessage({
|
|
10
|
+
tool_call_id: step.action.toolCallId,
|
|
11
|
+
content: step.observation,
|
|
12
|
+
additional_kwargs: { name: step.action.tool },
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function formatToToolMessages(steps) {
|
|
16
|
+
return steps.flatMap(({ action, observation }) => {
|
|
17
|
+
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
18
|
+
const log = action.messageLog;
|
|
19
|
+
return log.concat(_createToolMessage({ action, observation }));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return [new AIMessage(action.log)];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
package/dist/agents/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createReactAgent = exports.createXmlAgent = exports.XMLAgent = exports.createOpenAIToolsAgent = exports.createOpenAIFunctionsAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.createStructuredChatAgent = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
|
|
3
|
+
exports.createReactAgent = exports.createXmlAgent = exports.XMLAgent = exports.createToolCallingAgent = exports.createOpenAIToolsAgent = exports.createOpenAIFunctionsAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.createStructuredChatAgent = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
|
|
4
4
|
var agent_js_1 = require("./agent.cjs");
|
|
5
5
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_js_1.Agent; } });
|
|
6
6
|
Object.defineProperty(exports, "BaseSingleActionAgent", { enumerable: true, get: function () { return agent_js_1.BaseSingleActionAgent; } });
|
|
@@ -51,8 +51,10 @@ Object.defineProperty(exports, "OpenAIAgent", { enumerable: true, get: function
|
|
|
51
51
|
Object.defineProperty(exports, "createOpenAIFunctionsAgent", { enumerable: true, get: function () { return index_js_6.createOpenAIFunctionsAgent; } });
|
|
52
52
|
var index_js_7 = require("./openai_tools/index.cjs");
|
|
53
53
|
Object.defineProperty(exports, "createOpenAIToolsAgent", { enumerable: true, get: function () { return index_js_7.createOpenAIToolsAgent; } });
|
|
54
|
-
var index_js_8 = require("./
|
|
55
|
-
Object.defineProperty(exports, "
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Object.defineProperty(exports, "
|
|
54
|
+
var index_js_8 = require("./tool_calling/index.cjs");
|
|
55
|
+
Object.defineProperty(exports, "createToolCallingAgent", { enumerable: true, get: function () { return index_js_8.createToolCallingAgent; } });
|
|
56
|
+
var index_js_9 = require("./xml/index.cjs");
|
|
57
|
+
Object.defineProperty(exports, "XMLAgent", { enumerable: true, get: function () { return index_js_9.XMLAgent; } });
|
|
58
|
+
Object.defineProperty(exports, "createXmlAgent", { enumerable: true, get: function () { return index_js_9.createXmlAgent; } });
|
|
59
|
+
var index_js_10 = require("./react/index.cjs");
|
|
60
|
+
Object.defineProperty(exports, "createReactAgent", { enumerable: true, get: function () { return index_js_10.createReactAgent; } });
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { StructuredChatAgent, type StructuredChatAgentInput, type StructuredChat
|
|
|
14
14
|
export { StructuredChatOutputParser, type StructuredChatOutputParserArgs, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
|
|
15
15
|
export { OpenAIAgent, type OpenAIAgentInput, type OpenAIAgentCreatePromptArgs, type CreateOpenAIFunctionsAgentParams, createOpenAIFunctionsAgent, } from "./openai_functions/index.js";
|
|
16
16
|
export { type CreateOpenAIToolsAgentParams, createOpenAIToolsAgent, } from "./openai_tools/index.js";
|
|
17
|
+
export { type CreateToolCallingAgentParams, createToolCallingAgent, } from "./tool_calling/index.js";
|
|
17
18
|
export { XMLAgent, type XMLAgentInput, type CreateXmlAgentParams, createXmlAgent, } from "./xml/index.js";
|
|
18
19
|
export { type CreateReactAgentParams, createReactAgent, } from "./react/index.js";
|
|
19
20
|
export type { AgentAction, AgentFinish, AgentStep, } from "@langchain/core/agents";
|
package/dist/agents/index.js
CHANGED
|
@@ -14,5 +14,6 @@ export { StructuredChatAgent, createStructuredChatAgent, } from "./structured_ch
|
|
|
14
14
|
export { StructuredChatOutputParser, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
|
|
15
15
|
export { OpenAIAgent, createOpenAIFunctionsAgent, } from "./openai_functions/index.js";
|
|
16
16
|
export { createOpenAIToolsAgent, } from "./openai_tools/index.js";
|
|
17
|
+
export { createToolCallingAgent, } from "./tool_calling/index.js";
|
|
17
18
|
export { XMLAgent, createXmlAgent, } from "./xml/index.js";
|
|
18
19
|
export { createReactAgent, } from "./react/index.js";
|
|
@@ -4,7 +4,7 @@ exports.createOpenAIToolsAgent = exports.OpenAIToolsAgentOutputParser = void 0;
|
|
|
4
4
|
const runnables_1 = require("@langchain/core/runnables");
|
|
5
5
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
6
|
const openai_tools_js_1 = require("../format_scratchpad/openai_tools.cjs");
|
|
7
|
-
const output_parser_js_1 = require("
|
|
7
|
+
const output_parser_js_1 = require("./output_parser.cjs");
|
|
8
8
|
Object.defineProperty(exports, "OpenAIToolsAgentOutputParser", { enumerable: true, get: function () { return output_parser_js_1.OpenAIToolsAgentOutputParser; } });
|
|
9
9
|
const agent_js_1 = require("../agent.cjs");
|
|
10
10
|
/**
|
|
@@ -2,7 +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 { OpenAIToolsAgentOutputParser, type ToolsAgentStep } from "
|
|
5
|
+
import { OpenAIToolsAgentOutputParser, type ToolsAgentStep } from "./output_parser.js";
|
|
6
6
|
import { AgentRunnableSequence } from "../agent.js";
|
|
7
7
|
export { OpenAIToolsAgentOutputParser, type ToolsAgentStep };
|
|
8
8
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RunnablePassthrough } from "@langchain/core/runnables";
|
|
2
2
|
import { convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
3
3
|
import { formatToOpenAIToolMessages } from "../format_scratchpad/openai_tools.js";
|
|
4
|
-
import { OpenAIToolsAgentOutputParser, } from "
|
|
4
|
+
import { OpenAIToolsAgentOutputParser, } from "./output_parser.js";
|
|
5
5
|
import { AgentRunnableSequence } from "../agent.js";
|
|
6
6
|
export { OpenAIToolsAgentOutputParser };
|
|
7
7
|
/**
|
|
@@ -7,7 +7,6 @@ const types_js_1 = require("../types.cjs");
|
|
|
7
7
|
/**
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
|
-
*
|
|
11
10
|
* const prompt = ChatPromptTemplate.fromMessages([
|
|
12
11
|
* ["ai", "You are a helpful assistant"],
|
|
13
12
|
* ["human", "{input}"],
|
|
@@ -32,7 +31,6 @@ const types_js_1 = require("../types.cjs");
|
|
|
32
31
|
* input:
|
|
33
32
|
* "What is the sum of the current temperature in San Francisco, New York, and Tokyo?",
|
|
34
33
|
* });
|
|
35
|
-
*
|
|
36
34
|
* ```
|
|
37
35
|
*/
|
|
38
36
|
class OpenAIToolsAgentOutputParser extends types_js_1.AgentMultiActionOutputParser {
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import { AgentAction, AgentFinish
|
|
1
|
+
import { AgentAction, AgentFinish } from "@langchain/core/agents";
|
|
2
2
|
import { BaseMessage } from "@langchain/core/messages";
|
|
3
3
|
import { ChatGeneration } from "@langchain/core/outputs";
|
|
4
4
|
import { AgentMultiActionOutputParser } from "../types.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export type ToolsAgentAction = AgentAction & {
|
|
9
|
-
toolCallId: string;
|
|
10
|
-
messageLog?: BaseMessage[];
|
|
11
|
-
};
|
|
12
|
-
export type ToolsAgentStep = AgentStep & {
|
|
13
|
-
action: ToolsAgentAction;
|
|
14
|
-
};
|
|
5
|
+
import { ToolsAgentAction, ToolsAgentStep } from "../tool_calling/output_parser.js";
|
|
6
|
+
export type { ToolsAgentAction, ToolsAgentStep };
|
|
15
7
|
/**
|
|
16
8
|
* @example
|
|
17
9
|
* ```typescript
|
|
18
|
-
*
|
|
19
10
|
* const prompt = ChatPromptTemplate.fromMessages([
|
|
20
11
|
* ["ai", "You are a helpful assistant"],
|
|
21
12
|
* ["human", "{input}"],
|
|
@@ -40,7 +31,6 @@ export type ToolsAgentStep = AgentStep & {
|
|
|
40
31
|
* input:
|
|
41
32
|
* "What is the sum of the current temperature in San Francisco, New York, and Tokyo?",
|
|
42
33
|
* });
|
|
43
|
-
*
|
|
44
34
|
* ```
|
|
45
35
|
*/
|
|
46
36
|
export declare class OpenAIToolsAgentOutputParser extends AgentMultiActionOutputParser {
|
|
@@ -4,7 +4,6 @@ import { AgentMultiActionOutputParser } from "../types.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @example
|
|
6
6
|
* ```typescript
|
|
7
|
-
*
|
|
8
7
|
* const prompt = ChatPromptTemplate.fromMessages([
|
|
9
8
|
* ["ai", "You are a helpful assistant"],
|
|
10
9
|
* ["human", "{input}"],
|
|
@@ -29,7 +28,6 @@ import { AgentMultiActionOutputParser } from "../types.js";
|
|
|
29
28
|
* input:
|
|
30
29
|
* "What is the sum of the current temperature in San Francisco, New York, and Tokyo?",
|
|
31
30
|
* });
|
|
32
|
-
*
|
|
33
31
|
* ```
|
|
34
32
|
*/
|
|
35
33
|
export class OpenAIToolsAgentOutputParser extends AgentMultiActionOutputParser {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createToolCallingAgent = void 0;
|
|
4
|
+
const runnables_1 = require("@langchain/core/runnables");
|
|
5
|
+
const agent_js_1 = require("../agent.cjs");
|
|
6
|
+
const output_parser_js_1 = require("./output_parser.cjs");
|
|
7
|
+
const tool_calling_js_1 = require("../format_scratchpad/tool_calling.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* Create an agent that uses tools.
|
|
10
|
+
* @param params Params required to create the agent. Includes an LLM, tools, and prompt.
|
|
11
|
+
* @returns A runnable sequence representing an agent. It takes as input all the same input
|
|
12
|
+
* variables as the prompt passed in does. It returns as output either an
|
|
13
|
+
* AgentAction or AgentFinish.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { ChatAnthropic } from "@langchain/anthropic";
|
|
17
|
+
* import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
|
|
18
|
+
* import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
|
|
19
|
+
*
|
|
20
|
+
* const prompt = ChatPromptTemplate.fromMessages(
|
|
21
|
+
* [
|
|
22
|
+
* ["system", "You are a helpful assistant"],
|
|
23
|
+
* ["placeholder", "{chat_history}"],
|
|
24
|
+
* ["human", "{input}"],
|
|
25
|
+
* ["placeholder", "{agent_scratchpad}"],
|
|
26
|
+
* ]
|
|
27
|
+
* );
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
* const llm = new ChatAnthropic({
|
|
31
|
+
* modelName: "claude-3-opus-20240229",
|
|
32
|
+
* temperature: 0,
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Define the tools the agent will have access to.
|
|
36
|
+
* const tools = [...];
|
|
37
|
+
*
|
|
38
|
+
* const agent = createToolCallingAgent({ llm, tools, prompt });
|
|
39
|
+
*
|
|
40
|
+
* const agentExecutor = new AgentExecutor({ agent, tools });
|
|
41
|
+
*
|
|
42
|
+
* const result = await agentExecutor.invoke({input: "what is LangChain?"});
|
|
43
|
+
*
|
|
44
|
+
* // Using with chat history
|
|
45
|
+
* import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
46
|
+
*
|
|
47
|
+
* const result2 = await agentExecutor.invoke(
|
|
48
|
+
* {
|
|
49
|
+
* input: "what's my name?",
|
|
50
|
+
* chat_history: [
|
|
51
|
+
* new HumanMessage({content: "hi! my name is bob"}),
|
|
52
|
+
* new AIMessage({content: "Hello Bob! How can I assist you today?"}),
|
|
53
|
+
* ],
|
|
54
|
+
* }
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function createToolCallingAgent({ llm, tools, prompt, streamRunnable, }) {
|
|
59
|
+
if (!prompt.inputVariables.includes("agent_scratchpad")) {
|
|
60
|
+
throw new Error([
|
|
61
|
+
`Prompt must have an input variable named "agent_scratchpad".`,
|
|
62
|
+
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
63
|
+
].join("\n"));
|
|
64
|
+
}
|
|
65
|
+
if (llm.bindTools === undefined) {
|
|
66
|
+
throw new Error(`This agent requires that the "bind_tools()" method be implemented on the input model.`);
|
|
67
|
+
}
|
|
68
|
+
const modelWithTools = llm.bindTools(tools);
|
|
69
|
+
const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
|
|
70
|
+
runnables_1.RunnablePassthrough.assign({
|
|
71
|
+
agent_scratchpad: (input) => (0, tool_calling_js_1.formatToToolMessages)(input.steps),
|
|
72
|
+
}),
|
|
73
|
+
prompt,
|
|
74
|
+
modelWithTools,
|
|
75
|
+
new output_parser_js_1.ToolCallingAgentOutputParser(),
|
|
76
|
+
], {
|
|
77
|
+
name: "ToolCallingAgent",
|
|
78
|
+
streamRunnable,
|
|
79
|
+
singleAction: false,
|
|
80
|
+
});
|
|
81
|
+
return agent;
|
|
82
|
+
}
|
|
83
|
+
exports.createToolCallingAgent = createToolCallingAgent;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
2
|
+
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
3
|
+
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
4
|
+
import { AgentRunnableSequence } from "../agent.js";
|
|
5
|
+
import { ToolsAgentStep } from "./output_parser.js";
|
|
6
|
+
/**
|
|
7
|
+
* Params used by the createOpenAIToolsAgent function.
|
|
8
|
+
*/
|
|
9
|
+
export type CreateToolCallingAgentParams = {
|
|
10
|
+
/**
|
|
11
|
+
* LLM to use as the agent. Should work with OpenAI tool calling,
|
|
12
|
+
* so must either be an OpenAI model that supports that or a wrapper of
|
|
13
|
+
* a different model that adds in equivalent support.
|
|
14
|
+
*/
|
|
15
|
+
llm: BaseChatModel;
|
|
16
|
+
/** Tools this agent has access to. */
|
|
17
|
+
tools: StructuredToolInterface[];
|
|
18
|
+
/** The prompt to use, must have an input key of `agent_scratchpad`. */
|
|
19
|
+
prompt: ChatPromptTemplate;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to invoke the underlying model in streaming mode,
|
|
22
|
+
* allowing streaming of intermediate steps. Defaults to true.
|
|
23
|
+
*/
|
|
24
|
+
streamRunnable?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Create an agent that uses tools.
|
|
28
|
+
* @param params Params required to create the agent. Includes an LLM, tools, and prompt.
|
|
29
|
+
* @returns A runnable sequence representing an agent. It takes as input all the same input
|
|
30
|
+
* variables as the prompt passed in does. It returns as output either an
|
|
31
|
+
* AgentAction or AgentFinish.
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { ChatAnthropic } from "@langchain/anthropic";
|
|
35
|
+
* import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
|
|
36
|
+
* import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
|
|
37
|
+
*
|
|
38
|
+
* const prompt = ChatPromptTemplate.fromMessages(
|
|
39
|
+
* [
|
|
40
|
+
* ["system", "You are a helpful assistant"],
|
|
41
|
+
* ["placeholder", "{chat_history}"],
|
|
42
|
+
* ["human", "{input}"],
|
|
43
|
+
* ["placeholder", "{agent_scratchpad}"],
|
|
44
|
+
* ]
|
|
45
|
+
* );
|
|
46
|
+
*
|
|
47
|
+
*
|
|
48
|
+
* const llm = new ChatAnthropic({
|
|
49
|
+
* modelName: "claude-3-opus-20240229",
|
|
50
|
+
* temperature: 0,
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Define the tools the agent will have access to.
|
|
54
|
+
* const tools = [...];
|
|
55
|
+
*
|
|
56
|
+
* const agent = createToolCallingAgent({ llm, tools, prompt });
|
|
57
|
+
*
|
|
58
|
+
* const agentExecutor = new AgentExecutor({ agent, tools });
|
|
59
|
+
*
|
|
60
|
+
* const result = await agentExecutor.invoke({input: "what is LangChain?"});
|
|
61
|
+
*
|
|
62
|
+
* // Using with chat history
|
|
63
|
+
* import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
64
|
+
*
|
|
65
|
+
* const result2 = await agentExecutor.invoke(
|
|
66
|
+
* {
|
|
67
|
+
* input: "what's my name?",
|
|
68
|
+
* chat_history: [
|
|
69
|
+
* new HumanMessage({content: "hi! my name is bob"}),
|
|
70
|
+
* new AIMessage({content: "Hello Bob! How can I assist you today?"}),
|
|
71
|
+
* ],
|
|
72
|
+
* }
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function createToolCallingAgent({ llm, tools, prompt, streamRunnable, }: CreateToolCallingAgentParams): AgentRunnableSequence<{
|
|
77
|
+
steps: ToolsAgentStep[];
|
|
78
|
+
}, import("@langchain/core/agents").AgentFinish | import("@langchain/core/agents").AgentAction[]>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { RunnablePassthrough } from "@langchain/core/runnables";
|
|
2
|
+
import { AgentRunnableSequence } from "../agent.js";
|
|
3
|
+
import { ToolCallingAgentOutputParser, } from "./output_parser.js";
|
|
4
|
+
import { formatToToolMessages } from "../format_scratchpad/tool_calling.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create an agent that uses tools.
|
|
7
|
+
* @param params Params required to create the agent. Includes an LLM, tools, and prompt.
|
|
8
|
+
* @returns A runnable sequence representing an agent. It takes as input all the same input
|
|
9
|
+
* variables as the prompt passed in does. It returns as output either an
|
|
10
|
+
* AgentAction or AgentFinish.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ChatAnthropic } from "@langchain/anthropic";
|
|
14
|
+
* import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
|
|
15
|
+
* import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
|
|
16
|
+
*
|
|
17
|
+
* const prompt = ChatPromptTemplate.fromMessages(
|
|
18
|
+
* [
|
|
19
|
+
* ["system", "You are a helpful assistant"],
|
|
20
|
+
* ["placeholder", "{chat_history}"],
|
|
21
|
+
* ["human", "{input}"],
|
|
22
|
+
* ["placeholder", "{agent_scratchpad}"],
|
|
23
|
+
* ]
|
|
24
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* const llm = new ChatAnthropic({
|
|
28
|
+
* modelName: "claude-3-opus-20240229",
|
|
29
|
+
* temperature: 0,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Define the tools the agent will have access to.
|
|
33
|
+
* const tools = [...];
|
|
34
|
+
*
|
|
35
|
+
* const agent = createToolCallingAgent({ llm, tools, prompt });
|
|
36
|
+
*
|
|
37
|
+
* const agentExecutor = new AgentExecutor({ agent, tools });
|
|
38
|
+
*
|
|
39
|
+
* const result = await agentExecutor.invoke({input: "what is LangChain?"});
|
|
40
|
+
*
|
|
41
|
+
* // Using with chat history
|
|
42
|
+
* import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
43
|
+
*
|
|
44
|
+
* const result2 = await agentExecutor.invoke(
|
|
45
|
+
* {
|
|
46
|
+
* input: "what's my name?",
|
|
47
|
+
* chat_history: [
|
|
48
|
+
* new HumanMessage({content: "hi! my name is bob"}),
|
|
49
|
+
* new AIMessage({content: "Hello Bob! How can I assist you today?"}),
|
|
50
|
+
* ],
|
|
51
|
+
* }
|
|
52
|
+
* );
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function createToolCallingAgent({ llm, tools, prompt, streamRunnable, }) {
|
|
56
|
+
if (!prompt.inputVariables.includes("agent_scratchpad")) {
|
|
57
|
+
throw new Error([
|
|
58
|
+
`Prompt must have an input variable named "agent_scratchpad".`,
|
|
59
|
+
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
60
|
+
].join("\n"));
|
|
61
|
+
}
|
|
62
|
+
if (llm.bindTools === undefined) {
|
|
63
|
+
throw new Error(`This agent requires that the "bind_tools()" method be implemented on the input model.`);
|
|
64
|
+
}
|
|
65
|
+
const modelWithTools = llm.bindTools(tools);
|
|
66
|
+
const agent = AgentRunnableSequence.fromRunnables([
|
|
67
|
+
RunnablePassthrough.assign({
|
|
68
|
+
agent_scratchpad: (input) => formatToToolMessages(input.steps),
|
|
69
|
+
}),
|
|
70
|
+
prompt,
|
|
71
|
+
modelWithTools,
|
|
72
|
+
new ToolCallingAgentOutputParser(),
|
|
73
|
+
], {
|
|
74
|
+
name: "ToolCallingAgent",
|
|
75
|
+
streamRunnable,
|
|
76
|
+
singleAction: false,
|
|
77
|
+
});
|
|
78
|
+
return agent;
|
|
79
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolCallingAgentOutputParser = exports.parseAIMessageToToolAction = void 0;
|
|
4
|
+
const messages_1 = require("@langchain/core/messages");
|
|
5
|
+
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
6
|
+
const types_js_1 = require("../types.cjs");
|
|
7
|
+
function parseAIMessageToToolAction(message) {
|
|
8
|
+
const stringifiedMessageContent = typeof message.content === "string"
|
|
9
|
+
? message.content
|
|
10
|
+
: JSON.stringify(message.content);
|
|
11
|
+
let toolCalls = [];
|
|
12
|
+
if (message.tool_calls !== undefined && message.tool_calls.length > 0) {
|
|
13
|
+
toolCalls = message.tool_calls;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (message.additional_kwargs.tool_calls === undefined ||
|
|
17
|
+
message.additional_kwargs.tool_calls.length === 0) {
|
|
18
|
+
return {
|
|
19
|
+
returnValues: { output: message.content },
|
|
20
|
+
log: stringifiedMessageContent,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Best effort parsing
|
|
24
|
+
for (const toolCall of message.additional_kwargs.tool_calls ?? []) {
|
|
25
|
+
const functionName = toolCall.function?.name;
|
|
26
|
+
try {
|
|
27
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
28
|
+
toolCalls.push({ name: functionName, args, id: toolCall.id });
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new output_parsers_1.OutputParserException(`Failed to parse tool arguments from chat model response. Text: "${JSON.stringify(toolCalls)}". ${e}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return toolCalls.map((toolCall, i) => {
|
|
37
|
+
const messageLog = i === 0 ? [message] : [];
|
|
38
|
+
const log = `Invoking "${toolCall.name}" with ${JSON.stringify(toolCall.args ?? {})}\n${stringifiedMessageContent}`;
|
|
39
|
+
return {
|
|
40
|
+
tool: toolCall.name,
|
|
41
|
+
toolInput: toolCall.args,
|
|
42
|
+
toolCallId: toolCall.id ?? "",
|
|
43
|
+
log,
|
|
44
|
+
messageLog,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
exports.parseAIMessageToToolAction = parseAIMessageToToolAction;
|
|
49
|
+
class ToolCallingAgentOutputParser extends types_js_1.AgentMultiActionOutputParser {
|
|
50
|
+
constructor() {
|
|
51
|
+
super(...arguments);
|
|
52
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: ["langchain", "agents", "tool_calling"]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
static lc_name() {
|
|
60
|
+
return "ToolCallingAgentOutputParser";
|
|
61
|
+
}
|
|
62
|
+
async parse(text) {
|
|
63
|
+
throw new Error(`ToolCallingAgentOutputParser can only parse messages.\nPassed input: ${text}`);
|
|
64
|
+
}
|
|
65
|
+
async parseResult(generations) {
|
|
66
|
+
if ("message" in generations[0] && (0, messages_1.isBaseMessage)(generations[0].message)) {
|
|
67
|
+
return parseAIMessageToToolAction(generations[0].message);
|
|
68
|
+
}
|
|
69
|
+
throw new Error("parseResult on ToolCallingAgentOutputParser only works on ChatGeneration output");
|
|
70
|
+
}
|
|
71
|
+
getFormatInstructions() {
|
|
72
|
+
throw new Error("getFormatInstructions not implemented inside ToolCallingAgentOutputParser.");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ToolCallingAgentOutputParser = ToolCallingAgentOutputParser;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AgentAction, AgentFinish, AgentStep } from "@langchain/core/agents";
|
|
2
|
+
import { AIMessage, BaseMessage } from "@langchain/core/messages";
|
|
3
|
+
import { ChatGeneration } from "@langchain/core/outputs";
|
|
4
|
+
import { AgentMultiActionOutputParser } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Type that represents an agent action with an optional message log.
|
|
7
|
+
*/
|
|
8
|
+
export type ToolsAgentAction = AgentAction & {
|
|
9
|
+
toolCallId: string;
|
|
10
|
+
messageLog?: BaseMessage[];
|
|
11
|
+
};
|
|
12
|
+
export type ToolsAgentStep = AgentStep & {
|
|
13
|
+
action: ToolsAgentAction;
|
|
14
|
+
};
|
|
15
|
+
export declare function parseAIMessageToToolAction(message: AIMessage): ToolsAgentAction[] | AgentFinish;
|
|
16
|
+
export declare class ToolCallingAgentOutputParser extends AgentMultiActionOutputParser {
|
|
17
|
+
lc_namespace: string[];
|
|
18
|
+
static lc_name(): string;
|
|
19
|
+
parse(text: string): Promise<AgentAction[] | AgentFinish>;
|
|
20
|
+
parseResult(generations: ChatGeneration[]): Promise<AgentFinish | ToolsAgentAction[]>;
|
|
21
|
+
getFormatInstructions(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isBaseMessage, } from "@langchain/core/messages";
|
|
2
|
+
import { OutputParserException } from "@langchain/core/output_parsers";
|
|
3
|
+
import { AgentMultiActionOutputParser } from "../types.js";
|
|
4
|
+
export function parseAIMessageToToolAction(message) {
|
|
5
|
+
const stringifiedMessageContent = typeof message.content === "string"
|
|
6
|
+
? message.content
|
|
7
|
+
: JSON.stringify(message.content);
|
|
8
|
+
let toolCalls = [];
|
|
9
|
+
if (message.tool_calls !== undefined && message.tool_calls.length > 0) {
|
|
10
|
+
toolCalls = message.tool_calls;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
if (message.additional_kwargs.tool_calls === undefined ||
|
|
14
|
+
message.additional_kwargs.tool_calls.length === 0) {
|
|
15
|
+
return {
|
|
16
|
+
returnValues: { output: message.content },
|
|
17
|
+
log: stringifiedMessageContent,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// Best effort parsing
|
|
21
|
+
for (const toolCall of message.additional_kwargs.tool_calls ?? []) {
|
|
22
|
+
const functionName = toolCall.function?.name;
|
|
23
|
+
try {
|
|
24
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
25
|
+
toolCalls.push({ name: functionName, args, id: toolCall.id });
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new OutputParserException(`Failed to parse tool arguments from chat model response. Text: "${JSON.stringify(toolCalls)}". ${e}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return toolCalls.map((toolCall, i) => {
|
|
34
|
+
const messageLog = i === 0 ? [message] : [];
|
|
35
|
+
const log = `Invoking "${toolCall.name}" with ${JSON.stringify(toolCall.args ?? {})}\n${stringifiedMessageContent}`;
|
|
36
|
+
return {
|
|
37
|
+
tool: toolCall.name,
|
|
38
|
+
toolInput: toolCall.args,
|
|
39
|
+
toolCallId: toolCall.id ?? "",
|
|
40
|
+
log,
|
|
41
|
+
messageLog,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export class ToolCallingAgentOutputParser extends AgentMultiActionOutputParser {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: ["langchain", "agents", "tool_calling"]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
static lc_name() {
|
|
56
|
+
return "ToolCallingAgentOutputParser";
|
|
57
|
+
}
|
|
58
|
+
async parse(text) {
|
|
59
|
+
throw new Error(`ToolCallingAgentOutputParser can only parse messages.\nPassed input: ${text}`);
|
|
60
|
+
}
|
|
61
|
+
async parseResult(generations) {
|
|
62
|
+
if ("message" in generations[0] && isBaseMessage(generations[0].message)) {
|
|
63
|
+
return parseAIMessageToToolAction(generations[0].message);
|
|
64
|
+
}
|
|
65
|
+
throw new Error("parseResult on ToolCallingAgentOutputParser only works on ChatGeneration output");
|
|
66
|
+
}
|
|
67
|
+
getFormatInstructions() {
|
|
68
|
+
throw new Error("getFormatInstructions not implemented inside ToolCallingAgentOutputParser.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -10,7 +10,7 @@ import { LLMChain } from "../llm_chain.js";
|
|
|
10
10
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
11
11
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
12
12
|
*/
|
|
13
|
-
export declare function createExtractionChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions>>;
|
|
13
|
+
export declare function createExtractionChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk>>;
|
|
14
14
|
/**
|
|
15
15
|
* Function that creates an extraction chain from a Zod schema. It
|
|
16
16
|
* converts the Zod schema to a JSON schema using zod-to-json-schema
|
|
@@ -19,4 +19,4 @@ export declare function createExtractionChain(schema: FunctionParameters, llm: B
|
|
|
19
19
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
20
20
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
21
21
|
*/
|
|
22
|
-
export declare function createExtractionChainFromZod(schema: z.ZodObject<any, any, any, any>, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions>>;
|
|
22
|
+
export declare function createExtractionChainFromZod(schema: z.ZodObject<any, any, any, any>, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk>>;
|
|
@@ -55,6 +55,6 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
|
|
|
55
55
|
* as well as an additional required "outputSchema" JSON Schema object.
|
|
56
56
|
* @returns OpenAPIChain
|
|
57
57
|
*/
|
|
58
|
-
export declare function createStructuredOutputChain<T extends z.AnyZodObject = z.AnyZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
58
|
+
export declare function createStructuredOutputChain<T extends z.AnyZodObject = z.AnyZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
59
59
|
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
60
|
-
export declare function createStructuredOutputChainFromZod<T extends z.AnyZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
60
|
+
export declare function createStructuredOutputChainFromZod<T extends z.AnyZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
@@ -23,7 +23,7 @@ export type TaggingChainOptions = {
|
|
|
23
23
|
* Switch to expression language: https://js.langchain.com/docs/expression_language/
|
|
24
24
|
* Will be removed in 0.2.0
|
|
25
25
|
*/
|
|
26
|
-
export declare function createTaggingChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions>>;
|
|
26
|
+
export declare function createTaggingChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk>>;
|
|
27
27
|
/**
|
|
28
28
|
* Function that creates a tagging chain from a Zod schema. It converts
|
|
29
29
|
* the Zod schema to a JSON schema using the zodToJsonSchema function and
|
|
@@ -37,4 +37,4 @@ export declare function createTaggingChain(schema: FunctionParameters, llm: Base
|
|
|
37
37
|
* Switch to expression language: https://js.langchain.com/docs/expression_language/
|
|
38
38
|
* Will be removed in 0.2.0
|
|
39
39
|
*/
|
|
40
|
-
export declare function createTaggingChainFromZod(schema: z.ZodObject<any, any, any, any>, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions>>;
|
|
40
|
+
export declare function createTaggingChainFromZod(schema: z.ZodObject<any, any, any, any>, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -1190,7 +1190,7 @@
|
|
|
1190
1190
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/langchain/",
|
|
1191
1191
|
"scripts": {
|
|
1192
1192
|
"build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
|
|
1193
|
-
"build:deps": "yarn run turbo:command build --filter=@langchain/
|
|
1193
|
+
"build:deps": "yarn run turbo:command build --filter=@langchain/openai --filter=@langchain/community --concurrency=1",
|
|
1194
1194
|
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests",
|
|
1195
1195
|
"build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
|
|
1196
1196
|
"build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
|
|
@@ -1512,9 +1512,9 @@
|
|
|
1512
1512
|
},
|
|
1513
1513
|
"dependencies": {
|
|
1514
1514
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1515
|
-
"@langchain/community": "~0.0.
|
|
1516
|
-
"@langchain/core": "~0.1.
|
|
1517
|
-
"@langchain/openai": "~0.0.
|
|
1515
|
+
"@langchain/community": "~0.0.47",
|
|
1516
|
+
"@langchain/core": "~0.1.56",
|
|
1517
|
+
"@langchain/openai": "~0.0.28",
|
|
1518
1518
|
"binary-extensions": "^2.2.0",
|
|
1519
1519
|
"js-tiktoken": "^1.0.7",
|
|
1520
1520
|
"js-yaml": "^4.1.0",
|