@langchain/core 0.2.31 → 0.3.0-rc.0

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 CHANGED
@@ -89,7 +89,7 @@ For more check out the [LCEL docs](https://js.langchain.com/v0.2/docs/concepts#l
89
89
 
90
90
  ## 📕 Releases & Versioning
91
91
 
92
- `@langchain/core` is currently on version `0.1.x`.
92
+ `@langchain/core` is currently on version `0.3.x`.
93
93
 
94
94
  As `@langchain/core` contains the base abstractions and runtime for the whole LangChain ecosystem, we will communicate any breaking changes with advance notice and version bumps. The exception for this is anything in `@langchain/core/beta`. The reason for `@langchain/core/beta` is that given the rate of change of the field, being able to move quickly is still a priority, and this module is our attempt to do so.
95
95
 
@@ -109,7 +109,7 @@ Patch version increases will occur for:
109
109
  Other LangChain packages should add this package as a dependency and extend the classes within.
110
110
  For an example, see the [@langchain/anthropic](https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-anthropic) in this repo.
111
111
 
112
- Because all used packages must share the same version of core, we suggest using a tilde dependency to allow for different (backwards-compatible) patch versions:
112
+ Because all used packages must share the same version of core, packages should never directly depend on `@langchain/core`. Instead they should have core as a peer dependency and a dev dependency. We suggest using a tilde dependency to allow for different (backwards-compatible) patch versions:
113
113
 
114
114
  ```json
115
115
  {
@@ -120,8 +120,13 @@ Because all used packages must share the same version of core, we suggest using
120
120
  "author": "LangChain",
121
121
  "license": "MIT",
122
122
  "dependencies": {
123
- "@anthropic-ai/sdk": "^0.10.0",
124
- "@langchain/core": "~0.1.5"
123
+ "@anthropic-ai/sdk": "^0.10.0"
124
+ },
125
+ "peerDependencies": {
126
+ "@langchain/core": "~0.3.0"
127
+ },
128
+ "devDependencies": {
129
+ "@langchain/core": "~0.3.0"
125
130
  }
126
131
  }
127
132
  ```
@@ -125,7 +125,7 @@ class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
125
125
  enumerable: true,
126
126
  configurable: true,
127
127
  writable: true,
128
- value: (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_CALLBACKS_BACKGROUND") !== "true"
128
+ value: (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
129
129
  });
130
130
  this.lc_kwargs = input || {};
131
131
  if (input) {
@@ -99,7 +99,7 @@ export class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
99
99
  enumerable: true,
100
100
  configurable: true,
101
101
  writable: true,
102
- value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") !== "true"
102
+ value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
103
103
  });
104
104
  this.lc_kwargs = input || {};
105
105
  if (input) {
@@ -10,16 +10,6 @@ const tracer_langchain_js_1 = require("../tracers/tracer_langchain.cjs");
10
10
  const promises_js_1 = require("./promises.cjs");
11
11
  const callbacks_js_1 = require("../utils/callbacks.cjs");
12
12
  const base_js_2 = require("../tracers/base.cjs");
13
- if (
14
- /* #__PURE__ */ (0, callbacks_js_1.isTracingEnabled)() &&
15
- /* #__PURE__ */ (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_CALLBACKS_BACKGROUND") !==
16
- "true") {
17
- /* #__PURE__ */ console.warn([
18
- "[WARN]: You have enabled LangSmith tracing without backgrounding callbacks.",
19
- "[WARN]: If you are not using a serverless environment where you must wait for tracing calls to finish,",
20
- `[WARN]: we suggest setting "process.env.LANGCHAIN_CALLBACKS_BACKGROUND=true" to avoid additional latency.`,
21
- ].join("\n"));
22
- }
23
13
  function parseCallbackConfigArg(arg) {
24
14
  if (!arg) {
25
15
  return {};
@@ -729,7 +719,7 @@ class CallbackManager extends BaseCallbackManager {
729
719
  manager.addHandler(new Handler());
730
720
  return manager;
731
721
  }
732
- static async configure(inheritableHandlers, localHandlers, inheritableTags, localTags, inheritableMetadata, localMetadata, options) {
722
+ static configure(inheritableHandlers, localHandlers, inheritableTags, localTags, inheritableMetadata, localMetadata, options) {
733
723
  return this._configureSync(inheritableHandlers, localHandlers, inheritableTags, localTags, inheritableMetadata, localMetadata, options);
734
724
  }
735
725
  // TODO: Deprecate async method in favor of this one.
@@ -152,7 +152,7 @@ export declare class CallbackManager extends BaseCallbackManager implements Base
152
152
  removeMetadata(metadata: Record<string, unknown>): void;
153
153
  copy(additionalHandlers?: BaseCallbackHandler[], inherit?: boolean): CallbackManager;
154
154
  static fromHandlers(handlers: CallbackHandlerMethods): CallbackManager;
155
- static configure(inheritableHandlers?: Callbacks, localHandlers?: Callbacks, inheritableTags?: string[], localTags?: string[], inheritableMetadata?: Record<string, unknown>, localMetadata?: Record<string, unknown>, options?: CallbackManagerOptions): Promise<CallbackManager | undefined>;
155
+ static configure(inheritableHandlers?: Callbacks, localHandlers?: Callbacks, inheritableTags?: string[], localTags?: string[], inheritableMetadata?: Record<string, unknown>, localMetadata?: Record<string, unknown>, options?: CallbackManagerOptions): CallbackManager | undefined;
156
156
  static _configureSync(inheritableHandlers?: Callbacks, localHandlers?: Callbacks, inheritableTags?: string[], localTags?: string[], inheritableMetadata?: Record<string, unknown>, localMetadata?: Record<string, unknown>, options?: CallbackManagerOptions): CallbackManager | undefined;
157
157
  }
158
158
  export declare function ensureHandler(handler: BaseCallbackHandler | CallbackHandlerMethods): BaseCallbackHandler;
@@ -7,16 +7,6 @@ import { LangChainTracer, } from "../tracers/tracer_langchain.js";
7
7
  import { consumeCallback } from "./promises.js";
8
8
  import { isTracingEnabled } from "../utils/callbacks.js";
9
9
  import { isBaseTracer } from "../tracers/base.js";
10
- if (
11
- /* #__PURE__ */ isTracingEnabled() &&
12
- /* #__PURE__ */ getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") !==
13
- "true") {
14
- /* #__PURE__ */ console.warn([
15
- "[WARN]: You have enabled LangSmith tracing without backgrounding callbacks.",
16
- "[WARN]: If you are not using a serverless environment where you must wait for tracing calls to finish,",
17
- `[WARN]: we suggest setting "process.env.LANGCHAIN_CALLBACKS_BACKGROUND=true" to avoid additional latency.`,
18
- ].join("\n"));
19
- }
20
10
  export function parseCallbackConfigArg(arg) {
21
11
  if (!arg) {
22
12
  return {};
@@ -719,7 +709,7 @@ export class CallbackManager extends BaseCallbackManager {
719
709
  manager.addHandler(new Handler());
720
710
  return manager;
721
711
  }
722
- static async configure(inheritableHandlers, localHandlers, inheritableTags, localTags, inheritableMetadata, localMetadata, options) {
712
+ static configure(inheritableHandlers, localHandlers, inheritableTags, localTags, inheritableMetadata, localMetadata, options) {
723
713
  return this._configureSync(inheritableHandlers, localHandlers, inheritableTags, localTags, inheritableMetadata, localMetadata, options);
724
714
  }
725
715
  // TODO: Deprecate async method in favor of this one.
@@ -55,30 +55,12 @@ export interface FunctionCall {
55
55
  */
56
56
  name: string;
57
57
  }
58
- /**
59
- * @deprecated
60
- * Import as "OpenAIToolCall" instead
61
- */
62
- export interface ToolCall {
63
- /**
64
- * The ID of the tool call.
65
- */
66
- id: string;
67
- /**
68
- * The function that the model called.
69
- */
70
- function: FunctionCall;
71
- /**
72
- * The type of the tool. Currently, only `function` is supported.
73
- */
74
- type: "function";
75
- }
76
58
  export type BaseMessageFields = {
77
59
  content: MessageContent;
78
60
  name?: string;
79
61
  additional_kwargs?: {
80
62
  function_call?: FunctionCall;
81
- tool_calls?: ToolCall[];
63
+ tool_calls?: OpenAIToolCall[];
82
64
  [key: string]: unknown;
83
65
  };
84
66
  /** Response metadata. For example: response headers, logprobs, token counts. */
@@ -137,8 +119,20 @@ export declare abstract class BaseMessage extends Serializable implements BaseMe
137
119
  _updateId(value: string | undefined): void;
138
120
  get [Symbol.toStringTag](): any;
139
121
  }
140
- export type OpenAIToolCall = ToolCall & {
141
- index: number;
122
+ export type OpenAIToolCall = {
123
+ /**
124
+ * The ID of the tool call.
125
+ */
126
+ id: string;
127
+ /**
128
+ * The function that the model called.
129
+ */
130
+ function: FunctionCall;
131
+ /**
132
+ * The type of the tool. Currently, only `function` is supported.
133
+ */
134
+ type: "function";
135
+ index?: number;
142
136
  };
143
137
  export declare function isOpenAIToolCallArray(value?: unknown): value is OpenAIToolCall[];
144
138
  export declare function _mergeDicts(left: Record<string, any>, right: Record<string, any>): Record<string, any>;
@@ -942,7 +942,7 @@ class RunnableEach extends Runnable {
942
942
  * @returns A promise that resolves to the output of the runnable.
943
943
  */
944
944
  async invoke(inputs, config) {
945
- return this._callWithConfig(this._invoke, inputs, config);
945
+ return this._callWithConfig(this._invoke.bind(this), inputs, config);
946
946
  }
947
947
  /**
948
948
  * A helper method that is used to invoke the runnable with the specified input and configuration.
@@ -1026,7 +1026,7 @@ class RunnableRetry extends RunnableBinding {
1026
1026
  * @returns A promise that resolves to the output of the runnable.
1027
1027
  */
1028
1028
  async invoke(input, config) {
1029
- return this._callWithConfig(this._invoke, input, config);
1029
+ return this._callWithConfig(this._invoke.bind(this), input, config);
1030
1030
  }
1031
1031
  async _batch(inputs, configs, runManagers, batchOptions) {
1032
1032
  const resultsMap = {};
@@ -1590,7 +1590,7 @@ class RunnableLambda extends Runnable {
1590
1590
  });
1591
1591
  }
1592
1592
  async invoke(input, options) {
1593
- return this._callWithConfig(this._invoke, input, options);
1593
+ return this._callWithConfig(this._invoke.bind(this), input, options);
1594
1594
  }
1595
1595
  async *_transform(generator, runManager, config) {
1596
1596
  let finalChunk;
@@ -11,13 +11,7 @@ import { Run } from "../tracers/base.js";
11
11
  import { Graph } from "./graph.js";
12
12
  import { ToolCall } from "../messages/tool.js";
13
13
  export { type RunnableInterface, RunnableBatchOptions };
14
- export type RunnableFunc<RunInput, RunOutput> = (input: RunInput, options?: ({
15
- /** @deprecated Use top-level config fields instead. */
16
- config?: RunnableConfig;
17
- } & RunnableConfig) | Record<string, any> | (Record<string, any> & {
18
- /** @deprecated Use top-level config fields instead. */
19
- config: RunnableConfig;
20
- } & RunnableConfig)) => RunOutput | Promise<RunOutput>;
14
+ export type RunnableFunc<RunInput, RunOutput> = (input: RunInput, options: RunnableConfig | Record<string, any> | (Record<string, any> & RunnableConfig)) => RunOutput | Promise<RunOutput>;
21
15
  export type RunnableMapLike<RunInput, RunOutput> = {
22
16
  [K in keyof RunOutput]: RunnableLike<RunInput, RunOutput[K]>;
23
17
  };
@@ -351,7 +345,7 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
351
345
  batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
352
346
  _streamIterator(input: RunInput, options?: Partial<CallOptions> | undefined): AsyncGenerator<Awaited<RunOutput>, void, unknown>;
353
347
  stream(input: RunInput, options?: Partial<CallOptions> | undefined): Promise<IterableReadableStream<RunOutput>>;
354
- transform(generator: AsyncGenerator<RunInput>, options: Partial<CallOptions>): AsyncGenerator<RunOutput>;
348
+ transform(generator: AsyncGenerator<RunInput>, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
355
349
  streamEvents(input: RunInput, options: Partial<CallOptions> & {
356
350
  version: "v1" | "v2";
357
351
  }, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
@@ -933,7 +933,7 @@ export class RunnableEach extends Runnable {
933
933
  * @returns A promise that resolves to the output of the runnable.
934
934
  */
935
935
  async invoke(inputs, config) {
936
- return this._callWithConfig(this._invoke, inputs, config);
936
+ return this._callWithConfig(this._invoke.bind(this), inputs, config);
937
937
  }
938
938
  /**
939
939
  * A helper method that is used to invoke the runnable with the specified input and configuration.
@@ -1016,7 +1016,7 @@ export class RunnableRetry extends RunnableBinding {
1016
1016
  * @returns A promise that resolves to the output of the runnable.
1017
1017
  */
1018
1018
  async invoke(input, config) {
1019
- return this._callWithConfig(this._invoke, input, config);
1019
+ return this._callWithConfig(this._invoke.bind(this), input, config);
1020
1020
  }
1021
1021
  async _batch(inputs, configs, runManagers, batchOptions) {
1022
1022
  const resultsMap = {};
@@ -1576,7 +1576,7 @@ export class RunnableLambda extends Runnable {
1576
1576
  });
1577
1577
  }
1578
1578
  async invoke(input, options) {
1579
- return this._callWithConfig(this._invoke, input, options);
1579
+ return this._callWithConfig(this._invoke.bind(this), input, options);
1580
1580
  }
1581
1581
  async *_transform(generator, runManager, config) {
1582
1582
  let finalChunk;
@@ -61,12 +61,7 @@ class RootListenersTracer extends base_js_1.BaseTracer {
61
61
  }
62
62
  this.rootId = run.id;
63
63
  if (this.argOnStart) {
64
- if (this.argOnStart.length === 1) {
65
- await this.argOnStart(run);
66
- }
67
- else if (this.argOnStart.length === 2) {
68
- await this.argOnStart(run, this.config);
69
- }
64
+ await this.argOnStart(run, this.config);
70
65
  }
71
66
  }
72
67
  async onRunUpdate(run) {
@@ -75,21 +70,11 @@ class RootListenersTracer extends base_js_1.BaseTracer {
75
70
  }
76
71
  if (!run.error) {
77
72
  if (this.argOnEnd) {
78
- if (this.argOnEnd.length === 1) {
79
- await this.argOnEnd(run);
80
- }
81
- else if (this.argOnEnd.length === 2) {
82
- await this.argOnEnd(run, this.config);
83
- }
73
+ await this.argOnEnd(run, this.config);
84
74
  }
85
75
  }
86
76
  else if (this.argOnError) {
87
- if (this.argOnError.length === 1) {
88
- await this.argOnError(run);
89
- }
90
- else if (this.argOnError.length === 2) {
91
- await this.argOnError(run, this.config);
92
- }
77
+ await this.argOnError(run, this.config);
93
78
  }
94
79
  }
95
80
  }
@@ -5,23 +5,14 @@ export declare class RootListenersTracer extends BaseTracer {
5
5
  /** The Run's ID. Type UUID */
6
6
  rootId?: string;
7
7
  config: RunnableConfig;
8
- argOnStart?: {
9
- (run: Run): void | Promise<void>;
10
- (run: Run, config: RunnableConfig): void | Promise<void>;
11
- };
12
- argOnEnd?: {
13
- (run: Run): void | Promise<void>;
14
- (run: Run, config: RunnableConfig): void | Promise<void>;
15
- };
16
- argOnError?: {
17
- (run: Run): void | Promise<void>;
18
- (run: Run, config: RunnableConfig): void | Promise<void>;
19
- };
8
+ argOnStart?: (run: Run, config: RunnableConfig) => void | Promise<void>;
9
+ argOnEnd?: (run: Run, config: RunnableConfig) => void | Promise<void>;
10
+ argOnError?: (run: Run, config: RunnableConfig) => void | Promise<void>;
20
11
  constructor({ config, onStart, onEnd, onError, }: {
21
12
  config: RunnableConfig;
22
- onStart?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
23
- onEnd?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
24
- onError?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
13
+ onStart?: (run: Run, config: RunnableConfig) => void | Promise<void>;
14
+ onEnd?: (run: Run, config: RunnableConfig) => void | Promise<void>;
15
+ onError?: (run: Run, config: RunnableConfig) => void | Promise<void>;
25
16
  });
26
17
  /**
27
18
  * This is a legacy method only called once for an entire run tree
@@ -58,12 +58,7 @@ export class RootListenersTracer extends BaseTracer {
58
58
  }
59
59
  this.rootId = run.id;
60
60
  if (this.argOnStart) {
61
- if (this.argOnStart.length === 1) {
62
- await this.argOnStart(run);
63
- }
64
- else if (this.argOnStart.length === 2) {
65
- await this.argOnStart(run, this.config);
66
- }
61
+ await this.argOnStart(run, this.config);
67
62
  }
68
63
  }
69
64
  async onRunUpdate(run) {
@@ -72,21 +67,11 @@ export class RootListenersTracer extends BaseTracer {
72
67
  }
73
68
  if (!run.error) {
74
69
  if (this.argOnEnd) {
75
- if (this.argOnEnd.length === 1) {
76
- await this.argOnEnd(run);
77
- }
78
- else if (this.argOnEnd.length === 2) {
79
- await this.argOnEnd(run, this.config);
80
- }
70
+ await this.argOnEnd(run, this.config);
81
71
  }
82
72
  }
83
73
  else if (this.argOnError) {
84
- if (this.argOnError.length === 1) {
85
- await this.argOnError(run);
86
- }
87
- else if (this.argOnError.length === 2) {
88
- await this.argOnError(run, this.config);
89
- }
74
+ await this.argOnError(run, this.config);
90
75
  }
91
76
  }
92
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.2.31",
3
+ "version": "0.3.0-rc.0",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {