langchain 0.1.22 → 0.1.23

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Agent = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.BaseAgent = void 0;
4
4
  const serializable_1 = require("@langchain/core/load/serializable");
5
+ const runnables_1 = require("@langchain/core/runnables");
5
6
  /**
6
7
  * Error class for parse errors in LangChain. Contains information about
7
8
  * the error message and the output that caused the error.
@@ -119,12 +120,12 @@ class RunnableAgent extends BaseMultiActionAgent {
119
120
  this.runnable = fields.runnable;
120
121
  this.stop = fields.stop;
121
122
  }
122
- async plan(steps, inputs, callbackManager) {
123
+ async plan(steps, inputs, callbackManager, config) {
123
124
  const invokeInput = { ...inputs, steps };
124
- const output = await this.runnable.invoke(invokeInput, {
125
+ const output = await this.runnable.invoke(invokeInput, (0, runnables_1.patchConfig)(config, {
125
126
  callbacks: callbackManager,
126
127
  runName: "RunnableAgent",
127
- });
128
+ }));
128
129
  if (isAgentAction(output)) {
129
130
  return [output];
130
131
  }
@@ -6,7 +6,7 @@ import { AgentAction, AgentFinish, AgentStep } from "@langchain/core/agents";
6
6
  import { BaseMessage } from "@langchain/core/messages";
7
7
  import { ChainValues } from "@langchain/core/utils/types";
8
8
  import { Serializable } from "@langchain/core/load/serializable";
9
- import { Runnable } from "@langchain/core/runnables";
9
+ import { Runnable, type RunnableConfig } from "@langchain/core/runnables";
10
10
  import { LLMChain } from "../chains/llm_chain.js";
11
11
  import { AgentActionOutputParser, AgentInput, RunnableAgentInput, SerializedAgent, StoppingMethod } from "./types.js";
12
12
  /**
@@ -55,7 +55,7 @@ export declare abstract class BaseSingleActionAgent extends BaseAgent {
55
55
  *
56
56
  * @returns Action specifying what tool to use.
57
57
  */
58
- abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction | AgentFinish>;
58
+ abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager, config?: RunnableConfig): Promise<AgentAction | AgentFinish>;
59
59
  }
60
60
  /**
61
61
  * Abstract base class for multi-action agents in LangChain. Extends the
@@ -73,7 +73,7 @@ export declare abstract class BaseMultiActionAgent extends BaseAgent {
73
73
  *
74
74
  * @returns Actions specifying what tools to use.
75
75
  */
76
- abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction[] | AgentFinish>;
76
+ abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager, config?: RunnableConfig): Promise<AgentAction[] | AgentFinish>;
77
77
  }
78
78
  /**
79
79
  * Class representing a single action agent which accepts runnables.
@@ -89,7 +89,7 @@ export declare class RunnableAgent extends BaseMultiActionAgent {
89
89
  stop?: string[];
90
90
  get inputKeys(): string[];
91
91
  constructor(fields: RunnableAgentInput);
92
- plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction[] | AgentFinish>;
92
+ plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager, config?: RunnableConfig): Promise<AgentAction[] | AgentFinish>;
93
93
  }
94
94
  /**
95
95
  * Interface for input data for creating a LLMSingleActionAgent.
@@ -1,4 +1,5 @@
1
1
  import { Serializable } from "@langchain/core/load/serializable";
2
+ import { patchConfig, } from "@langchain/core/runnables";
2
3
  /**
3
4
  * Error class for parse errors in LangChain. Contains information about
4
5
  * the error message and the output that caused the error.
@@ -113,12 +114,12 @@ export class RunnableAgent extends BaseMultiActionAgent {
113
114
  this.runnable = fields.runnable;
114
115
  this.stop = fields.stop;
115
116
  }
116
- async plan(steps, inputs, callbackManager) {
117
+ async plan(steps, inputs, callbackManager, config) {
117
118
  const invokeInput = { ...inputs, steps };
118
- const output = await this.runnable.invoke(invokeInput, {
119
+ const output = await this.runnable.invoke(invokeInput, patchConfig(config, {
119
120
  callbacks: callbackManager,
120
121
  runName: "RunnableAgent",
121
- });
122
+ }));
122
123
  if (isAgentAction(output)) {
123
124
  return [output];
124
125
  }
@@ -46,24 +46,34 @@ class AgentExecutorIterator extends serializable_1.Serializable {
46
46
  writable: true,
47
47
  value: void 0
48
48
  });
49
+ Object.defineProperty(this, "config", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: void 0
54
+ });
55
+ /** @deprecated Use "config" */
49
56
  Object.defineProperty(this, "callbacks", {
50
57
  enumerable: true,
51
58
  configurable: true,
52
59
  writable: true,
53
60
  value: void 0
54
61
  });
