@agentforge/core 0.10.6 → 0.11.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/dist/index.cjs CHANGED
@@ -421,7 +421,7 @@ function getMissingDescriptions(schema) {
421
421
  }
422
422
 
423
423
  // src/tools/helpers.ts
424
- function createTool(metadata, schema, execute) {
424
+ function createTool(metadata, schema, invoke) {
425
425
  const metadataResult = validateToolMetadata(metadata);
426
426
  if (!metadataResult.success) {
427
427
  const errors = metadataResult.error.errors.map((err) => ` - ${err.path.join(".")}: ${err.message}`).join("\n");
@@ -432,12 +432,12 @@ ${errors}`);
432
432
  const tool = {
433
433
  metadata: metadataResult.data,
434
434
  schema,
435
- execute
435
+ invoke
436
436
  };
437
- tool.invoke = execute;
437
+ tool.execute = invoke;
438
438
  return tool;
439
439
  }
440
- function createToolUnsafe(metadata, schema, execute) {
440
+ function createToolUnsafe(metadata, schema, invoke) {
441
441
  const metadataResult = validateToolMetadata(metadata);
442
442
  if (!metadataResult.success) {
443
443
  const errors = metadataResult.error.errors.map((err) => ` - ${err.path.join(".")}: ${err.message}`).join("\n");
@@ -447,9 +447,9 @@ ${errors}`);
447
447
  const tool = {
448
448
  metadata: metadataResult.data,
449
449
  schema,
450
- execute
450
+ invoke
451
451
  };
452
- tool.invoke = execute;
452
+ tool.execute = invoke;
453
453
  return tool;
454
454
  }
455
455
  function validateTool(tool) {
@@ -477,7 +477,7 @@ function validateTool(tool) {
477
477
  var ToolBuilder = class {
478
478
  metadata = {};
479
479
  _schema;
480
- _execute;
480
+ _invoke;
481
481
  /**
482
482
  * Set the tool name (required)
483
483
  *
@@ -689,10 +689,10 @@ var ToolBuilder = class {
689
689
  /**
690
690
  * Set the implementation function (required)
691
691
  *
692
- * @param execute - Async function that implements the tool
692
+ * @param invoke - Async function that implements the tool
693
693
  */
694
- implement(execute) {
695
- this._execute = execute;
694
+ implement(invoke) {
695
+ this._invoke = invoke;
696
696
  return this;
697
697
  }
698
698
  /**
@@ -701,7 +701,7 @@ var ToolBuilder = class {
701
701
  * Wraps the implementation in a try-catch block and returns a standardized
702
702
  * result object with success/error information.
703
703
  *
704
- * @param execute - Async function that implements the tool
704
+ * @param invoke - Async function that implements the tool
705
705
  * @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
706
706
  *
707
707
  * @example
@@ -718,10 +718,10 @@ var ToolBuilder = class {
718
718
  * // Or on error: { success: false, error: "ENOENT: no such file..." }
719
719
  * ```
720
720
  */
721
- implementSafe(execute) {
722
- const safeExecute = async (input) => {
721
+ implementSafe(invoke) {
722
+ const safeInvoke = async (input) => {
723
723
  try {
724
- const data = await execute(input);
724
+ const data = await invoke(input);
725
725
  return { success: true, data };
726
726
  } catch (error) {
727
727
  return {
@@ -730,17 +730,17 @@ var ToolBuilder = class {
730
730
  };
731
731
  }
732
732
  };
733
- this._execute = safeExecute;
733
+ this._invoke = safeInvoke;
734
734
  return this;
735
735
  }
736
736
  /**
737
737
  * Build the tool with validation
738
- *
738
+ *
739
739
  * Validates:
740
740
  * - All required fields are present
741
741
  * - Metadata is valid
742
742
  * - Schema has descriptions on all fields
743
- *
743
+ *
744
744
  * @returns The validated tool
745
745
  * @throws {Error} If validation fails
746
746
  */
@@ -757,13 +757,13 @@ var ToolBuilder = class {
757
757
  if (!this._schema) {
758
758
  throw new Error("Tool schema is required. Use .schema() to set it.");
759
759
  }
760
- if (!this._execute) {
760
+ if (!this._invoke) {
761
761
  throw new Error("Tool implementation is required. Use .implement() to set it.");
762
762
  }
763
763
  return createTool(
764
764
  this.metadata,
765
765
  this._schema,
766
- this._execute
766
+ this._invoke
767
767
  );
768
768
  }
769
769
  };
@@ -780,7 +780,7 @@ function toLangChainTool(tool) {
780
780
  description: tool.metadata.description,
781
781
  schema: tool.schema,
782
782
  func: async (input) => {
783
- const result = await tool.execute(input);
783
+ const result = await tool.invoke(input);
784
784
  if (typeof result === "string") {
785
785
  return result;
786
786
  }
@@ -1509,13 +1509,17 @@ function createToolExecutor(config = {}) {
1509
1509
  return Math.min(delay, maxDelay);
1510
1510
  }
1511
1511
  async function executeWithRetry(tool, input, policy) {
1512
+ const executeFn = tool.invoke || tool.execute;
1513
+ if (!executeFn) {
1514
+ throw new Error("Tool must implement either invoke() or execute() method");
1515
+ }
1512
1516
  if (!policy) {
1513
- return await tool.invoke(input);
1517
+ return await executeFn.call(tool, input);
1514
1518
  }
1515
1519
  let lastError;
1516
1520
  for (let attempt = 1; attempt <= policy.maxAttempts; attempt++) {
1517
1521
  try {
1518
- return await tool.invoke(input);
1522
+ return await executeFn.call(tool, input);
1519
1523
  } catch (error) {
1520
1524
  lastError = error;
1521
1525
  if (policy.retryableErrors && policy.retryableErrors.length > 0) {
package/dist/index.d.cts CHANGED
@@ -309,7 +309,7 @@ interface Tool<TInput = unknown, TOutput = unknown> {
309
309
  */
310
310
  schema: z.ZodSchema<TInput>;
311
311
  /**
312
- * Tool implementation
312
+ * Tool implementation (primary method)
313
313
  *
314
314
  * Why async?
315
315
  * - Most tools do I/O (files, network, database)
@@ -317,22 +317,33 @@ interface Tool<TInput = unknown, TOutput = unknown> {
317
317
  *
318
318
  * The input is automatically validated against the schema
319
319
  * before this function is called.
320
+ *
321
+ * This is the industry standard method name used by LangChain.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const result = await tool.invoke({ input: 'hello' });
326
+ * ```
320
327
  */
321
- execute: (input: TInput) => Promise<TOutput>;
328
+ invoke: (input: TInput) => Promise<TOutput>;
322
329
  /**
323
- * LangChain-compatible alias for execute
330
+ * Deprecated alias for invoke()
331
+ *
332
+ * @deprecated Use invoke() instead. This method will be removed in v1.0.0.
324
333
  *
325
- * This allows developers familiar with LangChain to use .invoke()
326
- * instead of .execute(). Both methods do exactly the same thing.
334
+ * Both methods do exactly the same thing, but invoke() is the industry
335
+ * standard used by LangChain and should be preferred.
327
336
  *
328
337
  * @example
329
338
  * ```ts
330
- * // Both of these work:
339
+ * // Deprecated (still works, but will be removed in v1.0.0):
331
340
  * const result1 = await tool.execute({ input: 'hello' });
341
+ *
342
+ * // ✅ Preferred (industry standard):
332
343
  * const result2 = await tool.invoke({ input: 'hello' });
333
344
  * ```
334
345
  */
335
- invoke?: (input: TInput) => Promise<TOutput>;
346
+ execute?: (input: TInput) => Promise<TOutput>;
336
347
  }
337
348
 
338
349
  /**
@@ -832,7 +843,7 @@ declare function getMissingDescriptions(schema: z.ZodTypeAny): string[];
832
843
  *
833
844
  * @param metadata - Tool metadata
834
845
  * @param schema - Zod schema for input validation (must have descriptions!)
835
- * @param execute - Tool implementation
846
+ * @param invoke - Tool implementation (primary method, industry standard)
836
847
  * @returns Validated tool
837
848
  * @throws {Error} If metadata is invalid or schema is missing descriptions
838
849
  *
@@ -863,7 +874,7 @@ declare function getMissingDescriptions(schema: z.ZodTypeAny): string[];
863
874
  * );
864
875
  * ```
865
876
  */
866
- declare function createTool<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, execute: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
877
+ declare function createTool<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, invoke: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
867
878
  /**
868
879
  * Create a tool without enforcing schema descriptions
869
880
  *
@@ -877,10 +888,10 @@ declare function createTool<TInput = unknown, TOutput = unknown>(metadata: ToolM
877
888
  *
878
889
  * @param metadata - Tool metadata
879
890
  * @param schema - Zod schema for input validation
880
- * @param execute - Tool implementation
891
+ * @param invoke - Tool implementation (primary method, industry standard)
881
892
  * @returns Tool (without schema validation)
882
893
  */
883
- declare function createToolUnsafe<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, execute: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
894
+ declare function createToolUnsafe<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, invoke: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
884
895
  /**
885
896
  * Validate an existing tool
886
897
  *
@@ -933,7 +944,7 @@ declare function validateTool(tool: Tool): {
933
944
  declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
934
945
  private metadata;
935
946
  private _schema?;
936
- private _execute?;
947
+ private _invoke?;
937
948
  /**
938
949
  * Set the tool name (required)
939
950
  *
@@ -1067,16 +1078,16 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
1067
1078
  /**
1068
1079
  * Set the implementation function (required)
1069
1080
  *
1070
- * @param execute - Async function that implements the tool
1081
+ * @param invoke - Async function that implements the tool
1071
1082
  */
1072
- implement<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, T>;
1083
+ implement<T>(invoke: (input: TInput) => Promise<T>): ToolBuilder<TInput, T>;
1073
1084
  /**
1074
1085
  * Set the implementation function with automatic error handling
1075
1086
  *
1076
1087
  * Wraps the implementation in a try-catch block and returns a standardized
1077
1088
  * result object with success/error information.
1078
1089
  *
1079
- * @param execute - Async function that implements the tool
1090
+ * @param invoke - Async function that implements the tool
1080
1091
  * @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
1081
1092
  *
1082
1093
  * @example
@@ -1093,7 +1104,7 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
1093
1104
  * // Or on error: { success: false, error: "ENOENT: no such file..." }
1094
1105
  * ```
1095
1106
  */
1096
- implementSafe<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, {
1107
+ implementSafe<T>(invoke: (input: TInput) => Promise<T>): ToolBuilder<TInput, {
1097
1108
  success: boolean;
1098
1109
  data?: T;
1099
1110
  error?: string;
package/dist/index.d.ts CHANGED
@@ -309,7 +309,7 @@ interface Tool<TInput = unknown, TOutput = unknown> {
309
309
  */
310
310
  schema: z.ZodSchema<TInput>;
311
311
  /**
312
- * Tool implementation
312
+ * Tool implementation (primary method)
313
313
  *
314
314
  * Why async?
315
315
  * - Most tools do I/O (files, network, database)
@@ -317,22 +317,33 @@ interface Tool<TInput = unknown, TOutput = unknown> {
317
317
  *
318
318
  * The input is automatically validated against the schema
319
319
  * before this function is called.
320
+ *
321
+ * This is the industry standard method name used by LangChain.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const result = await tool.invoke({ input: 'hello' });
326
+ * ```
320
327
  */
321
- execute: (input: TInput) => Promise<TOutput>;
328
+ invoke: (input: TInput) => Promise<TOutput>;
322
329
  /**
323
- * LangChain-compatible alias for execute
330
+ * Deprecated alias for invoke()
331
+ *
332
+ * @deprecated Use invoke() instead. This method will be removed in v1.0.0.
324
333
  *
325
- * This allows developers familiar with LangChain to use .invoke()
326
- * instead of .execute(). Both methods do exactly the same thing.
334
+ * Both methods do exactly the same thing, but invoke() is the industry
335
+ * standard used by LangChain and should be preferred.
327
336
  *
328
337
  * @example
329
338
  * ```ts
330
- * // Both of these work:
339
+ * // Deprecated (still works, but will be removed in v1.0.0):
331
340
  * const result1 = await tool.execute({ input: 'hello' });
341
+ *
342
+ * // ✅ Preferred (industry standard):
332
343
  * const result2 = await tool.invoke({ input: 'hello' });
333
344
  * ```
334
345
  */
335
- invoke?: (input: TInput) => Promise<TOutput>;
346
+ execute?: (input: TInput) => Promise<TOutput>;
336
347
  }
337
348
 
338
349
  /**
@@ -832,7 +843,7 @@ declare function getMissingDescriptions(schema: z.ZodTypeAny): string[];
832
843
  *
833
844
  * @param metadata - Tool metadata
834
845
  * @param schema - Zod schema for input validation (must have descriptions!)
835
- * @param execute - Tool implementation
846
+ * @param invoke - Tool implementation (primary method, industry standard)
836
847
  * @returns Validated tool
837
848
  * @throws {Error} If metadata is invalid or schema is missing descriptions
838
849
  *
@@ -863,7 +874,7 @@ declare function getMissingDescriptions(schema: z.ZodTypeAny): string[];
863
874
  * );
864
875
  * ```
865
876
  */
866
- declare function createTool<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, execute: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
877
+ declare function createTool<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, invoke: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
867
878
  /**
868
879
  * Create a tool without enforcing schema descriptions
869
880
  *
@@ -877,10 +888,10 @@ declare function createTool<TInput = unknown, TOutput = unknown>(metadata: ToolM
877
888
  *
878
889
  * @param metadata - Tool metadata
879
890
  * @param schema - Zod schema for input validation
880
- * @param execute - Tool implementation
891
+ * @param invoke - Tool implementation (primary method, industry standard)
881
892
  * @returns Tool (without schema validation)
882
893
  */
883
- declare function createToolUnsafe<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, execute: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
894
+ declare function createToolUnsafe<TInput = unknown, TOutput = unknown>(metadata: ToolMetadata, schema: z.ZodSchema<TInput>, invoke: (input: TInput) => Promise<TOutput>): Tool<TInput, TOutput>;
884
895
  /**
885
896
  * Validate an existing tool
886
897
  *
@@ -933,7 +944,7 @@ declare function validateTool(tool: Tool): {
933
944
  declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
934
945
  private metadata;
935
946
  private _schema?;
936
- private _execute?;
947
+ private _invoke?;
937
948
  /**
938
949
  * Set the tool name (required)
939
950
  *
@@ -1067,16 +1078,16 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
1067
1078
  /**
1068
1079
  * Set the implementation function (required)
1069
1080
  *
1070
- * @param execute - Async function that implements the tool
1081
+ * @param invoke - Async function that implements the tool
1071
1082
  */
1072
- implement<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, T>;
1083
+ implement<T>(invoke: (input: TInput) => Promise<T>): ToolBuilder<TInput, T>;
1073
1084
  /**
1074
1085
  * Set the implementation function with automatic error handling
1075
1086
  *
1076
1087
  * Wraps the implementation in a try-catch block and returns a standardized
1077
1088
  * result object with success/error information.
1078
1089
  *
1079
- * @param execute - Async function that implements the tool
1090
+ * @param invoke - Async function that implements the tool
1080
1091
  * @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
1081
1092
  *
1082
1093
  * @example
@@ -1093,7 +1104,7 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
1093
1104
  * // Or on error: { success: false, error: "ENOENT: no such file..." }
1094
1105
  * ```
1095
1106
  */
1096
- implementSafe<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, {
1107
+ implementSafe<T>(invoke: (input: TInput) => Promise<T>): ToolBuilder<TInput, {
1097
1108
  success: boolean;
1098
1109
  data?: T;
1099
1110
  error?: string;
package/dist/index.js CHANGED
@@ -265,7 +265,7 @@ function getMissingDescriptions(schema) {
265
265
  }
266
266
 
267
267
  // src/tools/helpers.ts
268
- function createTool(metadata, schema, execute) {
268
+ function createTool(metadata, schema, invoke) {
269
269
  const metadataResult = validateToolMetadata(metadata);
270
270
  if (!metadataResult.success) {
271
271
  const errors = metadataResult.error.errors.map((err) => ` - ${err.path.join(".")}: ${err.message}`).join("\n");
@@ -276,12 +276,12 @@ ${errors}`);
276
276
  const tool = {
277
277
  metadata: metadataResult.data,
278
278
  schema,
279
- execute
279
+ invoke
280
280
  };
281
- tool.invoke = execute;
281
+ tool.execute = invoke;
282
282
  return tool;
283
283
  }
284
- function createToolUnsafe(metadata, schema, execute) {
284
+ function createToolUnsafe(metadata, schema, invoke) {
285
285
  const metadataResult = validateToolMetadata(metadata);
286
286
  if (!metadataResult.success) {
287
287
  const errors = metadataResult.error.errors.map((err) => ` - ${err.path.join(".")}: ${err.message}`).join("\n");
@@ -291,9 +291,9 @@ ${errors}`);
291
291
  const tool = {
292
292
  metadata: metadataResult.data,
293
293
  schema,
294
- execute
294
+ invoke
295
295
  };
296
- tool.invoke = execute;
296
+ tool.execute = invoke;
297
297
  return tool;
298
298
  }
299
299
  function validateTool(tool) {
@@ -321,7 +321,7 @@ function validateTool(tool) {
321
321
  var ToolBuilder = class {
322
322
  metadata = {};
323
323
  _schema;
324
- _execute;
324
+ _invoke;
325
325
  /**
326
326
  * Set the tool name (required)
327
327
  *
@@ -533,10 +533,10 @@ var ToolBuilder = class {
533
533
  /**
534
534
  * Set the implementation function (required)
535
535
  *
536
- * @param execute - Async function that implements the tool
536
+ * @param invoke - Async function that implements the tool
537
537
  */
538
- implement(execute) {
539
- this._execute = execute;
538
+ implement(invoke) {
539
+ this._invoke = invoke;
540
540
  return this;
541
541
  }
542
542
  /**
@@ -545,7 +545,7 @@ var ToolBuilder = class {
545
545
  * Wraps the implementation in a try-catch block and returns a standardized
546
546
  * result object with success/error information.
547
547
  *
548
- * @param execute - Async function that implements the tool
548
+ * @param invoke - Async function that implements the tool
549
549
  * @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
550
550
  *
551
551
  * @example
@@ -562,10 +562,10 @@ var ToolBuilder = class {
562
562
  * // Or on error: { success: false, error: "ENOENT: no such file..." }
563
563
  * ```
564
564
  */
565
- implementSafe(execute) {
566
- const safeExecute = async (input) => {
565
+ implementSafe(invoke) {
566
+ const safeInvoke = async (input) => {
567
567
  try {
568
- const data = await execute(input);
568
+ const data = await invoke(input);
569
569
  return { success: true, data };
570
570
  } catch (error) {
571
571
  return {
@@ -574,17 +574,17 @@ var ToolBuilder = class {
574
574
  };
575
575
  }
576
576
  };
577
- this._execute = safeExecute;
577
+ this._invoke = safeInvoke;
578
578
  return this;
579
579
  }
580
580
  /**
581
581
  * Build the tool with validation
582
- *
582
+ *
583
583
  * Validates:
584
584
  * - All required fields are present
585
585
  * - Metadata is valid
586
586
  * - Schema has descriptions on all fields
587
- *
587
+ *
588
588
  * @returns The validated tool
589
589
  * @throws {Error} If validation fails
590
590
  */
@@ -601,13 +601,13 @@ var ToolBuilder = class {
601
601
  if (!this._schema) {
602
602
  throw new Error("Tool schema is required. Use .schema() to set it.");
603
603
  }
604
- if (!this._execute) {
604
+ if (!this._invoke) {
605
605
  throw new Error("Tool implementation is required. Use .implement() to set it.");
606
606
  }
607
607
  return createTool(
608
608
  this.metadata,
609
609
  this._schema,
610
- this._execute
610
+ this._invoke
611
611
  );
612
612
  }
613
613
  };
@@ -624,7 +624,7 @@ function toLangChainTool(tool) {
624
624
  description: tool.metadata.description,
625
625
  schema: tool.schema,
626
626
  func: async (input) => {
627
- const result = await tool.execute(input);
627
+ const result = await tool.invoke(input);
628
628
  if (typeof result === "string") {
629
629
  return result;
630
630
  }
@@ -1353,13 +1353,17 @@ function createToolExecutor(config = {}) {
1353
1353
  return Math.min(delay, maxDelay);
1354
1354
  }
1355
1355
  async function executeWithRetry(tool, input, policy) {
1356
+ const executeFn = tool.invoke || tool.execute;
1357
+ if (!executeFn) {
1358
+ throw new Error("Tool must implement either invoke() or execute() method");
1359
+ }
1356
1360
  if (!policy) {
1357
- return await tool.invoke(input);
1361
+ return await executeFn.call(tool, input);
1358
1362
  }
1359
1363
  let lastError;
1360
1364
  for (let attempt = 1; attempt <= policy.maxAttempts; attempt++) {
1361
1365
  try {
1362
- return await tool.invoke(input);
1366
+ return await executeFn.call(tool, input);
1363
1367
  } catch (error) {
1364
1368
  lastError = error;
1365
1369
  if (policy.retryableErrors && policy.retryableErrors.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/core",
3
- "version": "0.10.6",
3
+ "version": "0.11.0",
4
4
  "description": "Core abstractions for AgentForge - production-ready deep agents framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",