langchain 0.0.168 → 0.0.170
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/yandex.cjs +1 -0
- package/chat_models/yandex.d.ts +1 -0
- package/chat_models/yandex.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/callbacks/handlers/llmonitor.cjs +21 -17
- package/dist/callbacks/handlers/llmonitor.js +21 -17
- package/dist/chains/sql_db/sql_db_chain.cjs +9 -0
- package/dist/chains/sql_db/sql_db_chain.d.ts +9 -0
- package/dist/chains/sql_db/sql_db_chain.js +9 -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/cloudflare_workersai.cjs +7 -2
- package/dist/chat_models/cloudflare_workersai.d.ts +1 -1
- package/dist/chat_models/cloudflare_workersai.js +7 -2
- package/dist/chat_models/yandex.cjs +117 -0
- package/dist/chat_models/yandex.d.ts +16 -0
- package/dist/chat_models/yandex.js +113 -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/evaluation/comparison/prompt.d.ts +2 -2
- package/dist/experimental/chains/violation_of_expectations/index.cjs +5 -0
- package/dist/experimental/chains/violation_of_expectations/index.d.ts +1 -0
- package/dist/experimental/chains/violation_of_expectations/index.js +1 -0
- package/dist/experimental/chains/violation_of_expectations/types.cjs +49 -0
- package/dist/experimental/chains/violation_of_expectations/types.d.ts +69 -0
- package/dist/experimental/chains/violation_of_expectations/types.js +46 -0
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.cjs +328 -0
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.d.ts +148 -0
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.js +324 -0
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_prompt.cjs +49 -0
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_prompt.d.ts +5 -0
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_prompt.js +46 -0
- package/dist/llms/cloudflare_workersai.cjs +14 -7
- package/dist/llms/cloudflare_workersai.d.ts +1 -1
- package/dist/llms/cloudflare_workersai.js +14 -7
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +5 -2
- package/dist/load/import_map.d.ts +3 -0
- package/dist/load/import_map.js +3 -0
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- 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/retrievers/zep.cjs +29 -3
- package/dist/retrievers/zep.d.ts +14 -0
- package/dist/retrievers/zep.js +29 -3
- 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 +33 -1
- package/dist/schema/runnable/passthrough.d.ts +11 -1
- package/dist/schema/runnable/passthrough.js +32 -1
- package/dist/sql_db.cjs +12 -0
- package/dist/sql_db.d.ts +12 -0
- package/dist/sql_db.js +12 -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/vectorstores/faiss.cjs +38 -6
- package/dist/vectorstores/faiss.d.ts +14 -2
- package/dist/vectorstores/faiss.js +38 -6
- package/dist/vectorstores/pgvector.cjs +1 -1
- package/dist/vectorstores/pgvector.js +1 -1
- package/dist/vectorstores/weaviate.cjs +13 -2
- package/dist/vectorstores/weaviate.js +13 -2
- package/experimental/chains/violation_of_expectations.cjs +1 -0
- package/experimental/chains/violation_of_expectations.d.ts +1 -0
- package/experimental/chains/violation_of_expectations.js +1 -0
- package/package.json +47 -10
- 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/yandex.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/yandex.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/yandex.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
|
+
* 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
|
+
* 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
|
+
* 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`
|
|
@@ -72,13 +72,15 @@ const parseInput = (rawInput) => {
|
|
|
72
72
|
const parseOutput = (rawOutput) => {
|
|
73
73
|
if (!rawOutput)
|
|
74
74
|
return null;
|
|
75
|
-
const { text, output, answer } = rawOutput;
|
|
75
|
+
const { text, output, answer, result } = rawOutput;
|
|
76
76
|
if (text)
|
|
77
77
|
return text;
|
|
78
78
|
if (answer)
|
|
79
79
|
return answer;
|
|
80
80
|
if (output)
|
|
81
81
|
return output;
|
|
82
|
+
if (result)
|
|
83
|
+
return result;
|
|
82
84
|
return rawOutput;
|
|
83
85
|
};
|
|
84
86
|
class LLMonitorHandler extends base_js_1.BaseCallbackHandler {
|
|
@@ -111,15 +113,14 @@ class LLMonitorHandler extends base_js_1.BaseCallbackHandler {
|
|
|
111
113
|
...(extraParams?.invocation_params || {}),
|
|
112
114
|
...(metadata || {}),
|
|
113
115
|
};
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const userProps = params?.userProps || undefined;
|
|
116
|
+
const { model, model_name, modelName, userId, userProps, ...rest } = params;
|
|
117
|
+
const name = model || modelName || model_name || llm.id.at(-1);
|
|
117
118
|
await this.monitor.trackEvent("llm", "start", {
|
|
118
119
|
runId,
|
|
119
120
|
parentRunId,
|
|
120
121
|
name,
|
|
121
122
|
input: (0, exports.convertToLLMonitorMessages)(prompts),
|
|
122
|
-
extra:
|
|
123
|
+
extra: rest,
|
|
123
124
|
userId,
|
|
124
125
|
userProps,
|
|
125
126
|
tags,
|
|
@@ -131,15 +132,15 @@ class LLMonitorHandler extends base_js_1.BaseCallbackHandler {
|
|
|
131
132
|
...(extraParams?.invocation_params || {}),
|
|
132
133
|
...(metadata || {}),
|
|
133
134
|
};
|
|
134
|
-
|
|
135
|
-
const userId = params
|
|
136
|
-
const
|
|
135
|
+
// Expand them so they're excluded from the "extra" field
|
|
136
|
+
const { model, model_name, modelName, userId, userProps, ...rest } = params;
|
|
137
|
+
const name = model || modelName || model_name || llm.id.at(-1);
|
|
137
138
|
await this.monitor.trackEvent("llm", "start", {
|
|
138
139
|
runId,
|
|
139
140
|
parentRunId,
|
|
140
141
|
name,
|
|
141
142
|
input: (0, exports.convertToLLMonitorMessages)(messages),
|
|
142
|
-
extra:
|
|
143
|
+
extra: rest,
|
|
143
144
|
userId,
|
|
144
145
|
userProps,
|
|
145
146
|
tags,
|
|
@@ -164,20 +165,19 @@ class LLMonitorHandler extends base_js_1.BaseCallbackHandler {
|
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata) {
|
|
168
|
+
const { agentName, userId, userProps, ...rest } = metadata || {};
|
|
167
169
|
// allow the user to specify an agent name
|
|
168
|
-
const
|
|
169
|
-
const name = (metadata?.agentName ?? chainName);
|
|
170
|
+
const name = agentName || chain.id.at(-1);
|
|
170
171
|
// Attempt to automatically detect if this is an agent or chain
|
|
171
|
-
const runType =
|
|
172
|
-
["AgentExecutor", "PlanAndExecute"].includes(chainName)
|
|
172
|
+
const runType = agentName || ["AgentExecutor", "PlanAndExecute"].includes(name)
|
|
173
173
|
? "agent"
|
|
174
174
|
: "chain";
|
|
175
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
176
|
-
const { agentName, ...rest } = metadata || {};
|
|
177
175
|
await this.monitor.trackEvent(runType, "start", {
|
|
178
176
|
runId,
|
|
179
177
|
parentRunId,
|
|
180
178
|
name,
|
|
179
|
+
userId,
|
|
180
|
+
userProps,
|
|
181
181
|
input: parseInput(inputs),
|
|
182
182
|
extra: rest,
|
|
183
183
|
tags,
|
|
@@ -197,12 +197,16 @@ class LLMonitorHandler extends base_js_1.BaseCallbackHandler {
|
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
async handleToolStart(tool, input, runId, parentRunId, tags, metadata) {
|
|
200
|
+
const { toolName, userId, userProps, ...rest } = metadata || {};
|
|
201
|
+
const name = toolName || tool.id.at(-1);
|
|
200
202
|
await this.monitor.trackEvent("tool", "start", {
|
|
201
203
|
runId,
|
|
202
204
|
parentRunId,
|
|
203
|
-
name
|
|
205
|
+
name,
|
|
206
|
+
userId,
|
|
207
|
+
userProps,
|
|
204
208
|
input,
|
|
205
|
-
extra:
|
|
209
|
+
extra: rest,
|
|
206
210
|
tags,
|
|
207
211
|
runtime: "langchain-js",
|
|
208
212
|
});
|