langchain 0.0.211 → 0.0.213
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/chains/combine_documents.cjs +1 -0
- package/chains/combine_documents.d.ts +1 -0
- package/chains/combine_documents.js +1 -0
- package/chains/history_aware_retriever.cjs +1 -0
- package/chains/history_aware_retriever.d.ts +1 -0
- package/chains/history_aware_retriever.js +1 -0
- package/chains/retrieval.cjs +1 -0
- package/chains/retrieval.d.ts +1 -0
- package/chains/retrieval.js +1 -0
- package/dist/agents/agent.cjs +1 -0
- package/dist/agents/agent.js +1 -0
- package/dist/agents/executor.cjs +28 -9
- package/dist/agents/executor.d.ts +4 -3
- package/dist/agents/executor.js +27 -8
- package/dist/agents/format_scratchpad/openai_functions.cjs +22 -1
- package/dist/agents/format_scratchpad/openai_functions.d.ts +10 -0
- package/dist/agents/format_scratchpad/openai_functions.js +21 -1
- package/dist/agents/index.cjs +11 -4
- package/dist/agents/index.d.ts +6 -3
- package/dist/agents/index.js +5 -3
- package/dist/agents/initialize.cjs +1 -1
- package/dist/agents/initialize.d.ts +1 -1
- package/dist/agents/initialize.js +1 -1
- package/dist/agents/openai/output_parser.cjs +20 -196
- package/dist/agents/openai/output_parser.d.ts +2 -111
- package/dist/agents/openai/output_parser.js +6 -193
- package/dist/agents/{openai → openai_functions}/index.cjs +78 -2
- package/dist/agents/{openai → openai_functions}/index.d.ts +75 -3
- package/dist/agents/{openai → openai_functions}/index.js +76 -1
- package/dist/agents/openai_functions/output_parser.cjs +102 -0
- package/dist/agents/openai_functions/output_parser.d.ts +56 -0
- package/dist/agents/openai_functions/output_parser.js +98 -0
- package/dist/agents/openai_tools/index.cjs +81 -0
- package/dist/agents/openai_tools/index.d.ts +80 -0
- package/dist/agents/openai_tools/index.js +77 -0
- package/dist/agents/openai_tools/output_parser.cjs +102 -0
- package/dist/agents/openai_tools/output_parser.d.ts +57 -0
- package/dist/agents/openai_tools/output_parser.js +98 -0
- package/dist/agents/react/index.cjs +75 -0
- package/dist/agents/react/index.d.ts +60 -0
- package/dist/agents/react/index.js +71 -0
- package/dist/agents/react/output_parser.cjs +0 -1
- package/dist/agents/react/output_parser.d.ts +0 -1
- package/dist/agents/react/output_parser.js +0 -1
- package/dist/agents/structured_chat/index.cjs +85 -1
- package/dist/agents/structured_chat/index.d.ts +71 -0
- package/dist/agents/structured_chat/index.js +83 -0
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.cjs +1 -1
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.js +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +1 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +1 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.js +1 -0
- package/dist/agents/toolkits/json/json.cjs +2 -0
- package/dist/agents/toolkits/json/json.d.ts +2 -0
- package/dist/agents/toolkits/json/json.js +2 -0
- package/dist/agents/toolkits/openapi/openapi.cjs +2 -0
- package/dist/agents/toolkits/openapi/openapi.d.ts +2 -0
- package/dist/agents/toolkits/openapi/openapi.js +2 -0
- package/dist/agents/toolkits/vectorstore/vectorstore.cjs +2 -0
- package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +2 -0
- package/dist/agents/toolkits/vectorstore/vectorstore.js +2 -0
- package/dist/agents/xml/index.cjs +75 -1
- package/dist/agents/xml/index.d.ts +65 -0
- package/dist/agents/xml/index.js +73 -0
- package/dist/chains/combine_documents/base.cjs +16 -0
- package/dist/chains/combine_documents/base.d.ts +13 -0
- package/dist/chains/combine_documents/base.js +12 -0
- package/dist/chains/combine_documents/index.cjs +5 -0
- package/dist/chains/combine_documents/index.d.ts +1 -0
- package/dist/chains/combine_documents/index.js +1 -0
- package/dist/chains/combine_documents/reduce.cjs +5 -2
- package/dist/chains/combine_documents/reduce.js +4 -1
- package/dist/chains/combine_documents/stuff.cjs +42 -0
- package/dist/chains/combine_documents/stuff.d.ts +28 -0
- package/dist/chains/combine_documents/stuff.js +38 -0
- package/dist/chains/conversational_retrieval_chain.cjs +3 -3
- package/dist/chains/conversational_retrieval_chain.js +1 -1
- package/dist/chains/history_aware_retriever.cjs +55 -0
- package/dist/chains/history_aware_retriever.d.ts +55 -0
- package/dist/chains/history_aware_retriever.js +51 -0
- package/dist/chains/retrieval.cjs +60 -0
- package/dist/chains/retrieval.d.ts +65 -0
- package/dist/chains/retrieval.js +56 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/load/import_map.cjs +7 -3
- package/dist/load/import_map.d.ts +4 -0
- package/dist/load/import_map.js +4 -0
- package/dist/output_parsers/json.cjs +2 -78
- package/dist/output_parsers/json.d.ts +1 -1
- package/dist/output_parsers/json.js +1 -77
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/tools/retriever.cjs +17 -0
- package/dist/tools/retriever.d.ts +10 -0
- package/dist/tools/retriever.js +13 -0
- package/package.json +36 -4
- package/tools/retriever.cjs +1 -0
- package/tools/retriever.d.ts +1 -0
- package/tools/retriever.js +1 -0
- /package/dist/agents/{openai → openai_functions}/prompt.cjs +0 -0
- /package/dist/agents/{openai → openai_functions}/prompt.d.ts +0 -0
- /package/dist/agents/{openai → openai_functions}/prompt.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chains/combine_documents/index.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/combine_documents/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/combine_documents/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chains/history_aware_retriever.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/history_aware_retriever.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/history_aware_retriever.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chains/retrieval.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/retrieval.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/retrieval.js'
|
package/dist/agents/agent.cjs
CHANGED
|
@@ -103,6 +103,7 @@ class RunnableAgent extends BaseMultiActionAgent {
|
|
|
103
103
|
writable: true,
|
|
104
104
|
value: ["langchain", "agents", "runnable"]
|
|
105
105
|
});
|
|
106
|
+
// TODO: Rename input to "intermediate_steps"
|
|
106
107
|
Object.defineProperty(this, "runnable", {
|
|
107
108
|
enumerable: true,
|
|
108
109
|
configurable: true,
|
package/dist/agents/agent.js
CHANGED
|
@@ -97,6 +97,7 @@ export class RunnableAgent extends BaseMultiActionAgent {
|
|
|
97
97
|
writable: true,
|
|
98
98
|
value: ["langchain", "agents", "runnable"]
|
|
99
99
|
});
|
|
100
|
+
// TODO: Rename input to "intermediate_steps"
|
|
100
101
|
Object.defineProperty(this, "runnable", {
|
|
101
102
|
enumerable: true,
|
|
102
103
|
configurable: true,
|
package/dist/agents/executor.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentExecutor = exports.ExceptionTool = exports.AgentExecutorIterator = void 0;
|
|
4
4
|
const tools_1 = require("@langchain/core/tools");
|
|
5
|
+
const runnables_1 = require("@langchain/core/runnables");
|
|
5
6
|
const base_js_1 = require("../chains/base.cjs");
|
|
6
7
|
const agent_js_1 = require("./agent.cjs");
|
|
7
8
|
const manager_js_1 = require("../callbacks/manager.cjs");
|
|
8
9
|
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
9
|
-
const base_js_2 = require("../schema/runnable/base.cjs");
|
|
10
10
|
const serializable_js_1 = require("../load/serializable.cjs");
|
|
11
11
|
class AgentExecutorIterator extends serializable_js_1.Serializable {
|
|
12
12
|
get finalOutputs() {
|
|
@@ -96,6 +96,7 @@ class AgentExecutorIterator extends serializable_js_1.Serializable {
|
|
|
96
96
|
});
|
|
97
97
|
this.agentExecutor = fields.agentExecutor;
|
|
98
98
|
this.inputs = fields.inputs;
|
|
99
|
+
this.callbacks = fields.callbacks;
|
|
99
100
|
this.tags = fields.tags;
|
|
100
101
|
this.metadata = fields.metadata;
|
|
101
102
|
this.runName = fields.runName;
|
|
@@ -268,8 +269,11 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
268
269
|
}
|
|
269
270
|
constructor(input) {
|
|
270
271
|
let agent;
|
|
271
|
-
|
|
272
|
+
let returnOnlyOutputs = true;
|
|
273
|
+
if (runnables_1.Runnable.isRunnable(input.agent)) {
|
|
272
274
|
agent = new agent_js_1.RunnableAgent({ runnable: input.agent });
|
|
275
|
+
// TODO: Update BaseChain implementation on breaking change
|
|
276
|
+
returnOnlyOutputs = false;
|
|
273
277
|
}
|
|
274
278
|
else {
|
|
275
279
|
agent = input.agent;
|
|
@@ -305,6 +309,13 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
305
309
|
writable: true,
|
|
306
310
|
value: "force"
|
|
307
311
|
});
|
|
312
|
+
// TODO: Update BaseChain implementation on breaking change to include this
|
|
313
|
+
Object.defineProperty(this, "returnOnlyOutputs", {
|
|
314
|
+
enumerable: true,
|
|
315
|
+
configurable: true,
|
|
316
|
+
writable: true,
|
|
317
|
+
value: true
|
|
318
|
+
});
|
|
308
319
|
/**
|
|
309
320
|
* How to handle errors raised by the agent's output parser.
|
|
310
321
|
Defaults to `False`, which raises the error.
|
|
@@ -325,6 +336,7 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
325
336
|
this.tools = input.tools;
|
|
326
337
|
this.handleParsingErrors =
|
|
327
338
|
input.handleParsingErrors ?? this.handleParsingErrors;
|
|
339
|
+
this.returnOnlyOutputs = returnOnlyOutputs;
|
|
328
340
|
if (this.agent._agentActionType() === "multi") {
|
|
329
341
|
for (const tool of this.tools) {
|
|
330
342
|
if (tool.returnDirect) {
|
|
@@ -362,11 +374,18 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
362
374
|
const getOutput = async (finishStep) => {
|
|
363
375
|
const { returnValues } = finishStep;
|
|
364
376
|
const additional = await this.agent.prepareForOutput(returnValues, steps);
|
|
377
|
+
await runManager?.handleAgentEnd(finishStep);
|
|
378
|
+
let response;
|
|
365
379
|
if (this.returnIntermediateSteps) {
|
|
366
|
-
|
|
380
|
+
response = { ...returnValues, intermediateSteps: steps, ...additional };
|
|
367
381
|
}
|
|
368
|
-
|
|
369
|
-
|
|
382
|
+
else {
|
|
383
|
+
response = { ...returnValues, ...additional };
|
|
384
|
+
}
|
|
385
|
+
if (!this.returnOnlyOutputs) {
|
|
386
|
+
response = { ...inputs, ...response };
|
|
387
|
+
}
|
|
388
|
+
return response;
|
|
370
389
|
};
|
|
371
390
|
while (this.shouldContinue(iterations)) {
|
|
372
391
|
let output;
|
|
@@ -591,13 +610,13 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
591
610
|
}
|
|
592
611
|
async *_streamIterator(
|
|
593
612
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
594
|
-
inputs) {
|
|
613
|
+
inputs, options) {
|
|
595
614
|
const agentExecutorIterator = new AgentExecutorIterator({
|
|
596
615
|
inputs,
|
|
597
616
|
agentExecutor: this,
|
|
598
|
-
metadata:
|
|
599
|
-
tags:
|
|
600
|
-
callbacks:
|
|
617
|
+
metadata: options?.metadata,
|
|
618
|
+
tags: options?.tags,
|
|
619
|
+
callbacks: options?.callbacks,
|
|
601
620
|
});
|
|
602
621
|
const iterator = agentExecutorIterator.streamIterator();
|
|
603
622
|
for await (const step of iterator) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type StructuredToolInterface, type ToolInterface, ToolInputParsingException, Tool } from "@langchain/core/tools";
|
|
2
|
+
import { Runnable, type RunnableConfig } from "@langchain/core/runnables";
|
|
2
3
|
import { BaseChain, ChainInputs } from "../chains/base.js";
|
|
3
4
|
import { BaseMultiActionAgent, BaseSingleActionAgent } from "./agent.js";
|
|
4
5
|
import { StoppingMethod } from "./types.js";
|
|
@@ -6,7 +7,6 @@ import { SerializedLLMChain } from "../chains/serde.js";
|
|
|
6
7
|
import { AgentAction, ChainValues, AgentFinish, AgentStep } from "../schema/index.js";
|
|
7
8
|
import { CallbackManagerForChainRun, Callbacks } from "../callbacks/manager.js";
|
|
8
9
|
import { OutputParserException } from "../schema/output_parser.js";
|
|
9
|
-
import { Runnable } from "../schema/runnable/base.js";
|
|
10
10
|
import { Serializable } from "../load/serializable.js";
|
|
11
11
|
interface AgentExecutorIteratorInput {
|
|
12
12
|
agentExecutor: AgentExecutor;
|
|
@@ -21,7 +21,7 @@ export declare class AgentExecutorIterator extends Serializable implements Agent
|
|
|
21
21
|
lc_namespace: string[];
|
|
22
22
|
agentExecutor: AgentExecutor;
|
|
23
23
|
inputs: Record<string, string>;
|
|
24
|
-
callbacks
|
|
24
|
+
callbacks?: Callbacks;
|
|
25
25
|
tags: string[] | undefined;
|
|
26
26
|
metadata: Record<string, unknown> | undefined;
|
|
27
27
|
runName: string | undefined;
|
|
@@ -113,6 +113,7 @@ export declare class AgentExecutor extends BaseChain<ChainValues, AgentExecutorO
|
|
|
113
113
|
returnIntermediateSteps: boolean;
|
|
114
114
|
maxIterations?: number;
|
|
115
115
|
earlyStoppingMethod: StoppingMethod;
|
|
116
|
+
returnOnlyOutputs: boolean;
|
|
116
117
|
/**
|
|
117
118
|
* How to handle errors raised by the agent's output parser.
|
|
118
119
|
Defaults to `False`, which raises the error.
|
|
@@ -143,7 +144,7 @@ export declare class AgentExecutor extends BaseChain<ChainValues, AgentExecutorO
|
|
|
143
144
|
_return(output: AgentFinish, intermediateSteps: AgentStep[], runManager?: CallbackManagerForChainRun): Promise<AgentExecutorOutput>;
|
|
144
145
|
_getToolReturn(nextStepOutput: AgentStep): Promise<AgentFinish | null>;
|
|
145
146
|
_returnStoppedResponse(earlyStoppingMethod: StoppingMethod): AgentFinish;
|
|
146
|
-
_streamIterator(inputs: Record<string, any>): AsyncGenerator<ChainValues>;
|
|
147
|
+
_streamIterator(inputs: Record<string, any>, options?: Partial<RunnableConfig>): AsyncGenerator<ChainValues>;
|
|
147
148
|
_chainType(): "agent_executor";
|
|
148
149
|
serialize(): SerializedLLMChain;
|
|
149
150
|
}
|
package/dist/agents/executor.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ToolInputParsingException, Tool, } from "@langchain/core/tools";
|
|
2
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
2
3
|
import { BaseChain } from "../chains/base.js";
|
|
3
4
|
import { RunnableAgent, } from "./agent.js";
|
|
4
5
|
import { CallbackManager, } from "../callbacks/manager.js";
|
|
5
6
|
import { OutputParserException } from "../schema/output_parser.js";
|
|
6
|
-
import { Runnable } from "../schema/runnable/base.js";
|
|
7
7
|
import { Serializable } from "../load/serializable.js";
|
|
8
8
|
export class AgentExecutorIterator extends Serializable {
|
|
9
9
|
get finalOutputs() {
|
|
@@ -93,6 +93,7 @@ export class AgentExecutorIterator extends Serializable {
|
|
|
93
93
|
});
|
|
94
94
|
this.agentExecutor = fields.agentExecutor;
|
|
95
95
|
this.inputs = fields.inputs;
|
|
96
|
+
this.callbacks = fields.callbacks;
|
|
96
97
|
this.tags = fields.tags;
|
|
97
98
|
this.metadata = fields.metadata;
|
|
98
99
|
this.runName = fields.runName;
|
|
@@ -263,8 +264,11 @@ export class AgentExecutor extends BaseChain {
|
|
|
263
264
|
}
|
|
264
265
|
constructor(input) {
|
|
265
266
|
let agent;
|
|
267
|
+
let returnOnlyOutputs = true;
|
|
266
268
|
if (Runnable.isRunnable(input.agent)) {
|
|
267
269
|
agent = new RunnableAgent({ runnable: input.agent });
|
|
270
|
+
// TODO: Update BaseChain implementation on breaking change
|
|
271
|
+
returnOnlyOutputs = false;
|
|
268
272
|
}
|
|
269
273
|
else {
|
|
270
274
|
agent = input.agent;
|
|
@@ -300,6 +304,13 @@ export class AgentExecutor extends BaseChain {
|
|
|
300
304
|
writable: true,
|
|
301
305
|
value: "force"
|
|
302
306
|
});
|
|
307
|
+
// TODO: Update BaseChain implementation on breaking change to include this
|
|
308
|
+
Object.defineProperty(this, "returnOnlyOutputs", {
|
|
309
|
+
enumerable: true,
|
|
310
|
+
configurable: true,
|
|
311
|
+
writable: true,
|
|
312
|
+
value: true
|
|
313
|
+
});
|
|
303
314
|
/**
|
|
304
315
|
* How to handle errors raised by the agent's output parser.
|
|
305
316
|
Defaults to `False`, which raises the error.
|
|
@@ -320,6 +331,7 @@ export class AgentExecutor extends BaseChain {
|
|
|
320
331
|
this.tools = input.tools;
|
|
321
332
|
this.handleParsingErrors =
|
|
322
333
|
input.handleParsingErrors ?? this.handleParsingErrors;
|
|
334
|
+
this.returnOnlyOutputs = returnOnlyOutputs;
|
|
323
335
|
if (this.agent._agentActionType() === "multi") {
|
|
324
336
|
for (const tool of this.tools) {
|
|
325
337
|
if (tool.returnDirect) {
|
|
@@ -357,11 +369,18 @@ export class AgentExecutor extends BaseChain {
|
|
|
357
369
|
const getOutput = async (finishStep) => {
|
|
358
370
|
const { returnValues } = finishStep;
|
|
359
371
|
const additional = await this.agent.prepareForOutput(returnValues, steps);
|
|
372
|
+
await runManager?.handleAgentEnd(finishStep);
|
|
373
|
+
let response;
|
|
360
374
|
if (this.returnIntermediateSteps) {
|
|
361
|
-
|
|
375
|
+
response = { ...returnValues, intermediateSteps: steps, ...additional };
|
|
362
376
|
}
|
|
363
|
-
|
|
364
|
-
|
|
377
|
+
else {
|
|
378
|
+
response = { ...returnValues, ...additional };
|
|
379
|
+
}
|
|
380
|
+
if (!this.returnOnlyOutputs) {
|
|
381
|
+
response = { ...inputs, ...response };
|
|
382
|
+
}
|
|
383
|
+
return response;
|
|
365
384
|
};
|
|
366
385
|
while (this.shouldContinue(iterations)) {
|
|
367
386
|
let output;
|
|
@@ -586,13 +605,13 @@ export class AgentExecutor extends BaseChain {
|
|
|
586
605
|
}
|
|
587
606
|
async *_streamIterator(
|
|
588
607
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
589
|
-
inputs) {
|
|
608
|
+
inputs, options) {
|
|
590
609
|
const agentExecutorIterator = new AgentExecutorIterator({
|
|
591
610
|
inputs,
|
|
592
611
|
agentExecutor: this,
|
|
593
|
-
metadata:
|
|
594
|
-
tags:
|
|
595
|
-
callbacks:
|
|
612
|
+
metadata: options?.metadata,
|
|
613
|
+
tags: options?.tags,
|
|
614
|
+
callbacks: options?.callbacks,
|
|
596
615
|
});
|
|
597
616
|
const iterator = agentExecutorIterator.streamIterator();
|
|
598
617
|
for await (const step of iterator) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatForOpenAIFunctions = void 0;
|
|
3
|
+
exports.formatToOpenAIFunctionMessages = exports.formatForOpenAIFunctions = void 0;
|
|
4
4
|
const template_js_1 = require("../../prompts/template.cjs");
|
|
5
5
|
const index_js_1 = require("../../schema/index.cjs");
|
|
6
6
|
const prompt_js_1 = require("../chat_convo/prompt.cjs");
|
|
@@ -9,6 +9,7 @@ const prompt_js_1 = require("../chat_convo/prompt.cjs");
|
|
|
9
9
|
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
10
10
|
* step context into new iterations.
|
|
11
11
|
*
|
|
12
|
+
* @deprecated Use formatToOpenAIFunctionMessages instead.
|
|
12
13
|
* @param steps A list of AgentSteps to format.
|
|
13
14
|
* @returns A list of BaseMessages.
|
|
14
15
|
*/
|
|
@@ -23,3 +24,23 @@ function formatForOpenAIFunctions(steps) {
|
|
|
23
24
|
return thoughts;
|
|
24
25
|
}
|
|
25
26
|
exports.formatForOpenAIFunctions = formatForOpenAIFunctions;
|
|
27
|
+
/**
|
|
28
|
+
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
29
|
+
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
30
|
+
* step context into new iterations.
|
|
31
|
+
*
|
|
32
|
+
* @param steps A list of AgentSteps to format.
|
|
33
|
+
* @returns A list of BaseMessages.
|
|
34
|
+
*/
|
|
35
|
+
function formatToOpenAIFunctionMessages(steps) {
|
|
36
|
+
return steps.flatMap(({ action, observation }) => {
|
|
37
|
+
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
38
|
+
const log = action.messageLog;
|
|
39
|
+
return log.concat(new index_js_1.FunctionMessage(observation, action.tool));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return [new index_js_1.AIMessage(action.log)];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.formatToOpenAIFunctionMessages = formatToOpenAIFunctionMessages;
|
|
@@ -4,7 +4,17 @@ import { AgentStep, BaseMessage } from "../../schema/index.js";
|
|
|
4
4
|
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
5
5
|
* step context into new iterations.
|
|
6
6
|
*
|
|
7
|
+
* @deprecated Use formatToOpenAIFunctionMessages instead.
|
|
7
8
|
* @param steps A list of AgentSteps to format.
|
|
8
9
|
* @returns A list of BaseMessages.
|
|
9
10
|
*/
|
|
10
11
|
export declare function formatForOpenAIFunctions(steps: AgentStep[]): BaseMessage[];
|
|
12
|
+
/**
|
|
13
|
+
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
14
|
+
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
15
|
+
* step context into new iterations.
|
|
16
|
+
*
|
|
17
|
+
* @param steps A list of AgentSteps to format.
|
|
18
|
+
* @returns A list of BaseMessages.
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatToOpenAIFunctionMessages(steps: AgentStep[]): BaseMessage[];
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { renderTemplate } from "../../prompts/template.js";
|
|
2
|
-
import { AIMessage, HumanMessage, } from "../../schema/index.js";
|
|
2
|
+
import { AIMessage, HumanMessage, FunctionMessage, } from "../../schema/index.js";
|
|
3
3
|
import { TEMPLATE_TOOL_RESPONSE } from "../chat_convo/prompt.js";
|
|
4
4
|
/**
|
|
5
5
|
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
6
6
|
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
7
7
|
* step context into new iterations.
|
|
8
8
|
*
|
|
9
|
+
* @deprecated Use formatToOpenAIFunctionMessages instead.
|
|
9
10
|
* @param steps A list of AgentSteps to format.
|
|
10
11
|
* @returns A list of BaseMessages.
|
|
11
12
|
*/
|
|
@@ -19,3 +20,22 @@ export function formatForOpenAIFunctions(steps) {
|
|
|
19
20
|
}
|
|
20
21
|
return thoughts;
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Format a list of AgentSteps into a list of BaseMessage instances for
|
|
25
|
+
* agents that use OpenAI's API. Helpful for passing in previous agent
|
|
26
|
+
* step context into new iterations.
|
|
27
|
+
*
|
|
28
|
+
* @param steps A list of AgentSteps to format.
|
|
29
|
+
* @returns A list of BaseMessages.
|
|
30
|
+
*/
|
|
31
|
+
export function formatToOpenAIFunctionMessages(steps) {
|
|
32
|
+
return steps.flatMap(({ action, observation }) => {
|
|
33
|
+
if ("messageLog" in action && action.messageLog !== undefined) {
|
|
34
|
+
const log = action.messageLog;
|
|
35
|
+
return log.concat(new FunctionMessage(observation, action.tool));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return [new AIMessage(action.log)];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
package/dist/agents/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XMLAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
|
|
3
|
+
exports.createReactAgent = exports.createXmlAgent = exports.XMLAgent = exports.createOpenAIToolsAgent = exports.createOpenAIFunctionsAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.createStructuredChatAgent = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
|
|
4
4
|
var agent_js_1 = require("./agent.cjs");
|
|
5
5
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_js_1.Agent; } });
|
|
6
6
|
Object.defineProperty(exports, "BaseSingleActionAgent", { enumerable: true, get: function () { return agent_js_1.BaseSingleActionAgent; } });
|
|
@@ -42,10 +42,17 @@ var types_js_1 = require("./types.cjs");
|
|
|
42
42
|
Object.defineProperty(exports, "AgentActionOutputParser", { enumerable: true, get: function () { return types_js_1.AgentActionOutputParser; } });
|
|
43
43
|
var index_js_5 = require("./structured_chat/index.cjs");
|
|
44
44
|
Object.defineProperty(exports, "StructuredChatAgent", { enumerable: true, get: function () { return index_js_5.StructuredChatAgent; } });
|
|
45
|
+
Object.defineProperty(exports, "createStructuredChatAgent", { enumerable: true, get: function () { return index_js_5.createStructuredChatAgent; } });
|
|
45
46
|
var outputParser_js_4 = require("./structured_chat/outputParser.cjs");
|
|
46
47
|
Object.defineProperty(exports, "StructuredChatOutputParser", { enumerable: true, get: function () { return outputParser_js_4.StructuredChatOutputParser; } });
|
|
47
48
|
Object.defineProperty(exports, "StructuredChatOutputParserWithRetries", { enumerable: true, get: function () { return outputParser_js_4.StructuredChatOutputParserWithRetries; } });
|
|
48
|
-
var index_js_6 = require("./
|
|
49
|
+
var index_js_6 = require("./openai_functions/index.cjs");
|
|
49
50
|
Object.defineProperty(exports, "OpenAIAgent", { enumerable: true, get: function () { return index_js_6.OpenAIAgent; } });
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
Object.defineProperty(exports, "createOpenAIFunctionsAgent", { enumerable: true, get: function () { return index_js_6.createOpenAIFunctionsAgent; } });
|
|
52
|
+
var index_js_7 = require("./openai_tools/index.cjs");
|
|
53
|
+
Object.defineProperty(exports, "createOpenAIToolsAgent", { enumerable: true, get: function () { return index_js_7.createOpenAIToolsAgent; } });
|
|
54
|
+
var index_js_8 = require("./xml/index.cjs");
|
|
55
|
+
Object.defineProperty(exports, "XMLAgent", { enumerable: true, get: function () { return index_js_8.XMLAgent; } });
|
|
56
|
+
Object.defineProperty(exports, "createXmlAgent", { enumerable: true, get: function () { return index_js_8.createXmlAgent; } });
|
|
57
|
+
var index_js_9 = require("./react/index.cjs");
|
|
58
|
+
Object.defineProperty(exports, "createReactAgent", { enumerable: true, get: function () { return index_js_9.createReactAgent; } });
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -10,7 +10,10 @@ export { initializeAgentExecutor, initializeAgentExecutorWithOptions, type Initi
|
|
|
10
10
|
export { ZeroShotAgent, type ZeroShotAgentInput, type ZeroShotCreatePromptArgs, } from "./mrkl/index.js";
|
|
11
11
|
export { ZeroShotAgentOutputParser } from "./mrkl/outputParser.js";
|
|
12
12
|
export { AgentActionOutputParser, type AgentInput, type SerializedAgent, type SerializedAgentT, type SerializedZeroShotAgent, type StoppingMethod, } from "./types.js";
|
|
13
|
-
export { StructuredChatAgent, type StructuredChatAgentInput, type StructuredChatCreatePromptArgs, } from "./structured_chat/index.js";
|
|
13
|
+
export { StructuredChatAgent, type StructuredChatAgentInput, type StructuredChatCreatePromptArgs, type CreateStructuredChatAgentParams, createStructuredChatAgent, } from "./structured_chat/index.js";
|
|
14
14
|
export { StructuredChatOutputParser, type StructuredChatOutputParserArgs, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
|
|
15
|
-
export { OpenAIAgent, type OpenAIAgentInput, type OpenAIAgentCreatePromptArgs, } from "./
|
|
16
|
-
export {
|
|
15
|
+
export { OpenAIAgent, type OpenAIAgentInput, type OpenAIAgentCreatePromptArgs, type CreateOpenAIFunctionsAgentParams, createOpenAIFunctionsAgent, } from "./openai_functions/index.js";
|
|
16
|
+
export { type CreateOpenAIToolsAgentParams, createOpenAIToolsAgent, } from "./openai_tools/index.js";
|
|
17
|
+
export { XMLAgent, type XMLAgentInput, type CreateXmlAgentParams, createXmlAgent, } from "./xml/index.js";
|
|
18
|
+
export { type CreateReactAgentParams, createReactAgent, } from "./react/index.js";
|
|
19
|
+
export type { AgentAction, AgentFinish, AgentStep } from "../schema/index.js";
|
package/dist/agents/index.js
CHANGED
|
@@ -10,7 +10,9 @@ export { initializeAgentExecutor, initializeAgentExecutorWithOptions, } from "./
|
|
|
10
10
|
export { ZeroShotAgent, } from "./mrkl/index.js";
|
|
11
11
|
export { ZeroShotAgentOutputParser } from "./mrkl/outputParser.js";
|
|
12
12
|
export { AgentActionOutputParser, } from "./types.js";
|
|
13
|
-
export { StructuredChatAgent, } from "./structured_chat/index.js";
|
|
13
|
+
export { StructuredChatAgent, createStructuredChatAgent, } from "./structured_chat/index.js";
|
|
14
14
|
export { StructuredChatOutputParser, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
|
|
15
|
-
export { OpenAIAgent, } from "./
|
|
16
|
-
export {
|
|
15
|
+
export { OpenAIAgent, createOpenAIFunctionsAgent, } from "./openai_functions/index.js";
|
|
16
|
+
export { createOpenAIToolsAgent, } from "./openai_tools/index.js";
|
|
17
|
+
export { XMLAgent, createXmlAgent, } from "./xml/index.js";
|
|
18
|
+
export { createReactAgent, } from "./react/index.js";
|
|
@@ -7,7 +7,7 @@ const index_js_2 = require("./chat_convo/index.cjs");
|
|
|
7
7
|
const index_js_3 = require("./structured_chat/index.cjs");
|
|
8
8
|
const executor_js_1 = require("./executor.cjs");
|
|
9
9
|
const index_js_4 = require("./mrkl/index.cjs");
|
|
10
|
-
const index_js_5 = require("./
|
|
10
|
+
const index_js_5 = require("./openai_functions/index.cjs");
|
|
11
11
|
const index_js_6 = require("./xml/index.cjs");
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated use initializeAgentExecutorWithOptions instead
|
|
@@ -6,7 +6,7 @@ import { ChatConversationalAgent } from "./chat_convo/index.js";
|
|
|
6
6
|
import { StructuredChatAgent } from "./structured_chat/index.js";
|
|
7
7
|
import { AgentExecutor, AgentExecutorInput } from "./executor.js";
|
|
8
8
|
import { ZeroShotAgent } from "./mrkl/index.js";
|
|
9
|
-
import { OpenAIAgent } from "./
|
|
9
|
+
import { OpenAIAgent } from "./openai_functions/index.js";
|
|
10
10
|
import { XMLAgent } from "./xml/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* Represents the type of an agent in LangChain. It can be
|
|
@@ -4,7 +4,7 @@ import { ChatConversationalAgent } from "./chat_convo/index.js";
|
|
|
4
4
|
import { StructuredChatAgent } from "./structured_chat/index.js";
|
|
5
5
|
import { AgentExecutor } from "./executor.js";
|
|
6
6
|
import { ZeroShotAgent } from "./mrkl/index.js";
|
|
7
|
-
import { OpenAIAgent } from "./
|
|
7
|
+
import { OpenAIAgent } from "./openai_functions/index.js";
|
|
8
8
|
import { XMLAgent } from "./xml/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* @deprecated use initializeAgentExecutorWithOptions instead
|