diff --git a/.jules/bolt.md b/.jules/bolt.md index 134f394..7368904 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-05-28 - Agentic Loop Caching Optimization +**Learning:** In agentic tools that repeatedly query the same context (e.g., `SearchTool.deep`), making redundant operations or API calls causes significant bottlenecks. Caching within the `core.execute()` wrapper ensures standardized formatting, logging, and retry logic are maintained while eliminating the overhead. +**Action:** Use an in-memory `Map` cache for agentic tools that perform identical context queries during loops, placing cache logic inside the execution wrapper. diff --git a/src/tools/index.ts b/src/tools/index.ts index 6af329e..2d9a3a6 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -60,14 +60,22 @@ export class FileTool { } export class SearchTool { + // Cache repeated context queries to prevent redundant API calls during agentic loops + 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 () => { + if (this.cache.has(query)) { + this.core.log(`Cache hit for query: ${query}`); + return this.cache.get(query); + } + // Simulated results for the SDK base - return { + const result = { query, timestamp: new Date().toISOString(), findings: [ @@ -75,6 +83,9 @@ export class SearchTool { "Trending solutions in 2026" ] }; + + this.cache.set(query, result); + return result; }); } }