@langchain/core 0.3.65 → 0.3.66

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.
@@ -60,9 +60,19 @@ class StructuredTool extends base_js_1.BaseLangChain {
60
60
  writable: true,
61
61
  value: "content"
62
62
  });
63
+ /**
64
+ * Default config object for the tool runnable.
65
+ */
66
+ Object.defineProperty(this, "defaultConfig", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
63
72
  this.verboseParsingErrors =
64
73
  fields?.verboseParsingErrors ?? this.verboseParsingErrors;
65
74
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
75
+ this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;
66
76
  }
67
77
  /**
68
78
  * Invokes the tool with the provided input and configuration.
@@ -72,7 +82,7 @@ class StructuredTool extends base_js_1.BaseLangChain {
72
82
  */
73
83
  async invoke(input, config) {
74
84
  let toolInput;
75
- let enrichedConfig = (0, config_js_1.ensureConfig)(config);
85
+ let enrichedConfig = (0, config_js_1.ensureConfig)((0, config_js_1.mergeConfigs)(this.defaultConfig, config));
76
86
  if ((0, utils_js_1._isToolCall)(input)) {
77
87
  toolInput = input.args;
78
88
  enrichedConfig = {
@@ -37,6 +37,10 @@ export declare abstract class StructuredTool<SchemaT = ToolInputSchemaBase, Sche
37
37
  * @default "content"
38
38
  */
39
39
  responseFormat?: ResponseFormat;
40
+ /**
41
+ * Default config object for the tool runnable.
42
+ */
43
+ defaultConfig?: ToolRunnableConfig;
40
44
  constructor(fields?: ToolParams);
41
45
  protected abstract _call(arg: SchemaOutputT, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolOutputT>;
42
46
  /**
@@ -2,7 +2,7 @@ import { z } from "zod/v3";
2
2
  import { validate, } from "@cfworker/json-schema";
3
3
  import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
4
4
  import { BaseLangChain } from "../language_models/base.js";
5
- import { ensureConfig, patchConfig, pickRunnableConfigKeys, } from "../runnables/config.js";
5
+ import { mergeConfigs, ensureConfig, patchConfig, pickRunnableConfigKeys, } from "../runnables/config.js";
6
6
  import { isDirectToolOutput, ToolMessage } from "../messages/tool.js";
7
7
  import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";
8
8
  import { _configHasToolCallId, _isToolCall, ToolInputParsingException, } from "./utils.js";
@@ -52,9 +52,19 @@ export class StructuredTool extends BaseLangChain {
52
52
  writable: true,
53
53
  value: "content"
54
54
  });
55
+ /**
56
+ * Default config object for the tool runnable.
57
+ */
58
+ Object.defineProperty(this, "defaultConfig", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: void 0
63
+ });
55
64
  this.verboseParsingErrors =
56
65
  fields?.verboseParsingErrors ?? this.verboseParsingErrors;
57
66
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
67
+ this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;
58
68
  }
59
69
  /**
60
70
  * Invokes the tool with the provided input and configuration.
@@ -64,7 +74,7 @@ export class StructuredTool extends BaseLangChain {
64
74
  */
65
75
  async invoke(input, config) {
66
76
  let toolInput;
67
- let enrichedConfig = ensureConfig(config);
77
+ let enrichedConfig = ensureConfig(mergeConfigs(this.defaultConfig, config));
68
78
  if (_isToolCall(input)) {
69
79
  toolInput = input.args;
70
80
  enrichedConfig = {
@@ -48,6 +48,10 @@ export interface ToolParams extends BaseLangChainParams {
48
48
  * @default "content"
49
49
  */
50
50
  responseFormat?: ResponseFormat;
51
+ /**
52
+ * Default config object for the tool runnable.
53
+ */
54
+ defaultConfig?: ToolRunnableConfig;
51
55
  /**
52
56
  * Whether to show full details in the thrown parsing errors.
53
57
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.65",
3
+ "version": "0.3.66",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {