langchain 0.0.169 → 0.0.171
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/README.md +2 -2
- package/agents/format_scratchpad.cjs +1 -0
- package/agents/format_scratchpad.d.ts +1 -0
- package/agents/format_scratchpad.js +1 -0
- package/chat_models/llama_cpp.cjs +1 -0
- package/chat_models/llama_cpp.d.ts +1 -0
- package/chat_models/llama_cpp.js +1 -0
- package/dist/agents/agent.cjs +49 -1
- package/dist/agents/agent.d.ts +19 -1
- package/dist/agents/agent.js +47 -0
- package/dist/agents/executor.cjs +10 -1
- package/dist/agents/executor.d.ts +22 -8
- package/dist/agents/executor.js +11 -2
- package/dist/agents/format_scratchpad.cjs +25 -0
- package/dist/agents/format_scratchpad.d.ts +10 -0
- package/dist/agents/format_scratchpad.js +21 -0
- package/dist/agents/toolkits/aws_sfn.d.ts +4 -1
- package/dist/agents/toolkits/conversational_retrieval/openai_functions.d.ts +1 -1
- package/dist/agents/toolkits/json/json.d.ts +4 -1
- package/dist/agents/toolkits/openapi/openapi.cjs +8 -0
- package/dist/agents/toolkits/openapi/openapi.d.ts +12 -1
- package/dist/agents/toolkits/openapi/openapi.js +8 -0
- package/dist/agents/toolkits/sql/sql.d.ts +4 -1
- package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +8 -2
- package/dist/agents/types.d.ts +13 -1
- package/dist/chains/sql_db/sql_db_chain.cjs +11 -0
- package/dist/chains/sql_db/sql_db_chain.d.ts +11 -0
- package/dist/chains/sql_db/sql_db_chain.js +11 -0
- package/dist/chat_models/baiduwenxin.cjs +12 -1
- package/dist/chat_models/baiduwenxin.d.ts +3 -1
- package/dist/chat_models/baiduwenxin.js +12 -1
- package/dist/chat_models/llama_cpp.cjs +243 -0
- package/dist/chat_models/llama_cpp.d.ts +94 -0
- package/dist/chat_models/llama_cpp.js +239 -0
- package/dist/document_loaders/web/assemblyai.cjs +63 -114
- package/dist/document_loaders/web/assemblyai.d.ts +38 -57
- package/dist/document_loaders/web/assemblyai.js +63 -100
- package/dist/document_loaders/web/pdf.cjs +23 -5
- package/dist/document_loaders/web/pdf.d.ts +9 -1
- package/dist/document_loaders/web/pdf.js +20 -2
- package/dist/graphs/neo4j_graph.cjs +14 -0
- package/dist/graphs/neo4j_graph.d.ts +14 -0
- package/dist/graphs/neo4j_graph.js +14 -0
- package/dist/llms/googlepalm.cjs +3 -0
- package/dist/llms/googlepalm.js +3 -0
- package/dist/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/load/import_map.cjs +3 -2
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/retrievers/parent_document.cjs +22 -2
- package/dist/retrievers/parent_document.d.ts +8 -1
- package/dist/retrievers/parent_document.js +22 -2
- package/dist/retrievers/time_weighted.cjs +1 -1
- package/dist/retrievers/time_weighted.d.ts +1 -1
- package/dist/retrievers/time_weighted.js +1 -1
- package/dist/schema/runnable/base.cjs +4 -1
- package/dist/schema/runnable/base.d.ts +1 -0
- package/dist/schema/runnable/base.js +4 -1
- package/dist/schema/runnable/passthrough.cjs +35 -1
- package/dist/schema/runnable/passthrough.d.ts +11 -1
- package/dist/schema/runnable/passthrough.js +34 -1
- package/dist/sql_db.cjs +14 -0
- package/dist/sql_db.d.ts +14 -0
- package/dist/sql_db.js +14 -0
- package/dist/storage/ioredis.cjs +2 -1
- package/dist/storage/ioredis.js +2 -1
- package/dist/storage/upstash_redis.cjs +155 -0
- package/dist/storage/upstash_redis.d.ts +59 -0
- package/dist/storage/upstash_redis.js +151 -0
- package/dist/storage/vercel_kv.cjs +2 -1
- package/dist/storage/vercel_kv.js +2 -1
- package/dist/types/assemblyai-types.cjs +0 -150
- package/dist/types/assemblyai-types.d.ts +4 -670
- package/dist/types/assemblyai-types.js +1 -149
- package/dist/util/stream.cjs +3 -0
- package/dist/util/stream.js +3 -0
- package/dist/vectorstores/cassandra.cjs +25 -4
- package/dist/vectorstores/cassandra.d.ts +11 -1
- package/dist/vectorstores/cassandra.js +25 -4
- package/dist/vectorstores/momento_vector_index.cjs +3 -15
- package/dist/vectorstores/momento_vector_index.d.ts +0 -8
- package/dist/vectorstores/momento_vector_index.js +3 -15
- package/dist/vectorstores/neo4j_vector.cjs +14 -0
- package/dist/vectorstores/neo4j_vector.d.ts +14 -0
- package/dist/vectorstores/neo4j_vector.js +14 -0
- package/dist/vectorstores/pgvector.cjs +1 -1
- package/dist/vectorstores/pgvector.js +1 -1
- package/package.json +37 -8
- package/storage/upstash_redis.cjs +1 -0
- package/storage/upstash_redis.d.ts +1 -0
- package/storage/upstash_redis.js +1 -0
- package/dist/util/assemblyai-client.cjs +0 -173
- package/dist/util/assemblyai-client.d.ts +0 -63
- package/dist/util/assemblyai-client.js +0 -170
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/langchain-ai/langchainjs/actions/workflows/ci.yml)  [](https://opensource.org/licenses/MIT) [](https://twitter.com/langchainai) [](https://discord.gg/6adMQxSpJS) [](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/langchain-ai/langchainjs)
|
|
6
6
|
[<img src="https://github.com/codespaces/badge.svg" title="Open in Github Codespace" width="150" height="20">](https://codespaces.new/hwchase17/langchainjs)
|
|
7
7
|
|
|
8
|
-
Looking for the Python version? Check out [LangChain](https://github.com/
|
|
8
|
+
Looking for the Python version? Check out [LangChain](https://github.com/langchain-ai/langchain).
|
|
9
9
|
|
|
10
10
|
To help you ship LangChain apps to production faster, check out [LangSmith](https://smith.langchain.com).
|
|
11
11
|
[LangSmith](https://smith.langchain.com) is a unified developer platform for building, testing, and monitoring LLM applications.
|
|
@@ -45,7 +45,7 @@ For full documentation of prompts, chains, agents and more, please see [here](ht
|
|
|
45
45
|
|
|
46
46
|
## Relationship with Python LangChain
|
|
47
47
|
|
|
48
|
-
This is built to integrate as seamlessly as possible with the [LangChain Python package](https://github.com/
|
|
48
|
+
This is built to integrate as seamlessly as possible with the [LangChain Python package](https://github.com/langchain-ai/langchain). Specifically, this means all objects (prompts, LLMs, chains, etc) are designed in a way where they can be serialized and shared between languages.
|
|
49
49
|
|
|
50
50
|
The [LangChainHub](https://github.com/hwchase17/langchain-hub) is a central place for the serialized versions of these prompts, chains, and agents.
|
|
51
51
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/agents/format_scratchpad.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/agents/format_scratchpad.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/agents/format_scratchpad.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chat_models/llama_cpp.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/llama_cpp.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/llama_cpp.js'
|
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.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.BaseAgent = void 0;
|
|
3
|
+
exports.Agent = exports.LLMSingleActionAgent = exports.BaseMultiActionAgent = exports.RunnableAgent = 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,6 +66,54 @@ class BaseSingleActionAgent extends BaseAgent {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.BaseSingleActionAgent = BaseSingleActionAgent;
|
|
69
|
+
/**
|
|
70
|
+
* Class representing a single action agent which accepts runnables.
|
|
71
|
+
* Extends the BaseSingleActionAgent class and provides methods for
|
|
72
|
+
* planning agent actions with runnables.
|
|
73
|
+
*/
|
|
74
|
+
class RunnableAgent extends BaseSingleActionAgent {
|
|
75
|
+
get inputKeys() {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
constructor(fields) {
|
|
79
|
+
super();
|
|
80
|
+
Object.defineProperty(this, "lc_runnable", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: true
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: ["langchain", "agents", "runnable"]
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this, "runnable", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: void 0
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(this, "stop", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: void 0
|
|
103
|
+
});
|
|
104
|
+
this.runnable = fields.runnable;
|
|
105
|
+
this.stop = fields.stop;
|
|
106
|
+
}
|
|
107
|
+
async plan(steps, inputs, callbackManager) {
|
|
108
|
+
const invokeInput = { ...inputs, steps };
|
|
109
|
+
const output = await this.runnable.invoke(invokeInput, {
|
|
110
|
+
callbacks: callbackManager,
|
|
111
|
+
runName: "RunnableAgent",
|
|
112
|
+
});
|
|
113
|
+
return output;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.RunnableAgent = RunnableAgent;
|
|
69
117
|
/**
|
|
70
118
|
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
71
119
|
* BaseAgent class and provides additional functionality specific to
|
package/dist/agents/agent.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { BasePromptTemplate } from "../prompts/base.js";
|
|
|
5
5
|
import { AgentAction, AgentFinish, AgentStep, BaseMessage, ChainValues } from "../schema/index.js";
|
|
6
6
|
import { Serializable } from "../load/serializable.js";
|
|
7
7
|
import { StructuredTool, Tool } from "../tools/base.js";
|
|
8
|
-
import { AgentActionOutputParser, AgentInput, SerializedAgent, StoppingMethod } from "./types.js";
|
|
8
|
+
import { AgentActionOutputParser, AgentInput, RunnableAgentInput, SerializedAgent, StoppingMethod } from "./types.js";
|
|
9
|
+
import { Runnable } from "../schema/runnable/base.js";
|
|
9
10
|
/**
|
|
10
11
|
* Record type for arguments passed to output parsers.
|
|
11
12
|
*/
|
|
@@ -54,6 +55,23 @@ export declare abstract class BaseSingleActionAgent extends BaseAgent {
|
|
|
54
55
|
*/
|
|
55
56
|
abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction | AgentFinish>;
|
|
56
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
|
+
}
|
|
57
75
|
/**
|
|
58
76
|
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
59
77
|
* BaseAgent class and provides additional functionality specific to
|
package/dist/agents/agent.js
CHANGED
|
@@ -61,6 +61,53 @@ export class BaseSingleActionAgent extends BaseAgent {
|
|
|
61
61
|
return "single";
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Class representing a single action agent which accepts runnables.
|
|
66
|
+
* Extends the BaseSingleActionAgent class and provides methods for
|
|
67
|
+
* planning agent actions with runnables.
|
|
68
|
+
*/
|
|
69
|
+
export class RunnableAgent extends BaseSingleActionAgent {
|
|
70
|
+
get inputKeys() {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
constructor(fields) {
|
|
74
|
+
super();
|
|
75
|
+
Object.defineProperty(this, "lc_runnable", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: true
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: ["langchain", "agents", "runnable"]
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this, "runnable", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: void 0
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(this, "stop", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: void 0
|
|
98
|
+
});
|
|
99
|
+
this.runnable = fields.runnable;
|
|
100
|
+
this.stop = fields.stop;
|
|
101
|
+
}
|
|
102
|
+
async plan(steps, inputs, callbackManager) {
|
|
103
|
+
const invokeInput = { ...inputs, steps };
|
|
104
|
+
const output = await this.runnable.invoke(invokeInput, {
|
|
105
|
+
callbacks: callbackManager,
|
|
106
|
+
runName: "RunnableAgent",
|
|
107
|
+
});
|
|
108
|
+
return output;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
64
111
|
/**
|
|
65
112
|
* Abstract base class for multi-action agents in LangChain. Extends the
|
|
66
113
|
* BaseAgent class and provides additional functionality specific to
|
package/dist/agents/executor.cjs
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentExecutor = exports.ExceptionTool = void 0;
|
|
4
4
|
const base_js_1 = require("../chains/base.cjs");
|
|
5
|
+
const agent_js_1 = require("./agent.cjs");
|
|
5
6
|
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
6
7
|
const base_js_2 = require("../tools/base.cjs");
|
|
8
|
+
const base_js_3 = require("../schema/runnable/base.cjs");
|
|
7
9
|
/**
|
|
8
10
|
* Tool that just returns the query.
|
|
9
11
|
* Used for exception tracking.
|
|
@@ -47,6 +49,13 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
47
49
|
return this.agent.returnValues;
|
|
48
50
|
}
|
|
49
51
|
constructor(input) {
|
|
52
|
+
let agent;
|
|
53
|
+
if (base_js_3.Runnable.isRunnable(input.agent)) {
|
|
54
|
+
agent = new agent_js_1.RunnableAgent({ runnable: input.agent });
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
agent = input.agent;
|
|
58
|
+
}
|
|
50
59
|
super(input);
|
|
51
60
|
Object.defineProperty(this, "agent", {
|
|
52
61
|
enumerable: true,
|
|
@@ -94,7 +103,7 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
94
103
|
writable: true,
|
|
95
104
|
value: false
|
|
96
105
|
});
|
|
97
|
-
this.agent =
|
|
106
|
+
this.agent = agent;
|
|
98
107
|
this.tools = input.tools;
|
|
99
108
|
this.handleParsingErrors =
|
|
100
109
|
input.handleParsingErrors ?? this.handleParsingErrors;
|
|
@@ -2,18 +2,25 @@ 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 { ChainValues } from "../schema/index.js";
|
|
5
|
+
import { AgentAction, AgentFinish, BaseMessage, ChainValues } from "../schema/index.js";
|
|
6
6
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
7
7
|
import { OutputParserException } from "../schema/output_parser.js";
|
|
8
|
-
import { Tool, ToolInputParsingException } from "../tools/base.js";
|
|
8
|
+
import { StructuredTool, Tool, ToolInputParsingException } from "../tools/base.js";
|
|
9
|
+
import { Runnable } from "../schema/runnable/base.js";
|
|
10
|
+
type ExtractToolType<T> = T extends {
|
|
11
|
+
ToolType: infer Tool;
|
|
12
|
+
} ? Tool : StructuredTool;
|
|
9
13
|
/**
|
|
10
14
|
* Interface defining the structure of input data for creating an
|
|
11
15
|
* AgentExecutor. It extends ChainInputs and includes additional
|
|
12
16
|
* properties specific to agent execution.
|
|
13
17
|
*/
|
|
14
|
-
export interface AgentExecutorInput extends
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
export interface AgentExecutorInput<RunInput extends ChainValues & {
|
|
19
|
+
agent_scratchpad?: string | BaseMessage[];
|
|
20
|
+
stop?: string[];
|
|
21
|
+
} = any, RunOutput extends AgentAction | AgentFinish = any> extends ChainInputs {
|
|
22
|
+
agent: BaseSingleActionAgent | BaseMultiActionAgent | Runnable<RunInput, RunOutput>;
|
|
23
|
+
tools: ExtractToolType<this["agent"]>[];
|
|
17
24
|
returnIntermediateSteps?: boolean;
|
|
18
25
|
maxIterations?: number;
|
|
19
26
|
earlyStoppingMethod?: StoppingMethod;
|
|
@@ -32,7 +39,10 @@ export declare class ExceptionTool extends Tool {
|
|
|
32
39
|
* A chain managing an agent using tools.
|
|
33
40
|
* @augments BaseChain
|
|
34
41
|
*/
|
|
35
|
-
export declare class AgentExecutor extends
|
|
42
|
+
export declare class AgentExecutor<RunInput extends ChainValues & {
|
|
43
|
+
agent_scratchpad?: string | BaseMessage[];
|
|
44
|
+
stop?: string[];
|
|
45
|
+
} = any, RunOutput extends AgentAction | AgentFinish = any> extends BaseChain {
|
|
36
46
|
static lc_name(): string;
|
|
37
47
|
get lc_namespace(): string[];
|
|
38
48
|
agent: BaseSingleActionAgent | BaseMultiActionAgent;
|
|
@@ -53,9 +63,12 @@ export declare class AgentExecutor extends BaseChain {
|
|
|
53
63
|
handleParsingErrors: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
|
|
54
64
|
get inputKeys(): string[];
|
|
55
65
|
get outputKeys(): string[];
|
|
56
|
-
constructor(input: AgentExecutorInput);
|
|
66
|
+
constructor(input: AgentExecutorInput<RunInput, RunOutput>);
|
|
57
67
|
/** Create from agent and a list of tools. */
|
|
58
|
-
static fromAgentAndTools
|
|
68
|
+
static fromAgentAndTools<RunInput extends ChainValues & {
|
|
69
|
+
agent_scratchpad?: string | BaseMessage[];
|
|
70
|
+
stop?: string[];
|
|
71
|
+
}, RunOutput extends AgentAction | AgentFinish>(fields: AgentExecutorInput<RunInput, RunOutput>): AgentExecutor<RunInput, RunOutput>;
|
|
59
72
|
/**
|
|
60
73
|
* Method that checks if the agent execution should continue based on the
|
|
61
74
|
* number of iterations.
|
|
@@ -68,3 +81,4 @@ export declare class AgentExecutor extends BaseChain {
|
|
|
68
81
|
_chainType(): "agent_executor";
|
|
69
82
|
serialize(): SerializedLLMChain;
|
|
70
83
|
}
|
|
84
|
+
export {};
|
package/dist/agents/executor.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BaseChain } from "../chains/base.js";
|
|
2
|
+
import { RunnableAgent, } from "./agent.js";
|
|
2
3
|
import { OutputParserException } from "../schema/output_parser.js";
|
|
3
|
-
import { Tool, ToolInputParsingException } from "../tools/base.js";
|
|
4
|
+
import { Tool, ToolInputParsingException, } from "../tools/base.js";
|
|
5
|
+
import { Runnable } from "../schema/runnable/base.js";
|
|
4
6
|
/**
|
|
5
7
|
* Tool that just returns the query.
|
|
6
8
|
* Used for exception tracking.
|
|
@@ -43,6 +45,13 @@ export class AgentExecutor extends BaseChain {
|
|
|
43
45
|
return this.agent.returnValues;
|
|
44
46
|
}
|
|
45
47
|
constructor(input) {
|
|
48
|
+
let agent;
|
|
49
|
+
if (Runnable.isRunnable(input.agent)) {
|
|
50
|
+
agent = new RunnableAgent({ runnable: input.agent });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
agent = input.agent;
|
|
54
|
+
}
|
|
46
55
|
super(input);
|
|
47
56
|
Object.defineProperty(this, "agent", {
|
|
48
57
|
enumerable: true,
|
|
@@ -90,7 +99,7 @@ export class AgentExecutor extends BaseChain {
|
|
|
90
99
|
writable: true,
|
|
91
100
|
value: false
|
|
92
101
|
});
|
|
93
|
-
this.agent =
|
|
102
|
+
this.agent = agent;
|
|
94
103
|
this.tools = input.tools;
|
|
95
104
|
this.handleParsingErrors =
|
|
96
105
|
input.handleParsingErrors ?? this.handleParsingErrors;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatForOpenAIFunctions = void 0;
|
|
4
|
+
const template_js_1 = require("../prompts/template.cjs");
|
|
5
|
+
const index_js_1 = require("../schema/index.cjs");
|
|
6
|
+
const prompt_js_1 = require("./chat_convo/prompt.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
9
|
+
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
10
|
+
* step context into new iterations.
|
|
11
|
+
*
|
|
12
|
+
* @param steps A list of AgentSteps to format.
|
|
13
|
+
* @returns A list of BaseMessages.
|
|
14
|
+
*/
|
|
15
|
+
function formatForOpenAIFunctions(steps) {
|
|
16
|
+
const thoughts = [];
|
|
17
|
+
for (const step of steps) {
|
|
18
|
+
thoughts.push(new index_js_1.AIMessage(step.action.log));
|
|
19
|
+
thoughts.push(new index_js_1.HumanMessage((0, template_js_1.renderTemplate)(prompt_js_1.TEMPLATE_TOOL_RESPONSE, "f-string", {
|
|
20
|
+
observation: step.observation,
|
|
21
|
+
})));
|
|
22
|
+
}
|
|
23
|
+
return thoughts;
|
|
24
|
+
}
|
|
25
|
+
exports.formatForOpenAIFunctions = formatForOpenAIFunctions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AgentStep, BaseMessage } from "../schema/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
4
|
+
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
5
|
+
* step context into new iterations.
|
|
6
|
+
*
|
|
7
|
+
* @param steps A list of AgentSteps to format.
|
|
8
|
+
* @returns A list of BaseMessages.
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatForOpenAIFunctions(steps: AgentStep[]): BaseMessage[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { renderTemplate } from "../prompts/template.js";
|
|
2
|
+
import { AIMessage, HumanMessage, } from "../schema/index.js";
|
|
3
|
+
import { TEMPLATE_TOOL_RESPONSE } from "./chat_convo/prompt.js";
|
|
4
|
+
/**
|
|
5
|
+
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
6
|
+
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
7
|
+
* step context into new iterations.
|
|
8
|
+
*
|
|
9
|
+
* @param steps A list of AgentSteps to format.
|
|
10
|
+
* @returns A list of BaseMessages.
|
|
11
|
+
*/
|
|
12
|
+
export function formatForOpenAIFunctions(steps) {
|
|
13
|
+
const thoughts = [];
|
|
14
|
+
for (const step of steps) {
|
|
15
|
+
thoughts.push(new AIMessage(step.action.log));
|
|
16
|
+
thoughts.push(new HumanMessage(renderTemplate(TEMPLATE_TOOL_RESPONSE, "f-string", {
|
|
17
|
+
observation: step.observation,
|
|
18
|
+
})));
|
|
19
|
+
}
|
|
20
|
+
return thoughts;
|
|
21
|
+
}
|
|
@@ -30,4 +30,7 @@ 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
|
|
33
|
+
export declare function createAWSSfnAgent(llm: BaseLanguageModel, toolkit: AWSSfnToolkit, args?: AWSSfnCreatePromptArgs): AgentExecutor<import("../../schema/index.js").ChainValues & {
|
|
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>;
|
|
@@ -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<any, any>>;
|
|
@@ -24,4 +24,7 @@ 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
|
|
27
|
+
export declare function createJsonAgent(llm: BaseLanguageModel, toolkit: JsonToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor<import("../../../schema/index.js").ChainValues & {
|
|
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>;
|
|
@@ -60,6 +60,14 @@ exports.OpenApiToolkit = OpenApiToolkit;
|
|
|
60
60
|
* @param openApiToolkit The OpenAPI toolkit to use.
|
|
61
61
|
* @param args Optional arguments for creating the prompt.
|
|
62
62
|
* @returns An AgentExecutor for executing the agent with the tools.
|
|
63
|
+
*
|
|
64
|
+
* @security **Security Notice** This agent provides access to external APIs.
|
|
65
|
+
* Use with caution as this agent can make API calls with arbitrary headers.
|
|
66
|
+
* Exposing this agent to users could lead to security vulnerabilities. Consider
|
|
67
|
+
* limiting access to what endpoints it can hit, what actions can be taken, and
|
|
68
|
+
* more.
|
|
69
|
+
*
|
|
70
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
63
71
|
*/
|
|
64
72
|
function createOpenApiAgent(llm, openApiToolkit, args) {
|
|
65
73
|
const { prefix = prompt_js_1.OPENAPI_PREFIX, suffix = prompt_js_1.OPENAPI_SUFFIX, inputVariables = ["input", "agent_scratchpad"], } = args ?? {};
|
|
@@ -32,5 +32,16 @@ export declare class OpenApiToolkit extends RequestsToolkit {
|
|
|
32
32
|
* @param openApiToolkit The OpenAPI toolkit to use.
|
|
33
33
|
* @param args Optional arguments for creating the prompt.
|
|
34
34
|
* @returns An AgentExecutor for executing the agent with the tools.
|
|
35
|
+
*
|
|
36
|
+
* @security **Security Notice** This agent provides access to external APIs.
|
|
37
|
+
* Use with caution as this agent can make API calls with arbitrary headers.
|
|
38
|
+
* Exposing this agent to users could lead to security vulnerabilities. Consider
|
|
39
|
+
* limiting access to what endpoints it can hit, what actions can be taken, and
|
|
40
|
+
* more.
|
|
41
|
+
*
|
|
42
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
35
43
|
*/
|
|
36
|
-
export declare function createOpenApiAgent(llm: BaseLanguageModel, openApiToolkit: OpenApiToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor
|
|
44
|
+
export declare function createOpenApiAgent(llm: BaseLanguageModel, openApiToolkit: OpenApiToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor<import("../../../schema/index.js").ChainValues & {
|
|
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>;
|
|
@@ -55,6 +55,14 @@ export class OpenApiToolkit extends RequestsToolkit {
|
|
|
55
55
|
* @param openApiToolkit The OpenAPI toolkit to use.
|
|
56
56
|
* @param args Optional arguments for creating the prompt.
|
|
57
57
|
* @returns An AgentExecutor for executing the agent with the tools.
|
|
58
|
+
*
|
|
59
|
+
* @security **Security Notice** This agent provides access to external APIs.
|
|
60
|
+
* Use with caution as this agent can make API calls with arbitrary headers.
|
|
61
|
+
* Exposing this agent to users could lead to security vulnerabilities. Consider
|
|
62
|
+
* limiting access to what endpoints it can hit, what actions can be taken, and
|
|
63
|
+
* more.
|
|
64
|
+
*
|
|
65
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
58
66
|
*/
|
|
59
67
|
export function createOpenApiAgent(llm, openApiToolkit, args) {
|
|
60
68
|
const { prefix = OPENAPI_PREFIX, suffix = OPENAPI_SUFFIX, inputVariables = ["input", "agent_scratchpad"], } = args ?? {};
|
|
@@ -22,4 +22,7 @@ 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
|
|
25
|
+
export declare function createSqlAgent(llm: BaseLanguageModel, toolkit: SqlToolkit, args?: SqlCreatePromptArgs): AgentExecutor<import("../../../schema/index.js").ChainValues & {
|
|
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>;
|
|
@@ -34,5 +34,11 @@ 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
|
-
|
|
37
|
+
export declare function createVectorStoreAgent(llm: BaseLanguageModel, toolkit: VectorStoreToolkit, args?: ZeroShotCreatePromptArgs): AgentExecutor<import("../../../schema/index.js").ChainValues & {
|
|
38
|
+
agent_scratchpad?: string | import("../../../schema/index.js").BaseMessage[] | undefined;
|
|
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>;
|
package/dist/agents/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { LLMChain } from "../chains/llm_chain.js";
|
|
2
2
|
import { SerializedLLMChain } from "../chains/serde.js";
|
|
3
|
-
import { AgentAction, AgentFinish } from "../schema/index.js";
|
|
3
|
+
import { AgentAction, AgentFinish, BaseMessage, ChainValues } from "../schema/index.js";
|
|
4
4
|
import { BaseOutputParser } from "../schema/output_parser.js";
|
|
5
|
+
import { Runnable } from "../schema/runnable/base.js";
|
|
5
6
|
/**
|
|
6
7
|
* Interface defining the input for creating an agent. It includes the
|
|
7
8
|
* LLMChain instance, an optional output parser, and an optional list of
|
|
@@ -12,6 +13,17 @@ export interface AgentInput {
|
|
|
12
13
|
outputParser: AgentActionOutputParser | undefined;
|
|
13
14
|
allowedTools?: string[];
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Interface defining the input for creating an agent that uses runnables.
|
|
18
|
+
* It includes the Runnable instance, and an optional list of stop strings.
|
|
19
|
+
*/
|
|
20
|
+
export interface RunnableAgentInput<RunInput extends ChainValues & {
|
|
21
|
+
agent_scratchpad?: string | BaseMessage[];
|
|
22
|
+
stop?: string[];
|
|
23
|
+
} = any, RunOutput extends AgentAction | AgentFinish = any> {
|
|
24
|
+
runnable: Runnable<RunInput, RunOutput>;
|
|
25
|
+
stop?: string[];
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
28
|
* Abstract class representing an output parser specifically for agent
|
|
17
29
|
* actions and finishes in LangChain. It extends the `BaseOutputParser`
|
|
@@ -10,6 +10,17 @@ const sql_utils_js_1 = require("../../util/sql_utils.cjs");
|
|
|
10
10
|
* Class that represents a SQL database chain in the LangChain framework.
|
|
11
11
|
* It extends the BaseChain class and implements the functionality
|
|
12
12
|
* specific to a SQL database chain.
|
|
13
|
+
*
|
|
14
|
+
* @security **Security Notice**
|
|
15
|
+
* This chain generates SQL queries for the given database.
|
|
16
|
+
* The SQLDatabase class provides a getTableInfo method that can be used
|
|
17
|
+
* to get column information as well as sample data from the table.
|
|
18
|
+
* To mitigate risk of leaking sensitive data, limit permissions
|
|
19
|
+
* to read and scope to the tables that are needed.
|
|
20
|
+
* Optionally, use the includesTables or ignoreTables class parameters
|
|
21
|
+
* to limit which tables can/cannot be accessed.
|
|
22
|
+
*
|
|
23
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
13
24
|
*/
|
|
14
25
|
class SqlDatabaseChain extends base_js_1.BaseChain {
|
|
15
26
|
static lc_name() {
|
|
@@ -22,6 +22,17 @@ export interface SqlDatabaseChainInput extends ChainInputs {
|
|
|
22
22
|
* Class that represents a SQL database chain in the LangChain framework.
|
|
23
23
|
* It extends the BaseChain class and implements the functionality
|
|
24
24
|
* specific to a SQL database chain.
|
|
25
|
+
*
|
|
26
|
+
* @security **Security Notice**
|
|
27
|
+
* This chain generates SQL queries for the given database.
|
|
28
|
+
* The SQLDatabase class provides a getTableInfo method that can be used
|
|
29
|
+
* to get column information as well as sample data from the table.
|
|
30
|
+
* To mitigate risk of leaking sensitive data, limit permissions
|
|
31
|
+
* to read and scope to the tables that are needed.
|
|
32
|
+
* Optionally, use the includesTables or ignoreTables class parameters
|
|
33
|
+
* to limit which tables can/cannot be accessed.
|
|
34
|
+
*
|
|
35
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
25
36
|
*/
|
|
26
37
|
export declare class SqlDatabaseChain extends BaseChain {
|
|
27
38
|
static lc_name(): string;
|
|
@@ -7,6 +7,17 @@ import { getPromptTemplateFromDataSource } from "../../util/sql_utils.js";
|
|
|
7
7
|
* Class that represents a SQL database chain in the LangChain framework.
|
|
8
8
|
* It extends the BaseChain class and implements the functionality
|
|
9
9
|
* specific to a SQL database chain.
|
|
10
|
+
*
|
|
11
|
+
* @security **Security Notice**
|
|
12
|
+
* This chain generates SQL queries for the given database.
|
|
13
|
+
* The SQLDatabase class provides a getTableInfo method that can be used
|
|
14
|
+
* to get column information as well as sample data from the table.
|
|
15
|
+
* To mitigate risk of leaking sensitive data, limit permissions
|
|
16
|
+
* to read and scope to the tables that are needed.
|
|
17
|
+
* Optionally, use the includesTables or ignoreTables class parameters
|
|
18
|
+
* to limit which tables can/cannot be accessed.
|
|
19
|
+
*
|
|
20
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
10
21
|
*/
|
|
11
22
|
export class SqlDatabaseChain extends BaseChain {
|
|
12
23
|
static lc_name() {
|
|
@@ -28,7 +28,7 @@ function messageToWenxinRole(message) {
|
|
|
28
28
|
case "human":
|
|
29
29
|
return "user";
|
|
30
30
|
case "system":
|
|
31
|
-
throw new Error("System messages not
|
|
31
|
+
throw new Error("System messages should not be here");
|
|
32
32
|
case "function":
|
|
33
33
|
throw new Error("Function messages not supported");
|
|
34
34
|
case "generic": {
|
|
@@ -164,6 +164,10 @@ class ChatBaiduWenxin extends base_js_1.BaseChatModel {
|
|
|
164
164
|
this.apiUrl =
|
|
165
165
|
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant";
|
|
166
166
|
}
|
|
167
|
+
else if (this.modelName === "ERNIE-Bot-4") {
|
|
168
|
+
this.apiUrl =
|
|
169
|
+
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro";
|
|
170
|
+
}
|
|
167
171
|
else {
|
|
168
172
|
throw new Error(`Invalid model name: ${this.modelName}`);
|
|
169
173
|
}
|
|
@@ -219,6 +223,13 @@ class ChatBaiduWenxin extends base_js_1.BaseChatModel {
|
|
|
219
223
|
async _generate(messages, options, runManager) {
|
|
220
224
|
const tokenUsage = {};
|
|
221
225
|
const params = this.invocationParams();
|
|
226
|
+
// Wenxin requires the system message to be put in the params, not messages array
|
|
227
|
+
const systemMessage = messages.find((message) => message._getType() === "system");
|
|
228
|
+
if (systemMessage) {
|
|
229
|
+
// eslint-disable-next-line no-param-reassign
|
|
230
|
+
messages = messages.filter((message) => message !== systemMessage);
|
|
231
|
+
params.system = systemMessage.text;
|
|
232
|
+
}
|
|
222
233
|
const messagesMapped = messages.map((message) => ({
|
|
223
234
|
role: messageToWenxinRole(message),
|
|
224
235
|
content: message.text,
|
|
@@ -22,12 +22,13 @@ interface ChatCompletionRequest {
|
|
|
22
22
|
temperature?: number;
|
|
23
23
|
top_p?: number;
|
|
24
24
|
penalty_score?: number;
|
|
25
|
+
system?: string;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Interface defining the input to the ChatBaiduWenxin class.
|
|
28
29
|
*/
|
|
29
30
|
declare interface BaiduWenxinChatInput {
|
|
30
|
-
/** Model name to use
|
|
31
|
+
/** Model name to use. Available options are: ERNIE-Bot, ERNIE-Bot-turbo, ERNIE-Bot-4
|
|
31
32
|
* @default "ERNIE-Bot-turbo"
|
|
32
33
|
*/
|
|
33
34
|
modelName: string;
|
|
@@ -110,6 +111,7 @@ export declare class ChatBaiduWenxin extends BaseChatModel implements BaiduWenxi
|
|
|
110
111
|
* Get the identifying parameters for the model
|
|
111
112
|
*/
|
|
112
113
|
identifyingParams(): {
|
|
114
|
+
system?: string | undefined;
|
|
113
115
|
stream?: boolean | undefined;
|
|
114
116
|
temperature?: number | undefined;
|
|
115
117
|
top_p?: number | undefined;
|