62
+ /** @deprecated Use "config" */
55
63
  Object.defineProperty(this, "tags", {
56
64
  enumerable: true,
57
65
  configurable: true,
58
66
  writable: true,
59
67
  value: void 0
60
68
  });
69
+ /** @deprecated Use "config" */
61
70
  Object.defineProperty(this, "metadata", {
62
71
  enumerable: true,
63
72
  configurable: true,
64
73
  writable: true,
65
74
  value: void 0
66
75
  });
76
+ /** @deprecated Use "config" */
67
77
  Object.defineProperty(this, "runName", {
68
78
  enumerable: true,
69
79
  configurable: true,
@@ -101,6 +111,7 @@ class AgentExecutorIterator extends serializable_1.Serializable {
101
111
  this.metadata = fields.metadata;
102
112
  this.runName = fields.runName;
103
113
  this.runManager = fields.runManager;
114
+ this.config = fields.config;
104
115
  }
105
116
  /**
106
117
  * Reset the iterator to its initial state, clearing intermediate steps,
@@ -158,7 +169,7 @@ class AgentExecutorIterator extends serializable_1.Serializable {
158
169
  * AgentExecutor's _takeNextStep method.
159
170
  */
160
171
  async _executeNextStep(runManager) {
161
- return this.agentExecutor._takeNextStep(this.nameToToolMap, this.inputs, this.intermediateSteps, runManager);
172
+ return this.agentExecutor._takeNextStep(this.nameToToolMap, this.inputs, this.intermediateSteps, runManager, this.config);
162
173
  }
163
174
  /**
164
175
  * Process the output of the next step,
@@ -390,7 +401,7 @@ class AgentExecutor extends base_js_1.BaseChain {
390
401
  while (this.shouldContinue(iterations)) {
391
402
  let output;
392
403
  try {
393
- output = await this.agent.plan(steps, inputs, runManager?.getChild());
404
+ output = await this.agent.plan(steps, inputs, runManager?.getChild(), config);
394
405
  }
395
406
  catch (e) {
396
407
  // eslint-disable-next-line no-instanceof/no-instanceof
@@ -483,10 +494,10 @@ class AgentExecutor extends base_js_1.BaseChain {
483
494
  const finish = await this.agent.returnStoppedResponse(this.earlyStoppingMethod, steps, inputs);
484
495
  return getOutput(finish);
485
496
  }
486
- async _takeNextStep(nameToolMap, inputs, intermediateSteps, runManager) {
497
+ async _takeNextStep(nameToolMap, inputs, intermediateSteps, runManager, config) {
487
498
  let output;
488
499
  try {
489
- output = await this.agent.plan(intermediateSteps, inputs, runManager?.getChild());
500
+ output = await this.agent.plan(intermediateSteps, inputs, runManager?.getChild(), config);
490
501
  }
491
502
  catch (e) {
492
503
  // eslint-disable-next-line no-instanceof/no-instanceof
@@ -614,6 +625,8 @@ class AgentExecutor extends base_js_1.BaseChain {
614
625
  const agentExecutorIterator = new AgentExecutorIterator({
615
626
  inputs,
616
627
  agentExecutor: this,
628
+ config: options,
629
+ // TODO: Deprecate these other parameters
617
630
  metadata: options?.metadata,
618
631
  tags: options?.tags,
619
632
  callbacks: options?.callbacks,
@@ -12,8 +12,12 @@ import { BaseChain, ChainInputs } from "../chains/base.js";
12
12
  interface AgentExecutorIteratorInput {
13
13
  agentExecutor: AgentExecutor;
14
14
  inputs: Record<string, string>;
15
+ config?: RunnableConfig;
16
+ /** @deprecated Use "config" */
15
17
  callbacks?: Callbacks;
18
+ /** @deprecated Use "config" */
16
19
  tags?: string[];
20
+ /** @deprecated Use "config" */
17
21
  metadata?: Record<string, unknown>;
18
22
  runName?: string;
19
23
  runManager?: CallbackManagerForChainRun;
@@ -22,9 +26,14 @@ export declare class AgentExecutorIterator extends Serializable implements Agent
22
26
  lc_namespace: string[];
23
27
  agentExecutor: AgentExecutor;
24
28
  inputs: Record<string, string>;
29
+ config?: RunnableConfig;
30
+ /** @deprecated Use "config" */
25
31
  callbacks?: Callbacks;
32
+ /** @deprecated Use "config" */
26
33
  tags: string[] | undefined;
34
+ /** @deprecated Use "config" */
27
35
  metadata: Record<string, unknown> | undefined;
36
+ /** @deprecated Use "config" */
28
37
  runName: string | undefined;
29
38
  private _finalOutputs;
30
39
  get finalOutputs(): Record<string, unknown> | undefined;
@@ -141,7 +150,7 @@ export declare class AgentExecutor extends BaseChain<ChainValues, AgentExecutorO
141
150
  private shouldContinue;
142
151
  /** @ignore */
143
152
  _call(inputs: ChainValues, runManager?: CallbackManagerForChainRun, config?: RunnableConfig): Promise<AgentExecutorOutput>;
144
- _takeNextStep(nameToolMap: Record<string, ToolInterface>, inputs: ChainValues, intermediateSteps: AgentStep[], runManager?: CallbackManagerForChainRun): Promise<AgentFinish | AgentStep[]>;
153
+ _takeNextStep(nameToolMap: Record<string, ToolInterface>, inputs: ChainValues, intermediateSteps: AgentStep[], runManager?: CallbackManagerForChainRun, config?: RunnableConfig): Promise<AgentFinish | AgentStep[]>;
145
154
  _return(output: AgentFinish, intermediateSteps: AgentStep[], runManager?: CallbackManagerForChainRun): Promise<AgentExecutorOutput>;
146
155
  _getToolReturn(nextStepOutput: AgentStep): Promise<AgentFinish | null>;
147
156
  _returnStoppedResponse(earlyStoppingMethod: StoppingMethod): AgentFinish;
@@ -43,24 +43,34 @@ export class AgentExecutorIterator extends Serializable {
43
43
  writable: true,
44
44
  value: void 0
45
45
  });
46
+ Object.defineProperty(this, "config", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: void 0
51
+ });
52
+ /** @deprecated Use "config" */
46
53
  Object.defineProperty(this, "callbacks", {
47
54
  enumerable: true,
48
55
  configurable: true,
49
56
  writable: true,
50
57
  value: void 0
51
58
  });
59
+ /** @deprecated Use "config" */
52
60
  Object.defineProperty(this, "tags", {
53
61
  enumerable: true,
54
62
  configurable: true,
55
63
  writable: true,
56
64
  value: void 0
57
65
  });
66
+ /** @deprecated Use "config" */
58
67
  Object.defineProperty(this, "metadata", {
59
68
  enumerable: true,
60
69
  configurable: true,
61
70
  writable: true,
62
71
  value: void 0
63
72
  });
73
+ /** @deprecated Use "config" */
64
74
  Object.defineProperty(this, "runName", {
65
75
  enumerable: true,
66
76
  configurable: true,
@@ -98,6 +108,7 @@ export class AgentExecutorIterator extends Serializable {
98
108
  this.metadata = fields.metadata;
99
109
  this.runName = fields.runName;
100
110
  this.runManager = fields.runManager;
111
+ this.config = fields.config;
101
112
  }
102
113
  /**
103
114
  * Reset the iterator to its initial state, clearing intermediate steps,
@@ -155,7 +166,7 @@ export class AgentExecutorIterator extends Serializable {
155
166
  * AgentExecutor's _takeNextStep method.
156
167
  */
157
168
  async _executeNextStep(runManager) {
158
- return this.agentExecutor._takeNextStep(this.nameToToolMap, this.inputs, this.intermediateSteps, runManager);
169
+ return this.agentExecutor._takeNextStep(this.nameToToolMap, this.inputs, this.intermediateSteps, runManager, this.config);
159
170
  }
160
171
  /**
161
172
  * Process the output of the next step,
@@ -385,7 +396,7 @@ export class AgentExecutor extends BaseChain {
385
396
  while (this.shouldContinue(iterations)) {
386
397
  let output;
387
398
  try {
388
- output = await this.agent.plan(steps, inputs, runManager?.getChild());
399
+ output = await this.agent.plan(steps, inputs, runManager?.getChild(), config);
389
400
  }
390
401
  catch (e) {
391
402
  // eslint-disable-next-line no-instanceof/no-instanceof
@@ -478,10 +489,10 @@ export class AgentExecutor extends BaseChain {
478
489
  const finish = await this.agent.returnStoppedResponse(this.earlyStoppingMethod, steps, inputs);
479
490
  return getOutput(finish);
480
491
  }
481
- async _takeNextStep(nameToolMap, inputs, intermediateSteps, runManager) {
492
+ async _takeNextStep(nameToolMap, inputs, intermediateSteps, runManager, config) {
482
493
  let output;
483
494
  try {
484
- output = await this.agent.plan(intermediateSteps, inputs, runManager?.getChild());
495
+ output = await this.agent.plan(intermediateSteps, inputs, runManager?.getChild(), config);
485
496
  }
486
497
  catch (e) {
487
498
  // eslint-disable-next-line no-instanceof/no-instanceof
@@ -609,6 +620,8 @@ export class AgentExecutor extends BaseChain {
609
620
  const agentExecutorIterator = new AgentExecutorIterator({
610
621
  inputs,
611
622
  agentExecutor: this,
623
+ config: options,
624
+ // TODO: Deprecate these other parameters
612
625
  metadata: options?.metadata,
613
626
  tags: options?.tags,
614
627
  callbacks: options?.callbacks,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseChain = void 0;
4
4
  const outputs_1 = require("@langchain/core/outputs");
5
5
  const manager_1 = require("@langchain/core/callbacks/manager");
6
+ const runnables_1 = require("@langchain/core/runnables");
6
7
  const base_1 = require("@langchain/core/language_models/base");
7
8
  /**
8
9
  * Base interface that all chains must implement.
@@ -48,7 +49,7 @@ class BaseChain extends base_1.BaseLangChain {
48
49
  * @returns Promise that resolves with the output of the chain run.
49
50
  */
50
51
  async invoke(input, options) {
51
- const [config] = this._getOptionsList(options ?? {}, 1);
52
+ const config = (0, runnables_1.ensureConfig)(options);
52
53
  const fullValues = await this._formatValues(input);
53
54
  const callbackManager_ = await manager_1.CallbackManager.configure(config?.callbacks, this.callbacks, config?.tags, this.tags, config?.metadata, this.metadata, { verbose: this.verbose });
54
55
  const runManager = await callbackManager_?.handleChainStart(this.toJSON(), fullValues, undefined, undefined, undefined, undefined, config?.runName);
@@ -1,5 +1,6 @@
1
1
  import { RUN_KEY } from "@langchain/core/outputs";
2
2
  import { CallbackManager, parseCallbackConfigArg, } from "@langchain/core/callbacks/manager";
3
+ import { ensureConfig } from "@langchain/core/runnables";
3
4
  import { BaseLangChain, } from "@langchain/core/language_models/base";
4
5
  /**
5
6
  * Base interface that all chains must implement.
@@ -45,7 +46,7 @@ export class BaseChain extends BaseLangChain {
45
46
  * @returns Promise that resolves with the output of the chain run.
46
47
  */
47
48
  async invoke(input, options) {
48
- const [config] = this._getOptionsList(options ?? {}, 1);
49
+ const config = ensureConfig(options);
49
50
  const fullValues = await this._formatValues(input);
50
51
  const callbackManager_ = await CallbackManager.configure(config?.callbacks, this.callbacks, config?.tags, this.tags, config?.metadata, this.metadata, { verbose: this.verbose });
51
52
  const runManager = await callbackManager_?.handleChainStart(this.toJSON(), fullValues, undefined, undefined, undefined, undefined, config?.runName);
@@ -14,10 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- const entrypoint_deprecation_js_1 = require("../util/entrypoint_deprecation.cjs");
18
17
  __exportStar(require("@langchain/core/utils/testing"), exports);
19
- /* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion010MigrationWarning)({
20
- oldEntrypointName: "embeddings/fake",
21
- newEntrypointName: "utils/testing",
22
- newPackageName: "@langchain/core",
23
- });
@@ -1,7 +1 @@
1
- import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
2
1
  export * from "@langchain/core/utils/testing";
3
- /* #__PURE__ */ logVersion010MigrationWarning({
4
- oldEntrypointName: "embeddings/fake",
5
- newEntrypointName: "utils/testing",
6
- newPackageName: "@langchain/core",
7
- });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -1508,8 +1508,8 @@
1508
1508
  },
1509
1509
  "dependencies": {
1510
1510
  "@anthropic-ai/sdk": "^0.9.1",
1511
- "@langchain/community": "~0.0.32",
1512
- "@langchain/core": "~0.1.34",
1511
+ "@langchain/community": "~0.0.33",
1512
+ "@langchain/core": "~0.1.36",
1513
1513
  "@langchain/openai": "~0.0.14",
1514
1514
  "binary-extensions": "^2.2.0",
1515
1515
  "expr-eval": "^2.0.2",
@@ -1517,7 +1517,7 @@
1517
1517
  "js-yaml": "^4.1.0",
1518
1518
  "jsonpointer": "^5.0.1",
1519
1519
  "langchainhub": "~0.0.8",
1520
- "langsmith": "~0.1.1",
1520
+ "langsmith": "~0.1.7",
1521
1521
  "ml-distance": "^4.0.0",
1522
1522
  "openapi-types": "^12.1.3",
1523
1523
  "p-retry": "4",