From 35fe18b1633a2aca4697b1cab8fb8ba366f96d81 Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Sun, 8 Mar 2026 15:02:50 +0530 Subject: [PATCH 1/2] feat: Use LRUCache instead of Map in MemoryCache --- packages/tools/src/shared/cache.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/tools/src/shared/cache.ts b/packages/tools/src/shared/cache.ts index 9125b24ca..15ce16fe4 100644 --- a/packages/tools/src/shared/cache.ts +++ b/packages/tools/src/shared/cache.ts @@ -1,3 +1,4 @@ +import { LRUCache } from "lru-cache" import type { MemoryMode } from "./types" /** @@ -5,7 +6,7 @@ import type { MemoryMode } from "./types" * Used to cache memory retrieval results during tool-call loops within the same turn. */ export class MemoryCache { - private cache: Map = new Map() + private cache: LRUCache = new LRUCache({ max: 100 }) /** * Generates a cache key for the current turn based on context parameters. From 035f78de0ceb9ea236c7ea9d976af6d936aa997a Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Sun, 8 Mar 2026 15:10:13 +0530 Subject: [PATCH 2/2] add dependency in package.json --- packages/tools/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tools/package.json b/packages/tools/package.json index 39cde98d8..5195c058c 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -14,6 +14,7 @@ "@ai-sdk/anthropic": "^2.0.25", "@ai-sdk/openai": "^2.0.23", "ai": "^5.0.29", + "lru-cache": "^11.2.6", "openai": "^4.104.0", "supermemory": "^3.0.0-alpha.26", "zod": "^4.1.5"