@langchain/core 0.3.67 → 0.3.69

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.
@@ -51,6 +51,12 @@ class ToolMessage extends base_js_1.BaseMessage {
51
51
  writable: true,
52
52
  value: void 0
53
53
  });
54
+ Object.defineProperty(this, "metadata", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
54
60
  /**
55
61
  * Artifact of the Tool execution which is not meant to be sent to the model.
56
62
  *
@@ -68,6 +74,7 @@ class ToolMessage extends base_js_1.BaseMessage {
68
74
  this.tool_call_id = fields.tool_call_id;
69
75
  this.artifact = fields.artifact;
70
76
  this.status = fields.status;
77
+ this.metadata = fields.metadata;
71
78
  }
72
79
  _getType() {
73
80
  return "tool";
@@ -18,6 +18,7 @@ export interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
18
18
  * @version 0.2.19
19
19
  */
20
20
  status?: "success" | "error";
21
+ metadata?: Record<string, unknown>;
21
22
  }
22
23
  /**
23
24
  * Marker parameter for objects that tools can return directly.
@@ -44,6 +45,7 @@ export declare class ToolMessage extends BaseMessage implements DirectToolOutput
44
45
  */
45
46
  status?: "success" | "error";
46
47
  tool_call_id: string;
48
+ metadata?: Record<string, unknown>;
47
49
  /**
48
50
  * Artifact of the Tool execution which is not meant to be sent to the model.
49
51
  *
@@ -44,6 +44,12 @@ export class ToolMessage extends BaseMessage {
44
44
  writable: true,
45
45
  value: void 0
46
46
  });
47
+ Object.defineProperty(this, "metadata", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
47
53
  /**
48
54
  * Artifact of the Tool execution which is not meant to be sent to the model.
49
55
  *
@@ -61,6 +67,7 @@ export class ToolMessage extends BaseMessage {
61
67
  this.tool_call_id = fields.tool_call_id;
62
68
  this.artifact = fields.artifact;
63
69
  this.status = fields.status;
70
+ this.metadata = fields.metadata;
64
71
  }
65
72
  _getType() {
66
73
  return "tool";
@@ -73,6 +73,7 @@ class StructuredTool extends base_js_1.BaseLangChain {
73
73
  fields?.verboseParsingErrors ?? this.verboseParsingErrors;
74
74
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
75
75
  this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;
76
+ this.metadata = fields?.metadata ?? this.metadata;
76
77
  }
77
78
  /**
78
79
  * Invokes the tool with the provided input and configuration.
@@ -185,6 +186,7 @@ class StructuredTool extends base_js_1.BaseLangChain {
185
186
  artifact,
186
187
  toolCallId,
187
188
  name: this.name,
189
+ metadata: this.metadata,
188
190
  });
189
191
  await runManager?.handleToolEnd(formattedOutput);
190
192
  return formattedOutput;
@@ -360,7 +362,7 @@ function tool(func, fields) {
360
362
  return new DynamicTool({
361
363
  ...fields,
362
364
  description: fields.description ??
363
- fields.schema?.description ??
365
+ (fields.schema && (0, zod_js_1.getSchemaDescription)(fields.schema)) ??
364
366
  `${fields.name} tool`,
365
367
  func: async (input, runManager, config) => {
366
368
  return new Promise((resolve, reject) => {
@@ -407,24 +409,28 @@ function tool(func, fields) {
407
409
  });
408
410
  }
409
411
  function _formatToolOutput(params) {
410
- const { content, artifact, toolCallId } = params;
412
+ const { content, artifact, toolCallId, metadata } = params;
411
413
  if (toolCallId && !(0, tool_js_1.isDirectToolOutput)(content)) {
412
414
  if (typeof content === "string" ||
413
415
  (Array.isArray(content) &&
414
416
  content.every((item) => typeof item === "object"))) {
415
417
  return new tool_js_1.ToolMessage({
418
+ status: "success",
416
419
  content,
417
420
  artifact,
418
421
  tool_call_id: toolCallId,
419
422
  name: params.name,
423
+ metadata,
420
424
  });
421
425
  }
422
426
  else {
423
427
  return new tool_js_1.ToolMessage({
428
+ status: "success",
424
429
  content: _stringify(content),
425
430
  artifact,
426
431
  tool_call_id: toolCallId,
427
432
  name: params.name,
433
+ metadata,
428
434
  });
429
435
  }
430
436
  }
@@ -6,7 +6,7 @@ import { mergeConfigs, ensureConfig, patchConfig, pickRunnableConfigKeys, } from
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";
9
- import { interopParseAsync, isSimpleStringZodSchema, isInteropZodSchema, } from "../utils/types/zod.js";
9
+ import { interopParseAsync, isSimpleStringZodSchema, isInteropZodSchema, getSchemaDescription, } from "../utils/types/zod.js";
10
10
  import { validatesOnlyStrings } from "../utils/json_schema.js";
11
11
  export { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, } from "./types.js";
12
12
  export { ToolInputParsingException };
@@ -65,6 +65,7 @@ export class StructuredTool extends BaseLangChain {
65
65
  fields?.verboseParsingErrors ?? this.verboseParsingErrors;
66
66
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
67
67
  this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;
68
+ this.metadata = fields?.metadata ?? this.metadata;
68
69
  }
69
70
  /**
70
71
  * Invokes the tool with the provided input and configuration.
@@ -177,6 +178,7 @@ export class StructuredTool extends BaseLangChain {
177
178
  artifact,
178
179
  toolCallId,
179
180
  name: this.name,
181
+ metadata: this.metadata,
180
182
  });
181
183
  await runManager?.handleToolEnd(formattedOutput);
182
184
  return formattedOutput;
@@ -347,7 +349,7 @@ export function tool(func, fields) {
347
349
  return new DynamicTool({
348
350
  ...fields,
349
351
  description: fields.description ??
350
- fields.schema?.description ??
352
+ (fields.schema && getSchemaDescription(fields.schema)) ??
351
353
  `${fields.name} tool`,
352
354
  func: async (input, runManager, config) => {
353
355
  return new Promise((resolve, reject) => {
@@ -394,24 +396,28 @@ export function tool(func, fields) {
394
396
  });
395
397
  }
396
398
  function _formatToolOutput(params) {
397
- const { content, artifact, toolCallId } = params;
399
+ const { content, artifact, toolCallId, metadata } = params;
398
400
  if (toolCallId && !isDirectToolOutput(content)) {
399
401
  if (typeof content === "string" ||
400
402
  (Array.isArray(content) &&
401
403
  content.every((item) => typeof item === "object"))) {
402
404
  return new ToolMessage({
405
+ status: "success",
403
406
  content,
404
407
  artifact,
405
408
  tool_call_id: toolCallId,
406
409
  name: params.name,
410
+ metadata,
407
411
  });
408
412
  }
409
413
  else {
410
414
  return new ToolMessage({
415
+ status: "success",
411
416
  content: _stringify(content),
412
417
  artifact,
413
418
  tool_call_id: toolCallId,
414
419
  name: params.name,
420
+ metadata,
415
421
  });
416
422
  }
417
423
  }
@@ -58,6 +58,10 @@ export interface ToolParams extends BaseLangChainParams {
58
58
  * @default false
59
59
  */
60
60
  verboseParsingErrors?: boolean;
61
+ /**
62
+ * Metadata for the tool.
63
+ */
64
+ metadata?: Record<string, unknown>;
61
65
  }
62
66
  export type ToolRunnableConfig<ConfigurableFieldType extends Record<string, any> = Record<string, any>> = RunnableConfig<ConfigurableFieldType> & {
63
67
  toolCall?: ToolCall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.67",
3
+ "version": "0.3.69",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {