@langchain/core 0.3.35 → 0.3.37

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.
@@ -507,16 +507,44 @@ class Runnable extends serializable_js_1.Serializable {
507
507
  // eslint-disable-next-line no-param-reassign
508
508
  config.callbacks = copiedCallbacks;
509
509
  }
510
+ const abortController = new AbortController();
510
511
  // Call the runnable in streaming mode,
511
512
  // add each chunk to the output stream
512
513
  const outerThis = this;
513
514
  async function consumeRunnableStream() {
514
515
  try {
515
- const runnableStream = await outerThis.stream(input, config);
516
+ let signal;
517
+ if (options?.signal) {
518
+ if ("any" in AbortSignal) {
519
+ // Use native AbortSignal.any() if available (Node 19+)
520
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
521
+ signal = AbortSignal.any([
522
+ abortController.signal,
523
+ options.signal,
524
+ ]);
525
+ }
526
+ else {
527
+ // Fallback for Node 18 and below - just use the provided signal
528
+ signal = options.signal;
529
+ // Ensure we still abort our controller when the parent signal aborts
530
+ options.signal.addEventListener("abort", () => {
531
+ abortController.abort();
532
+ }, { once: true });
533
+ }
534
+ }
535
+ else {
536
+ signal = abortController.signal;
537
+ }
538
+ const runnableStream = await outerThis.stream(input, {
539
+ ...config,
540
+ signal,
541
+ });
516
542
  const tappedStream = eventStreamer.tapOutputIterable(runId, runnableStream);
517
543
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
518
544
  for await (const _ of tappedStream) {
519
545
  // Just iterate so that the callback handler picks up events
546
+ if (abortController.signal.aborted)
547
+ break;
520
548
  }
521
549
  }
522
550
  finally {
@@ -551,6 +579,7 @@ class Runnable extends serializable_js_1.Serializable {
551
579
  }
552
580
  }
553
581
  finally {
582
+ abortController.abort();
554
583
  await runnableStreamConsumePromise;
555
584
  }
556
585
  }
@@ -500,16 +500,44 @@ export class Runnable extends Serializable {
500
500
  // eslint-disable-next-line no-param-reassign
501
501
  config.callbacks = copiedCallbacks;
502
502
  }
503
+ const abortController = new AbortController();
503
504
  // Call the runnable in streaming mode,
504
505
  // add each chunk to the output stream
505
506
  const outerThis = this;
506
507
  async function consumeRunnableStream() {
507
508
  try {
508
- const runnableStream = await outerThis.stream(input, config);
509
+ let signal;
510
+ if (options?.signal) {
511
+ if ("any" in AbortSignal) {
512
+ // Use native AbortSignal.any() if available (Node 19+)
513
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
514
+ signal = AbortSignal.any([
515
+ abortController.signal,
516
+ options.signal,
517
+ ]);
518
+ }
519
+ else {
520
+ // Fallback for Node 18 and below - just use the provided signal
521
+ signal = options.signal;
522
+ // Ensure we still abort our controller when the parent signal aborts
523
+ options.signal.addEventListener("abort", () => {
524
+ abortController.abort();
525
+ }, { once: true });
526
+ }
527
+ }
528
+ else {
529
+ signal = abortController.signal;
530
+ }
531
+ const runnableStream = await outerThis.stream(input, {
532
+ ...config,
533
+ signal,
534
+ });
509
535
  const tappedStream = eventStreamer.tapOutputIterable(runId, runnableStream);
510
536
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
511
537
  for await (const _ of tappedStream) {
512
538
  // Just iterate so that the callback handler picks up events
539
+ if (abortController.signal.aborted)
540
+ break;
513
541
  }
514
542
  }
515
543
  finally {
@@ -544,6 +572,7 @@ export class Runnable extends Serializable {
544
572
  }
545
573
  }
546
574
  finally {
575
+ abortController.abort();
547
576
  await runnableStreamConsumePromise;
548
577
  }
549
578
  }
@@ -19,13 +19,18 @@ class StructuredTool extends base_js_1.BaseLangChain {
19
19
  }
20
20
  constructor(fields) {
21
21
  super(fields ?? {});
22
+ /**
23
+ * Whether to return the tool's output directly.
24
+ *
25
+ * Setting this to true means that after the tool is called,
26
+ * an agent should stop looping.
27
+ */
22
28
  Object.defineProperty(this, "returnDirect", {
23
29
  enumerable: true,
24
30
  configurable: true,
25
31
  writable: true,
26
32
  value: false
27
33
  });
28
- // TODO: Make default in 0.3
29
34
  Object.defineProperty(this, "verboseParsingErrors", {
30
35
  enumerable: true,
31
36
  configurable: true,
@@ -74,6 +74,12 @@ export interface StructuredToolInterface<T extends ZodObjectAny = ZodObjectAny>
74
74
  * A description of the tool.
75
75
  */
76
76
  description: string;
77
+ /**
78
+ * Whether to return the tool's output directly.
79
+ *
80
+ * Setting this to true means that after the tool is called,
81
+ * an agent should stop looping.
82
+ */
77
83
  returnDirect: boolean;
78
84
  }
79
85
  /**
@@ -83,6 +89,12 @@ export declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectA
83
89
  abstract name: string;
84
90
  abstract description: string;
85
91
  abstract schema: T | z.ZodEffects<T>;
92
+ /**
93
+ * Whether to return the tool's output directly.
94
+ *
95
+ * Setting this to true means that after the tool is called,
96
+ * an agent should stop looping.
97
+ */
86
98
  returnDirect: boolean;
87
99
  verboseParsingErrors: boolean;
88
100
  get lc_namespace(): string[];
@@ -160,6 +172,12 @@ export declare abstract class Tool extends StructuredTool<ZodObjectAny> {
160
172
  export interface BaseDynamicToolInput extends ToolParams {
161
173
  name: string;
162
174
  description: string;
175
+ /**
176
+ * Whether to return the tool's output directly.
177
+ *
178
+ * Setting this to true means that after the tool is called,
179
+ * an agent should stop looping.
180
+ */
163
181
  returnDirect?: boolean;
164
182
  }
165
183
  /**
@@ -257,6 +275,13 @@ interface ToolWrapperParams<RunInput extends ZodObjectAny | z.ZodString | Record
257
275
  * @default "content"
258
276
  */
259
277
  responseFormat?: ResponseFormat;
278
+ /**
279
+ * Whether to return the tool's output directly.
280
+ *
281
+ * Setting this to true means that after the tool is called,
282
+ * an agent should stop looping.
283
+ */
284
+ returnDirect?: boolean;
260
285
  }
261
286
  /**
262
287
  * Creates a new StructuredTool instance with the provided function, name, description, and schema.
@@ -16,13 +16,18 @@ export class StructuredTool extends BaseLangChain {
16
16
  }
17
17
  constructor(fields) {
18
18
  super(fields ?? {});
19
+ /**
20
+ * Whether to return the tool's output directly.
21
+ *
22
+ * Setting this to true means that after the tool is called,
23
+ * an agent should stop looping.
24
+ */
19
25
  Object.defineProperty(this, "returnDirect", {
20
26
  enumerable: true,
21
27
  configurable: true,
22
28
  writable: true,
23
29
  value: false
24
30
  });
25
- // TODO: Make default in 0.3
26
31
  Object.defineProperty(this, "verboseParsingErrors", {
27
32
  enumerable: true,
28
33
  configurable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.35",
3
+ "version": "0.3.37",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {