Skip to content

Commit 259c6f6

Browse files
committed
Support refreshCache option for getAgentTools
* refreshCache forces a full refresh when getting agent tools * #agentTools() now fetches ALL servers * getAgentTools() now filters cached results * attempted to clean up the getAgentTools options with discriminated unions etc. * added tests for agent tools caching * updated existing test that needed a tweak to use mock API fetch framework
1 parent 0baa466 commit 259c6f6

File tree

6 files changed

+601
-112
lines changed

6 files changed

+601
-112
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ if (await client.isServerHealthy("time")) {
461461

462462
Generate (cached) callable functions that work directly with AI agent frameworks. No conversion layers needed.
463463

464-
> [!IMPORTANT]
465-
> If you want to get agent tools mutiple times using different filter options, you need to call `client.clearAgentToolsCache()` to force regeneration.
464+
> [!IMPORTANT]
465+
> Generated functions are cached for performance. Once cached, subsequent calls return cached functions regardless of filter parameters.
466+
> To force regeneration, either call `client.clearAgentToolsCache()` first, or use the `refreshCache: true` option.
466467
467468
##### Supports filtering by servers and by tools
468469

@@ -474,8 +475,8 @@ This prevents overwhelming the model's context window and improves response qual
474475
##### Examples
475476

476477
```typescript
477-
// Options: { servers?: string[], tools?: string[], format?: 'array' | 'object' | 'map' }
478-
// Default format is 'array' (for LangChain)
478+
// Options: { servers?: string[], tools?: string[], format?: 'array' | 'object' | 'map', refreshCache?: boolean }
479+
// Default format is 'array' (for LangChain), refreshCache defaults to false
479480
```
480481

481482
LangChain
@@ -553,18 +554,15 @@ const toolsObject = await client.getAgentTools({
553554
format: "object",
554555
});
555556

556-
// Clear cached generated functions before recreating
557-
client.clearAgentToolsCache();
558-
559557
// Use with Map for efficient lookups
560558
const toolMap = await client.getAgentTools({ format: "map" });
561559
const timeTool = toolMap.get("time__get_current_time");
562560
if (timeTool) {
563561
const result = await timeTool({ timezone: "UTC" });
564562
}
565563

566-
// Clear cached generated functions before recreating
567-
client.clearAgentToolsCache();
564+
// Force refresh from cache to get latest schemas
565+
const freshTools = await client.getAgentTools({ refreshCache: true });
568566

569567
// Each function has metadata for both frameworks
570568
const tools = await client.getAgentTools();

0 commit comments

Comments
 (0)