From 496d9ada469d4acf049622dde673af4dd033020e Mon Sep 17 00:00:00 2001 From: thirdbase1 <196722958+thirdbase1@users.noreply.github.com> Date: Wed, 3 Jun 2026 22:07:36 +0000 Subject: [PATCH] feat(tools): cache deep search queries in SearchTool - Implemented an in-memory Map to cache queries in `SearchTool.deep`. - This avoids redundant simulated or external API calls for repeated identical queries during agentic loops, which was a known architectural bottleneck. - Recorded a critical learning in `.jules/bolt.md`. --- .jules/bolt.md | 4 ++++ src/tools/index.ts | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 134f394..e49449a 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,7 @@ ## 2026-04-25 - LLM API Connection Pooling **Learning:** Making repeated API calls to external LLM providers (e.g. OpenRouter, OpenAI) without HTTP Keep-Alive results in 100-200ms of unnecessary TCP/TLS handshake overhead per request. In an agentic loop, this accumulates significantly. **Action:** When initializing HTTP clients (like Axios) for repeated internal/external services, configure them with an `https.Agent` setting `keepAlive: true` to pool connections. + +## 2026-06-03 - Agentic Loop API Redundancy +**Learning:** Agentic loops repeatedly calling the same context via external search or APIs create significant performance bottlenecks due to redundant network queries and delayed processing. +**Action:** Implement in-memory caching (e.g., using a Map) for repetitive read-only tools like `SearchTool.deep`. Cache hits should be evaluated inside the core execution wrappers to maintain standard formatting, retry logic, and standardized logging without duplicating code. diff --git a/src/tools/index.ts b/src/tools/index.ts index 6af329e..fee3803 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -60,14 +60,22 @@ export class FileTool { } export class SearchTool { + // ⚡ Bolt: Cache deep search queries to prevent redundant API calls + private cache = new Map(); + constructor(private core: CoreEngine) {} async deep(query: string): Promise> { this.core.log(`Initiating deep search for: ${query}`); // This is where real API calls to Google/X/Reddit would go return this.core.execute(async () => { + // ⚡ Bolt: Check cache inside execution wrapper to maintain execution result formatting and retry logic + if (this.cache.has(query)) { + return this.cache.get(query); + } + // Simulated results for the SDK base - return { + const result = { query, timestamp: new Date().toISOString(), findings: [ @@ -75,6 +83,10 @@ export class SearchTool { "Trending solutions in 2026" ] }; + + // ⚡ Bolt: Store result in cache + this.cache.set(query, result); + return result; }); } }