Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai): find lazy tools by search #2255

MergedAlemTuzlakmerged 14 commits intomain fromfeat/lazy-tools-searchmerged by tombeckenham View on GitHub

Showing 26 changed files with 27 additions and 4 deletions (loading 22).

x
0 of 26 viewed, 26 left
6 additions and 0 deletions.changeset/lazy-tools-search.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/ai': minor
+'@tanstack/ai-code-mode': minor
+---
+​
+Add `lazyToolsConfig.catalog: 'search'`. The discovery catalog then lists no lazy tool names, so hundreds of lazy tools cost almost no prompt tokens. The model finds tools with a `query` to `__lazy__tool__discovery__` (`chat()`) or `discover_tools` (Code Mode), and gets at most 10 keyword matches. Common words such as "a", "to", and "tool" do not score. Exact `toolNames` still work. A later `chat()` query that finds only tools already discovered says those tools are already available. `@tanstack/ai` also exports `searchLazyTools(tools, query, limit?)`, the ranking that both use.
1 addition and 1 deletiondocs/api/ai.mdModified
View file
@@ -85,7 +85,7 @@
| `toolExecution` | `"parallel"` (default) or `"sequential"`: how the server tools of one model turn run. |
| `repairToolInput` | How a tool input that fails the final check is repaired. `false` turns repair off. A function replaces it. |
| `retry` | Retries a rate-limited model call after the wait the provider asks for, for example `{ maxRetries: 3 }`. |
-| `lazyToolsConfig` | How much of each lazy tool description goes into the discovery catalog. See [Lazy Tool Discovery](../tools/lazy-tool-discovery). |
+| `lazyToolsConfig` | How much of each lazy tool description goes into the discovery catalog, or `catalog: 'search'` to list no tools and find them by query. See [Lazy Tool Discovery](../tools/lazy-tool-discovery). |
| `mcp` | MCP clients or pools. Their tools join the run. See [MCP](../tools/mcp). |
| `interrupts` | Definitions from `defineInterrupt()`. See [Generic Interrupts](../interrupts/generic). |
| `subagents` | Named child agents from `defineAgent()`. See [Subagents](../chat/subagents). |
20 additions and 3 deletionsdocs/code-mode/lazy-tools.mdModified
View file
@@ -15,7 +15,7 @@
​
Lazy Code Mode tools load a type stub only when the program imports that tool. The system prompt stays small when you register many tools.
​
-Mark the rarely used tools `lazy: true`. The prompt then lists only their names. When the model needs one, it calls `discover_tools` to get the signature, then uses the tool in `execute_typescript`.
+Mark the rarely used tools `lazy: true`. By default the prompt lists only their names. Set `lazyToolsConfig.catalog` to `'search'` to list no names. The model then finds a tool with a query. It calls `discover_tools` for the signature, then uses the tool in `execute_typescript`.
​
## Quick setup