langchain 0.0.183 → 0.0.185
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/agents/format_scratchpad/openai_tools.cjs +1 -0
- package/agents/format_scratchpad/openai_tools.d.ts +1 -0
- package/agents/format_scratchpad/openai_tools.js +1 -0
- package/dist/agents/agent.cjs +19 -13
- package/dist/agents/agent.d.ts +16 -17
- package/dist/agents/agent.js +17 -11
- package/dist/agents/executor.d.ts +10 -16
- package/dist/agents/format_scratchpad/openai_tools.cjs +19 -0
- package/dist/agents/format_scratchpad/openai_tools.d.ts +3 -0
- package/dist/agents/format_scratchpad/openai_tools.js +15 -0
- package/dist/agents/openai/output_parser.cjs +66 -1
- package/dist/agents/openai/output_parser.d.ts +26 -2
- package/dist/agents/openai/output_parser.js +65 -1
- package/dist/agents/structured_chat/index.cjs +1 -2
- package/dist/agents/structured_chat/index.d.ts +2 -0
- package/dist/agents/structured_chat/index.js +1 -2
- package/dist/agents/toolkits/aws_sfn.d.ts +1 -4
- package/dist/agents/toolkits/conversational_retrieval/openai_functions.d.ts +1 -1
- package/dist/agents/toolkits/json/json.d.ts +1 -4
- package/dist/agents/toolkits/openapi/openapi.d.ts +1 -4
- package/dist/agents/toolkits/sql/sql.d.ts +1 -4
- package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +2 -8
- package/dist/agents/types.cjs +8 -1
- package/dist/agents/types.d.ts +11 -5
- package/dist/agents/types.js +6 -0
- package/dist/document_loaders/fs/pdf.cjs +17 -3
- package/dist/document_loaders/fs/pdf.js +17 -3
- package/dist/document_loaders/web/apify_dataset.cjs +12 -6
- package/dist/document_loaders/web/apify_dataset.d.ts +9 -6
- package/dist/document_loaders/web/apify_dataset.js +12 -6
- package/dist/document_loaders/web/pdf.cjs +17 -3
- package/dist/document_loaders/web/pdf.js +17 -3
- package/dist/document_loaders/web/puppeteer.cjs +37 -0
- package/dist/document_loaders/web/puppeteer.d.ts +17 -0
- package/dist/document_loaders/web/puppeteer.js +37 -0
- package/dist/experimental/openai_assistant/index.cjs +221 -0
- package/dist/experimental/openai_assistant/index.d.ts +36 -0
- package/dist/experimental/openai_assistant/index.js +217 -0
- package/dist/experimental/openai_assistant/schema.cjs +2 -0
- package/dist/experimental/openai_assistant/schema.d.ts +12 -0
- package/dist/experimental/openai_assistant/schema.js +1 -0
- package/dist/experimental/plan_and_execute/agent_executor.cjs +28 -2
- package/dist/experimental/plan_and_execute/agent_executor.d.ts +10 -3
- package/dist/experimental/plan_and_execute/agent_executor.js +26 -1
- package/dist/experimental/plan_and_execute/prompt.d.ts +2 -1
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/prompts/chat.cjs +22 -1
- package/dist/prompts/chat.d.ts +1 -0
- package/dist/prompts/chat.js +22 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/tools/convert_to_openai.cjs +14 -2
- package/dist/tools/convert_to_openai.d.ts +1 -0
- package/dist/tools/convert_to_openai.js +11 -0
- package/dist/tools/index.cjs +2 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/vectorstores/momento_vector_index.cjs +1 -1
- package/dist/vectorstores/momento_vector_index.js +1 -1
- package/dist/vectorstores/pinecone.cjs +4 -1
- package/dist/vectorstores/pinecone.d.ts +2 -1
- package/dist/vectorstores/pinecone.js +4 -1
- package/experimental/openai_assistant.cjs +1 -0
- package/experimental/openai_assistant.d.ts +1 -0
- package/experimental/openai_assistant.js +1 -0
- package/package.json +24 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/agents/format_scratchpad/openai_tools.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/agents/format_scratchpad/openai_tools.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/agents/format_scratchpad/openai_tools.js'
|
package/dist/agents/agent.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Agent = exports.LLMSingleActionAgent = exports.
|
|
3
|
+
exports.Agent = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.BaseAgent = void 0;
|
|
4
4
|
const serializable_js_1 = require("../load/serializable.cjs");
|
|
5
5
|
/**
|
|
6
6
|
* Error class for parse errors in LangChain. Contains information about
|
|
@@ -66,12 +66,26 @@ class BaseSingleActionAgent extends BaseAgent {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.BaseSingleActionAgent = BaseSingleActionAgent;
|
|
69
|
+
/**
|
|
70
|
+
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
71
|
+
* BaseAgent class and provides additional functionality specific to
|
|
72
|
+
* multi-action agents.
|
|
73
|
+
*/
|
|
74
|
+
class BaseMultiActionAgent extends BaseAgent {
|
|
75
|
+
_agentActionType() {
|
|
76
|
+
return "multi";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.BaseMultiActionAgent = BaseMultiActionAgent;
|
|
80
|
+
function isAgentAction(input) {
|
|
81
|
+
return !Array.isArray(input) && input?.tool !== undefined;
|
|
82
|
+
}
|
|
69
83
|
/**
|
|
70
84
|
* Class representing a single action agent which accepts runnables.
|
|
71
85
|
* Extends the BaseSingleActionAgent class and provides methods for
|
|
72
86
|
* planning agent actions with runnables.
|
|
73
87
|
*/
|
|
74
|
-
class RunnableAgent extends
|
|
88
|
+
class RunnableAgent extends BaseMultiActionAgent {
|
|
75
89
|
get inputKeys() {
|
|
76
90
|
return [];
|
|
77
91
|
}
|
|
@@ -110,21 +124,13 @@ class RunnableAgent extends BaseSingleActionAgent {
|
|
|
110
124
|
callbacks: callbackManager,
|
|
111
125
|
runName: "RunnableAgent",
|
|
112
126
|
});
|
|
127
|
+
if (isAgentAction(output)) {
|
|
128
|
+
return [output];
|
|
129
|
+
}
|
|
113
130
|
return output;
|
|
114
131
|
}
|
|
115
132
|
}
|
|
116
133
|
exports.RunnableAgent = RunnableAgent;
|
|
117
|
-
/**
|
|
118
|
-
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
119
|
-
* BaseAgent class and provides additional functionality specific to
|
|
120
|
-
* multi-action agents.
|
|
121
|
-
*/
|
|
122
|
-
class BaseMultiActionAgent extends BaseAgent {
|
|
123
|
-
_agentActionType() {
|
|
124
|
-
return "multi";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.BaseMultiActionAgent = BaseMultiActionAgent;
|
|
128
134
|
/**
|
|
129
135
|
* Class representing a single action agent using a LLMChain in LangChain.
|
|
130
136
|
* Extends the BaseSingleActionAgent class and provides methods for
|
package/dist/agents/agent.d.ts
CHANGED
|
@@ -55,23 +55,6 @@ export declare abstract class BaseSingleActionAgent extends BaseAgent {
|
|
|
55
55
|
*/
|
|
56
56
|
abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction | AgentFinish>;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Class representing a single action agent which accepts runnables.
|
|
60
|
-
* Extends the BaseSingleActionAgent class and provides methods for
|
|
61
|
-
* planning agent actions with runnables.
|
|
62
|
-
*/
|
|
63
|
-
export declare class RunnableAgent<RunInput extends ChainValues & {
|
|
64
|
-
agent_scratchpad?: string | BaseMessage[];
|
|
65
|
-
stop?: string[];
|
|
66
|
-
}, RunOutput extends AgentAction | AgentFinish> extends BaseSingleActionAgent {
|
|
67
|
-
protected lc_runnable: boolean;
|
|
68
|
-
lc_namespace: string[];
|
|
69
|
-
runnable: Runnable<RunInput, RunOutput>;
|
|
70
|
-
stop?: string[];
|
|
71
|
-
get inputKeys(): string[];
|
|
72
|
-
constructor(fields: RunnableAgentInput<RunInput, RunOutput>);
|
|
73
|
-
plan(steps: AgentStep[], inputs: RunInput, callbackManager?: CallbackManager): Promise<AgentAction | AgentFinish>;
|
|
74
|
-
}
|
|
75
58
|
/**
|
|
76
59
|
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
77
60
|
* BaseAgent class and provides additional functionality specific to
|
|
@@ -90,6 +73,22 @@ export declare abstract class BaseMultiActionAgent extends BaseAgent {
|
|
|
90
73
|
*/
|
|
91
74
|
abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction[] | AgentFinish>;
|
|
92
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Class representing a single action agent which accepts runnables.
|
|
78
|
+
* Extends the BaseSingleActionAgent class and provides methods for
|
|
79
|
+
* planning agent actions with runnables.
|
|
80
|
+
*/
|
|
81
|
+
export declare class RunnableAgent extends BaseMultiActionAgent {
|
|
82
|
+
protected lc_runnable: boolean;
|
|
83
|
+
lc_namespace: string[];
|
|
84
|
+
runnable: Runnable<ChainValues & {
|
|
85
|
+
steps: AgentStep[];
|
|
86
|
+
}, AgentAction[] | AgentAction | AgentFinish>;
|
|
87
|
+
stop?: string[];
|
|
88
|
+
get inputKeys(): string[];
|
|
89
|
+
constructor(fields: RunnableAgentInput);
|
|
90
|
+
plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction[] | AgentFinish>;
|
|
91
|
+
}
|
|
93
92
|
/**
|
|
94
93
|
* Interface for input data for creating a LLMSingleActionAgent.
|
|
95
94
|
*/
|
package/dist/agents/agent.js
CHANGED
|
@@ -61,12 +61,25 @@ export class BaseSingleActionAgent extends BaseAgent {
|
|
|
61
61
|
return "single";
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
66
|
+
* BaseAgent class and provides additional functionality specific to
|
|
67
|
+
* multi-action agents.
|
|
68
|
+
*/
|
|
69
|
+
export class BaseMultiActionAgent extends BaseAgent {
|
|
70
|
+
_agentActionType() {
|
|
71
|
+
return "multi";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isAgentAction(input) {
|
|
75
|
+
return !Array.isArray(input) && input?.tool !== undefined;
|
|
76
|
+
}
|
|
64
77
|
/**
|
|
65
78
|
* Class representing a single action agent which accepts runnables.
|
|
66
79
|
* Extends the BaseSingleActionAgent class and provides methods for
|
|
67
80
|
* planning agent actions with runnables.
|
|
68
81
|
*/
|
|
69
|
-
export class RunnableAgent extends
|
|
82
|
+
export class RunnableAgent extends BaseMultiActionAgent {
|
|
70
83
|
get inputKeys() {
|
|
71
84
|
return [];
|
|
72
85
|
}
|
|
@@ -105,19 +118,12 @@ export class RunnableAgent extends BaseSingleActionAgent {
|
|
|
105
118
|
callbacks: callbackManager,
|
|
106
119
|
runName: "RunnableAgent",
|
|
107
120
|
});
|
|
121
|
+
if (isAgentAction(output)) {
|
|
122
|
+
return [output];
|
|
123
|
+
}
|
|
108
124
|
return output;
|
|
109
125
|
}
|
|
110
126
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
113
|
-
* BaseAgent class and provides additional functionality specific to
|
|
114
|
-
* multi-action agents.
|
|
115
|
-
*/
|
|
116
|
-
export class BaseMultiActionAgent extends BaseAgent {
|
|
117
|
-
_agentActionType() {
|
|
118
|
-
return "multi";
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
127
|
/**
|
|
122
128
|
* Class representing a single action agent using a LLMChain in LangChain.
|
|
123
129
|
* Extends the BaseSingleActionAgent class and provides methods for
|
|
@@ -2,7 +2,7 @@ import { BaseChain, ChainInputs } from "../chains/base.js";
|
|
|
2
2
|
import { BaseMultiActionAgent, BaseSingleActionAgent } from "./agent.js";
|
|
3
3
|
import { StoppingMethod } from "./types.js";
|
|
4
4
|
import { SerializedLLMChain } from "../chains/serde.js";
|
|
5
|
-
import { AgentAction, AgentFinish,
|
|
5
|
+
import { AgentAction, AgentFinish, AgentStep, ChainValues } from "../schema/index.js";
|
|
6
6
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
7
7
|
import { OutputParserException } from "../schema/output_parser.js";
|
|
8
8
|
import { StructuredTool, Tool, ToolInputParsingException } from "../tools/base.js";
|
|
@@ -15,17 +15,17 @@ type ExtractToolType<T> = T extends {
|
|
|
15
15
|
* AgentExecutor. It extends ChainInputs and includes additional
|
|
16
16
|
* properties specific to agent execution.
|
|
17
17
|
*/
|
|
18
|
-
export interface AgentExecutorInput
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
agent: BaseSingleActionAgent | BaseMultiActionAgent | Runnable<RunInput, RunOutput>;
|
|
18
|
+
export interface AgentExecutorInput extends ChainInputs {
|
|
19
|
+
agent: BaseSingleActionAgent | BaseMultiActionAgent | Runnable<ChainValues & {
|
|
20
|
+
steps?: AgentStep[];
|
|
21
|
+
}, AgentAction[] | AgentAction | AgentFinish>;
|
|
23
22
|
tools: ExtractToolType<this["agent"]>[];
|
|
24
23
|
returnIntermediateSteps?: boolean;
|
|
25
24
|
maxIterations?: number;
|
|
26
25
|
earlyStoppingMethod?: StoppingMethod;
|
|
27
26
|
handleParsingErrors?: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
|
|
28
27
|
}
|
|
28
|
+
export type AgentExecutorOutput = ChainValues;
|
|
29
29
|
/**
|
|
30
30
|
* Tool that just returns the query.
|
|
31
31
|
* Used for exception tracking.
|
|
@@ -39,10 +39,7 @@ export declare class ExceptionTool extends Tool {
|
|
|
39
39
|
* A chain managing an agent using tools.
|
|
40
40
|
* @augments BaseChain
|
|
41
41
|
*/
|
|
42
|
-
export declare class AgentExecutor
|
|
43
|
-
agent_scratchpad?: string | BaseMessage[];
|
|
44
|
-
stop?: string[];
|
|
45
|
-
} = any, RunOutput extends AgentAction | AgentFinish = any> extends BaseChain {
|
|
42
|
+
export declare class AgentExecutor extends BaseChain<ChainValues, AgentExecutorOutput> {
|
|
46
43
|
static lc_name(): string;
|
|
47
44
|
get lc_namespace(): string[];
|
|
48
45
|
agent: BaseSingleActionAgent | BaseMultiActionAgent;
|
|
@@ -63,12 +60,9 @@ export declare class AgentExecutor<RunInput extends ChainValues & {
|
|
|
63
60
|
handleParsingErrors: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
|
|
64
61
|
get inputKeys(): string[];
|
|
65
62
|
get outputKeys(): string[];
|
|
66
|
-
constructor(input: AgentExecutorInput
|
|
63
|
+
constructor(input: AgentExecutorInput);
|
|
67
64
|
/** Create from agent and a list of tools. */
|
|
68
|
-
static fromAgentAndTools
|
|
69
|
-
agent_scratchpad?: string | BaseMessage[];
|
|
70
|
-
stop?: string[];
|
|
71
|
-
}, RunOutput extends AgentAction | AgentFinish>(fields: AgentExecutorInput<RunInput, RunOutput>): AgentExecutor<RunInput, RunOutput>;
|
|
65
|
+
static fromAgentAndTools(fields: AgentExecutorInput): AgentExecutor;
|
|
72
66
|
/**
|
|
73
67
|
* Method that checks if the agent execution should continue based on the
|
|
74
68
|
* number of iterations.
|
|
@@ -77,7 +71,7 @@ export declare class AgentExecutor<RunInput extends ChainValues & {
|
|
|
77
71
|
*/
|
|
78
72
|
private shouldContinue;
|
|
79
73
|
/** @ignore */
|
|
80
|
-
_call(inputs: ChainValues, runManager?: CallbackManagerForChainRun): Promise<
|
|
74
|
+
_call(inputs: ChainValues, runManager?: CallbackManagerForChainRun): Promise<AgentExecutorOutput>;
|
|
81
75
|
_chainType(): "agent_executor";
|
|
82
76
|
serialize(): SerializedLLMChain;
|
|
83
77
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatToOpenAIToolMessages = void 0;
|
|
4
|
+
const index_js_1 = require("../../schema/index.cjs");
|
|
5
|
+
function formatToOpenAIToolMessages(steps) {
|
|
6
|
+
return steps.flatMap(({ action, observation }) => {
|
|
7
|
+
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
8
|
+
const log = action.messageLog;
|
|
9
|
+
return log.concat(new index_js_1.ToolMessage({
|
|
10
|
+
content: observation,
|
|
11
|
+
tool_call_id: action.toolCallId,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return [new index_js_1.AIMessage(action.log)];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.formatToOpenAIToolMessages = formatToOpenAIToolMessages;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ToolMessage, AIMessage, } from "../../schema/index.js";
|
|
2
|
+
export function formatToOpenAIToolMessages(steps) {
|
|
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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIFunctionsAgentOutputParser = void 0;
|
|
3
|
+
exports.OpenAIToolsAgentOutputParser = exports.OpenAIFunctionsAgentOutputParser = void 0;
|
|
4
4
|
const index_js_1 = require("../../schema/index.cjs");
|
|
5
5
|
const types_js_1 = require("../types.cjs");
|
|
6
6
|
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
@@ -66,3 +66,68 @@ class OpenAIFunctionsAgentOutputParser extends types_js_1.AgentActionOutputParse
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.OpenAIFunctionsAgentOutputParser = OpenAIFunctionsAgentOutputParser;
|
|
69
|
+
class OpenAIToolsAgentOutputParser extends types_js_1.AgentMultiActionOutputParser {
|
|
70
|
+
constructor() {
|
|
71
|
+
super(...arguments);
|
|
72
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: ["langchain", "agents", "openai"]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
static lc_name() {
|
|
80
|
+
return "OpenAIToolsAgentOutputParser";
|
|
81
|
+
}
|
|
82
|
+
async parse(text) {
|
|
83
|
+
throw new Error(`OpenAIFunctionsAgentOutputParser can only parse messages.\nPassed input: ${text}`);
|
|
84
|
+
}
|
|
85
|
+
async parseResult(generations) {
|
|
86
|
+
if ("message" in generations[0] && (0, index_js_1.isBaseMessage)(generations[0].message)) {
|
|
87
|
+
return this.parseAIMessage(generations[0].message);
|
|
88
|
+
}
|
|
89
|
+
throw new Error("parseResult on OpenAIFunctionsAgentOutputParser only works on ChatGeneration output");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parses the output message into a ToolsAgentAction[] or AgentFinish
|
|
93
|
+
* object.
|
|
94
|
+
* @param message The BaseMessage to parse.
|
|
95
|
+
* @returns A ToolsAgentAction[] or AgentFinish object.
|
|
96
|
+
*/
|
|
97
|
+
parseAIMessage(message) {
|
|
98
|
+
if (message.content && typeof message.content !== "string") {
|
|
99
|
+
throw new Error("This agent cannot parse non-string model responses.");
|
|
100
|
+
}
|
|
101
|
+
if (message.additional_kwargs.tool_calls) {
|
|
102
|
+
const toolCalls = message.additional_kwargs.tool_calls;
|
|
103
|
+
try {
|
|
104
|
+
return toolCalls.map((toolCall, i) => {
|
|
105
|
+
const toolInput = toolCall.function.arguments
|
|
106
|
+
? JSON.parse(toolCall.function.arguments)
|
|
107
|
+
: {};
|
|
108
|
+
const messageLog = i === 0 ? [message] : [];
|
|
109
|
+
return {
|
|
110
|
+
tool: toolCall.function.name,
|
|
111
|
+
toolInput,
|
|
112
|
+
toolCallId: toolCall.id,
|
|
113
|
+
log: `Invoking "${toolCall.function.name}" with ${toolCall.function.arguments ?? "{}"}\n${message.content}`,
|
|
114
|
+
messageLog,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new output_parser_js_1.OutputParserException(`Failed to parse tool arguments from chat model response. Text: "${JSON.stringify(toolCalls)}". ${error}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return {
|
|
124
|
+
returnValues: { output: message.content },
|
|
125
|
+
log: message.content,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
getFormatInstructions() {
|
|
130
|
+
throw new Error("getFormatInstructions not implemented inside OpenAIToolsAgentOutputParser.");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.OpenAIToolsAgentOutputParser = OpenAIToolsAgentOutputParser;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AgentAction, AgentFinish, BaseMessage, ChatGeneration } from "../../schema/index.js";
|
|
2
|
-
import { AgentActionOutputParser } from "../types.js";
|
|
1
|
+
import { AgentAction, AgentFinish, AgentStep, BaseMessage, ChatGeneration } from "../../schema/index.js";
|
|
2
|
+
import { AgentActionOutputParser, AgentMultiActionOutputParser } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Type that represents an agent action with an optional message log.
|
|
5
5
|
*/
|
|
@@ -20,3 +20,27 @@ export declare class OpenAIFunctionsAgentOutputParser extends AgentActionOutputP
|
|
|
20
20
|
parseAIMessage(message: BaseMessage): FunctionsAgentAction | AgentFinish;
|
|
21
21
|
getFormatInstructions(): string;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Type that represents an agent action with an optional message log.
|
|
25
|
+
*/
|
|
26
|
+
export type ToolsAgentAction = AgentAction & {
|
|
27
|
+
toolCallId: string;
|
|
28
|
+
messageLog?: BaseMessage[];
|
|
29
|
+
};
|
|
30
|
+
export type ToolsAgentStep = AgentStep & {
|
|
31
|
+
action: ToolsAgentAction;
|
|
32
|
+
};
|
|
33
|
+
export declare class OpenAIToolsAgentOutputParser extends AgentMultiActionOutputParser {
|
|
34
|
+
lc_namespace: string[];
|
|
35
|
+
static lc_name(): string;
|
|
36
|
+
parse(text: string): Promise<AgentAction[] | AgentFinish>;
|
|
37
|
+
parseResult(generations: ChatGeneration[]): Promise<AgentFinish | ToolsAgentAction[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Parses the output message into a ToolsAgentAction[] or AgentFinish
|
|
40
|
+
* object.
|
|
41
|
+
* @param message The BaseMessage to parse.
|
|
42
|
+
* @returns A ToolsAgentAction[] or AgentFinish object.
|
|
43
|
+
*/
|
|
44
|
+
parseAIMessage(message: BaseMessage): ToolsAgentAction[] | AgentFinish;
|
|
45
|
+
getFormatInstructions(): string;
|
|
46
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isBaseMessage, } from "../../schema/index.js";
|
|
2
|
-
import { AgentActionOutputParser } from "../types.js";
|
|
2
|
+
import { AgentActionOutputParser, AgentMultiActionOutputParser, } from "../types.js";
|
|
3
3
|
import { OutputParserException } from "../../schema/output_parser.js";
|
|
4
4
|
export class OpenAIFunctionsAgentOutputParser extends AgentActionOutputParser {
|
|
5
5
|
constructor() {
|
|
@@ -62,3 +62,67 @@ export class OpenAIFunctionsAgentOutputParser extends AgentActionOutputParser {
|
|
|
62
62
|
throw new Error("getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.");
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
export class OpenAIToolsAgentOutputParser extends AgentMultiActionOutputParser {
|
|
66
|
+
constructor() {
|
|
67
|
+
super(...arguments);
|
|
68
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: ["langchain", "agents", "openai"]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
static lc_name() {
|
|
76
|
+
return "OpenAIToolsAgentOutputParser";
|
|
77
|
+
}
|
|
78
|
+
async parse(text) {
|
|
79
|
+
throw new Error(`OpenAIFunctionsAgentOutputParser can only parse messages.\nPassed input: ${text}`);
|
|
80
|
+
}
|
|
81
|
+
async parseResult(generations) {
|
|
82
|
+
if ("message" in generations[0] && isBaseMessage(generations[0].message)) {
|
|
83
|
+
return this.parseAIMessage(generations[0].message);
|
|
84
|
+
}
|
|
85
|
+
throw new Error("parseResult on OpenAIFunctionsAgentOutputParser only works on ChatGeneration output");
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parses the output message into a ToolsAgentAction[] or AgentFinish
|
|
89
|
+
* object.
|
|
90
|
+
* @param message The BaseMessage to parse.
|
|
91
|
+
* @returns A ToolsAgentAction[] or AgentFinish object.
|
|
92
|
+
*/
|
|
93
|
+
parseAIMessage(message) {
|
|
94
|
+
if (message.content && typeof message.content !== "string") {
|
|
95
|
+
throw new Error("This agent cannot parse non-string model responses.");
|
|
96
|
+
}
|
|
97
|
+
if (message.additional_kwargs.tool_calls) {
|
|
98
|
+
const toolCalls = message.additional_kwargs.tool_calls;
|
|
99
|
+
try {
|
|
100
|
+
return toolCalls.map((toolCall, i) => {
|
|
101
|
+
const toolInput = toolCall.function.arguments
|
|
102
|
+
? JSON.parse(toolCall.function.arguments)
|
|
103
|
+
: {};
|
|
104
|
+
const messageLog = i === 0 ? [message] : [];
|
|
105
|
+
return {
|
|
106
|
+
tool: toolCall.function.name,
|
|
107
|
+
toolInput,
|
|
108
|
+
toolCallId: toolCall.id,
|
|
109
|
+
log: `Invoking "${toolCall.function.name}" with ${toolCall.function.arguments ?? "{}"}\n${message.content}`,
|
|
110
|
+
messageLog,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw new OutputParserException(`Failed to parse tool arguments from chat model response. Text: "${JSON.stringify(toolCalls)}". ${error}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return {
|
|
120
|
+
returnValues: { output: message.content },
|
|
121
|
+
log: message.content,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
getFormatInstructions() {
|
|
126
|
+
throw new Error("getFormatInstructions not implemented inside OpenAIToolsAgentOutputParser.");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -102,9 +102,8 @@ class StructuredChatAgent extends agent_js_1.Agent {
|
|
|
102
102
|
* @param args.memoryPrompts List of historical prompts from memory.
|
|
103
103
|
*/
|
|
104
104
|
static createPrompt(tools, args) {
|
|
105
|
-
const { prefix = prompt_js_2.PREFIX, suffix = prompt_js_2.SUFFIX, inputVariables = ["input", "agent_scratchpad"], memoryPrompts = [], } = args ?? {};
|
|
105
|
+
const { prefix = prompt_js_2.PREFIX, suffix = prompt_js_2.SUFFIX, inputVariables = ["input", "agent_scratchpad"], humanMessageTemplate = "{input}\n\n{agent_scratchpad}", memoryPrompts = [], } = args ?? {};
|
|
106
106
|
const template = [prefix, prompt_js_2.FORMAT_INSTRUCTIONS, suffix].join("\n\n");
|
|
107
|
-
const humanMessageTemplate = "{input}\n\n{agent_scratchpad}";
|
|
108
107
|
const messages = [
|
|
109
108
|
new chat_js_1.SystemMessagePromptTemplate(new prompt_js_1.PromptTemplate({
|
|
110
109
|
template,
|
|
@@ -15,6 +15,8 @@ export interface StructuredChatCreatePromptArgs {
|
|
|
15
15
|
suffix?: string;
|
|
16
16
|
/** String to put before the list of tools. */
|
|
17
17
|
prefix?: string;
|
|
18
|
+
/** String to use directly as the human message template. */
|
|
19
|
+
humanMessageTemplate?: string;
|
|
18
20
|
/** List of input variables the final prompt will expect. */
|
|
19
21
|
inputVariables?: string[];
|
|
20
22
|
/** List of historical prompts from memory. */
|
|
@@ -99,9 +99,8 @@ export class StructuredChatAgent extends Agent {
|
|
|
99
99
|
* @param args.memoryPrompts List of historical prompts from memory.
|
|
100
100
|
*/
|
|
101
101
|
static createPrompt(tools, args) {
|
|
102
|
-
const { prefix = PREFIX, suffix = SUFFIX, inputVariables = ["input", "agent_scratchpad"], memoryPrompts = [], } = args ?? {};
|
|
102
|
+
const { prefix = PREFIX, suffix = SUFFIX, inputVariables = ["input", "agent_scratchpad"], humanMessageTemplate = "{input}\n\n{agent_scratchpad}", memoryPrompts = [], } = args ?? {};
|
|
103
103
|
const template = [prefix, FORMAT_INSTRUCTIONS, suffix].join("\n\n");
|
|
104
|
-
const humanMessageTemplate = "{input}\n\n{agent_scratchpad}";
|
|
105
104
|
const messages = [
|
|
106
105
|
new SystemMessagePromptTemplate(new PromptTemplate({
|
|
107
106
|
template,
|
|
@@ -30,7 +30,4 @@ export declare class AWSSfnToolkit extends Toolkit {
|
|
|
30
30
|
asl: string;
|
|
31
31
|
constructor(args: AWSSfnToolkitArgs & SfnConfig);
|
|
32
32
|
}
|
|
33
|
-
export declare function createAWSSfnAgent(llm: BaseLanguageModel, toolkit: AWSSfnToolkit, args?: AWSSfnCreatePromptArgs): AgentExecutor
|
|
34
|
-
agent_scratchpad?: string | import("../../schema/index.js").BaseMessage[] | undefined;
|
|
35
|
-
stop?: string[] | undefined;
|
|
36
|
-
}, import("../../schema/index.js").AgentAction | import("../../schema/index.js").AgentFinish>;
|
|
33
|
+
export declare function createAWSSfnAgent(llm: BaseLanguageModel, toolkit: AWSSfnToolkit, args?: AWSSfnCreatePromptArgs): AgentExecutor;
|
|
@@ -17,4 +17,4 @@ export type ConversationalRetrievalAgentOptions = {
|
|
|
17
17
|
* @param options Optional ConversationalRetrievalAgentOptions to customize the agent.
|
|
18
18
|
* @returns A Promise that resolves to an initialized AgentExecutor.
|
|
19
19
|
*/
|
|
20
|
-
export declare function createConversationalRetrievalAgent(llm: ChatOpenAI, tools: StructuredTool[], options?: ConversationalRetrievalAgentOptions): Promise<import("../../executor.js").AgentExecutor
|
|
20
|
+
export declare function createConversationalRetrievalAgent(llm: ChatOpenAI, tools: StructuredTool[], options?: ConversationalRetrievalAgentOptions): Promise<import("../../executor.js").AgentExecutor>;
|
|
@@ -24,7 +24,4 @@ export declare class JsonToolkit extends Toolkit {
|
|
|
24
24
|
* @param args Optional prompt arguments used to create the JSON agent.
|
|
25
25
|
* @returns An AgentExecutor for executing the created JSON agent with the tools.
|
|
26
26
|
*/
|
|
27
|
-
export declare function createJsonAgent(llm: BaseLanguageModel, toolkit: JsonToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor
|
|
28
|
-
agent_scratchpad?: string | import("../../../schema/index.js").BaseMessage[] | undefined;
|
|
29
|
-
stop?: string[] | undefined;
|
|
30
|
-
}, import("../../../schema/index.js").AgentAction | import("../../../schema/index.js").AgentFinish>;
|
|
27
|
+
export declare function createJsonAgent(llm: BaseLanguageModel, toolkit: JsonToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor;
|
|
@@ -41,7 +41,4 @@ export declare class OpenApiToolkit extends RequestsToolkit {
|
|
|
41
41
|
*
|
|
42
42
|
* @link See https://js.langchain.com/docs/security for more information.
|
|
43
43
|
*/
|
|
44
|
-
export declare function createOpenApiAgent(llm: BaseLanguageModel, openApiToolkit: OpenApiToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor
|
|
45
|
-
agent_scratchpad?: string | import("../../../schema/index.js").BaseMessage[] | undefined;
|
|
46
|
-
stop?: string[] | undefined;
|
|
47
|
-
}, import("../../../schema/index.js").AgentAction | import("../../../schema/index.js").AgentFinish>;
|
|
44
|
+
export declare function createOpenApiAgent(llm: BaseLanguageModel, openApiToolkit: OpenApiToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor;
|
|
@@ -22,7 +22,4 @@ export declare class SqlToolkit extends Toolkit {
|
|
|
22
22
|
dialect: string;
|
|
23
23
|
constructor(db: SqlDatabase, llm?: BaseLanguageModel);
|
|
24
24
|
}
|
|
25
|
-
export declare function createSqlAgent(llm: BaseLanguageModel, toolkit: SqlToolkit, args?: SqlCreatePromptArgs): AgentExecutor
|
|
26
|
-
agent_scratchpad?: string | import("../../../schema/index.js").BaseMessage[] | undefined;
|
|
27
|
-
stop?: string[] | undefined;
|
|
28
|
-
}, import("../../../schema/index.js").AgentAction | import("../../../schema/index.js").AgentFinish>;
|
|
25
|
+
export declare function createSqlAgent(llm: BaseLanguageModel, toolkit: SqlToolkit, args?: SqlCreatePromptArgs): AgentExecutor;
|
|
@@ -34,11 +34,5 @@ export declare class VectorStoreRouterToolkit extends Toolkit {
|
|
|
34
34
|
llm: BaseLanguageModel;
|
|
35
35
|
constructor(vectorStoreInfos: VectorStoreInfo[], llm: BaseLanguageModel);
|
|
36
36
|
}
|
|
37
|
-
export declare function createVectorStoreAgent(llm: BaseLanguageModel, toolkit: VectorStoreToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor
|
|
38
|
-
|
|
39
|
-
stop?: string[] | undefined;
|
|
40
|
-
}, import("../../../schema/index.js").AgentAction | import("../../../schema/index.js").AgentFinish>;
|
|
41
|
-
export declare function createVectorStoreRouterAgent(llm: BaseLanguageModel, toolkit: VectorStoreRouterToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor<import("../../../schema/index.js").ChainValues & {
|
|
42
|
-
agent_scratchpad?: string | import("../../../schema/index.js").BaseMessage[] | undefined;
|
|
43
|
-
stop?: string[] | undefined;
|
|
44
|
-
}, import("../../../schema/index.js").AgentAction | import("../../../schema/index.js").AgentFinish>;
|
|
37
|
+
export declare function createVectorStoreAgent(llm: BaseLanguageModel, toolkit: VectorStoreToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor;
|
|
38
|
+
export declare function createVectorStoreRouterAgent(llm: BaseLanguageModel, toolkit: VectorStoreRouterToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor;
|
package/dist/agents/types.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentActionOutputParser = void 0;
|
|
3
|
+
exports.AgentMultiActionOutputParser = exports.AgentActionOutputParser = void 0;
|
|
4
4
|
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
5
5
|
/**
|
|
6
6
|
* Abstract class representing an output parser specifically for agent
|
|
@@ -10,3 +10,10 @@ const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
|
10
10
|
class AgentActionOutputParser extends output_parser_js_1.BaseOutputParser {
|
|
11
11
|
}
|
|
12
12
|
exports.AgentActionOutputParser = AgentActionOutputParser;
|
|
13
|
+
/**
|
|
14
|
+
* Abstract class representing an output parser specifically for agents
|
|
15
|
+
* that return multiple actions.
|
|
16
|
+
*/
|
|
17
|
+
class AgentMultiActionOutputParser extends output_parser_js_1.BaseOutputParser {
|
|
18
|
+
}
|
|
19
|
+
exports.AgentMultiActionOutputParser = AgentMultiActionOutputParser;
|
package/dist/agents/types.d.ts
CHANGED
|
@@ -17,11 +17,11 @@ export interface AgentInput {
|
|
|
17
17
|
* Interface defining the input for creating an agent that uses runnables.
|
|
18
18
|
* It includes the Runnable instance, and an optional list of stop strings.
|
|
19
19
|
*/
|
|
20
|
-
export interface RunnableAgentInput
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
export interface RunnableAgentInput {
|
|
21
|
+
runnable: Runnable<ChainValues & {
|
|
22
|
+
agent_scratchpad?: string | BaseMessage[];
|
|
23
|
+
stop?: string[];
|
|
24
|
+
}, AgentAction[] | AgentAction | AgentFinish>;
|
|
25
25
|
stop?: string[];
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
@@ -31,6 +31,12 @@ export interface RunnableAgentInput<RunInput extends ChainValues & {
|
|
|
31
31
|
*/
|
|
32
32
|
export declare abstract class AgentActionOutputParser extends BaseOutputParser<AgentAction | AgentFinish> {
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Abstract class representing an output parser specifically for agents
|
|
36
|
+
* that return multiple actions.
|
|
37
|
+
*/
|
|
38
|
+
export declare abstract class AgentMultiActionOutputParser extends BaseOutputParser<AgentAction[] | AgentFinish> {
|
|
39
|
+
}
|
|
34
40
|
/**
|
|
35
41
|
* Type representing the stopping method for an agent. It can be either
|
|
36
42
|
* 'force' or 'generate'.
|
package/dist/agents/types.js
CHANGED
|
@@ -6,3 +6,9 @@ import { BaseOutputParser } from "../schema/output_parser.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export class AgentActionOutputParser extends BaseOutputParser {
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Abstract class representing an output parser specifically for agents
|
|
11
|
+
* that return multiple actions.
|
|
12
|
+
*/
|
|
13
|
+
export class AgentMultiActionOutputParser extends BaseOutputParser {
|
|
14
|
+
}
|