@agentforge/patterns 0.11.4 → 0.11.6
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 +19 -1
- package/dist/index.d.cts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +19 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -279,8 +279,26 @@ var import_core3 = require("@agentforge/core");
|
|
|
279
279
|
|
|
280
280
|
// src/shared/deduplication.ts
|
|
281
281
|
var import_core2 = require("@agentforge/core");
|
|
282
|
+
function normalizeObject(obj) {
|
|
283
|
+
if (obj === null || obj === void 0) {
|
|
284
|
+
return obj;
|
|
285
|
+
}
|
|
286
|
+
if (Array.isArray(obj)) {
|
|
287
|
+
return obj.map(normalizeObject);
|
|
288
|
+
}
|
|
289
|
+
if (typeof obj === "object" && obj.constructor === Object) {
|
|
290
|
+
const normalized = {};
|
|
291
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
292
|
+
for (const key of sortedKeys) {
|
|
293
|
+
normalized[key] = normalizeObject(obj[key]);
|
|
294
|
+
}
|
|
295
|
+
return normalized;
|
|
296
|
+
}
|
|
297
|
+
return obj;
|
|
298
|
+
}
|
|
282
299
|
function generateToolCallCacheKey(toolName, args) {
|
|
283
|
-
const
|
|
300
|
+
const normalizedArgs = normalizeObject(args);
|
|
301
|
+
const sortedArgs = JSON.stringify(normalizedArgs);
|
|
284
302
|
return `${toolName}:${sortedArgs}`;
|
|
285
303
|
}
|
|
286
304
|
function createPatternLogger(name, defaultLevel = "info") {
|
package/dist/index.d.cts
CHANGED
|
@@ -3043,22 +3043,30 @@ declare function registerWorkers(system: MultiAgentSystemWithRegistry, workers:
|
|
|
3043
3043
|
* Generate a cache key for a tool call based on tool name and arguments
|
|
3044
3044
|
*
|
|
3045
3045
|
* The cache key is generated by:
|
|
3046
|
-
* 1.
|
|
3047
|
-
* 2. JSON stringifying the
|
|
3046
|
+
* 1. Recursively sorting all object keys (including nested objects) alphabetically
|
|
3047
|
+
* 2. JSON stringifying the normalized arguments
|
|
3048
3048
|
* 3. Combining tool name and stringified arguments with a colon separator
|
|
3049
3049
|
*
|
|
3050
3050
|
* This ensures that tool calls with the same arguments in different order
|
|
3051
|
-
* produce the same cache key.
|
|
3051
|
+
* produce the same cache key, even for deeply nested objects.
|
|
3052
3052
|
*
|
|
3053
3053
|
* @param toolName - Name of the tool
|
|
3054
|
-
* @param args - Tool arguments (will be
|
|
3055
|
-
* @returns Cache key string in format "toolName:
|
|
3054
|
+
* @param args - Tool arguments (will be normalized for consistent hashing)
|
|
3055
|
+
* @returns Cache key string in format "toolName:normalizedArgs"
|
|
3056
3056
|
*
|
|
3057
3057
|
* @example
|
|
3058
3058
|
* ```typescript
|
|
3059
3059
|
* const key1 = generateToolCallCacheKey('search', { query: 'test', limit: 10 });
|
|
3060
3060
|
* const key2 = generateToolCallCacheKey('search', { limit: 10, query: 'test' });
|
|
3061
3061
|
* // key1 === key2 (argument order doesn't matter)
|
|
3062
|
+
*
|
|
3063
|
+
* const key3 = generateToolCallCacheKey('search', {
|
|
3064
|
+
* filters: { type: 'article', status: 'published' }
|
|
3065
|
+
* });
|
|
3066
|
+
* const key4 = generateToolCallCacheKey('search', {
|
|
3067
|
+
* filters: { status: 'published', type: 'article' }
|
|
3068
|
+
* });
|
|
3069
|
+
* // key3 === key4 (nested object order doesn't matter)
|
|
3062
3070
|
* ```
|
|
3063
3071
|
*/
|
|
3064
3072
|
declare function generateToolCallCacheKey(toolName: string, args: any): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3043,22 +3043,30 @@ declare function registerWorkers(system: MultiAgentSystemWithRegistry, workers:
|
|
|
3043
3043
|
* Generate a cache key for a tool call based on tool name and arguments
|
|
3044
3044
|
*
|
|
3045
3045
|
* The cache key is generated by:
|
|
3046
|
-
* 1.
|
|
3047
|
-
* 2. JSON stringifying the
|
|
3046
|
+
* 1. Recursively sorting all object keys (including nested objects) alphabetically
|
|
3047
|
+
* 2. JSON stringifying the normalized arguments
|
|
3048
3048
|
* 3. Combining tool name and stringified arguments with a colon separator
|
|
3049
3049
|
*
|
|
3050
3050
|
* This ensures that tool calls with the same arguments in different order
|
|
3051
|
-
* produce the same cache key.
|
|
3051
|
+
* produce the same cache key, even for deeply nested objects.
|
|
3052
3052
|
*
|
|
3053
3053
|
* @param toolName - Name of the tool
|
|
3054
|
-
* @param args - Tool arguments (will be
|
|
3055
|
-
* @returns Cache key string in format "toolName:
|
|
3054
|
+
* @param args - Tool arguments (will be normalized for consistent hashing)
|
|
3055
|
+
* @returns Cache key string in format "toolName:normalizedArgs"
|
|
3056
3056
|
*
|
|
3057
3057
|
* @example
|
|
3058
3058
|
* ```typescript
|
|
3059
3059
|
* const key1 = generateToolCallCacheKey('search', { query: 'test', limit: 10 });
|
|
3060
3060
|
* const key2 = generateToolCallCacheKey('search', { limit: 10, query: 'test' });
|
|
3061
3061
|
* // key1 === key2 (argument order doesn't matter)
|
|
3062
|
+
*
|
|
3063
|
+
* const key3 = generateToolCallCacheKey('search', {
|
|
3064
|
+
* filters: { type: 'article', status: 'published' }
|
|
3065
|
+
* });
|
|
3066
|
+
* const key4 = generateToolCallCacheKey('search', {
|
|
3067
|
+
* filters: { status: 'published', type: 'article' }
|
|
3068
|
+
* });
|
|
3069
|
+
* // key3 === key4 (nested object order doesn't matter)
|
|
3062
3070
|
* ```
|
|
3063
3071
|
*/
|
|
3064
3072
|
declare function generateToolCallCacheKey(toolName: string, args: any): string;
|
package/dist/index.js
CHANGED
|
@@ -176,8 +176,26 @@ import { toLangChainTools } from "@agentforge/core";
|
|
|
176
176
|
|
|
177
177
|
// src/shared/deduplication.ts
|
|
178
178
|
import { createLogger } from "@agentforge/core";
|
|
179
|
+
function normalizeObject(obj) {
|
|
180
|
+
if (obj === null || obj === void 0) {
|
|
181
|
+
return obj;
|
|
182
|
+
}
|
|
183
|
+
if (Array.isArray(obj)) {
|
|
184
|
+
return obj.map(normalizeObject);
|
|
185
|
+
}
|
|
186
|
+
if (typeof obj === "object" && obj.constructor === Object) {
|
|
187
|
+
const normalized = {};
|
|
188
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
189
|
+
for (const key of sortedKeys) {
|
|
190
|
+
normalized[key] = normalizeObject(obj[key]);
|
|
191
|
+
}
|
|
192
|
+
return normalized;
|
|
193
|
+
}
|
|
194
|
+
return obj;
|
|
195
|
+
}
|
|
179
196
|
function generateToolCallCacheKey(toolName, args) {
|
|
180
|
-
const
|
|
197
|
+
const normalizedArgs = normalizeObject(args);
|
|
198
|
+
const sortedArgs = JSON.stringify(normalizedArgs);
|
|
181
199
|
return `${toolName}:${sortedArgs}`;
|
|
182
200
|
}
|
|
183
201
|
function createPatternLogger(name, defaultLevel = "info") {
|