@tanstack/ai
Version:
Core TanStack AI library - Open source AI SDK
58 lines (57 loc) • 1.99 kB
TypeScript
import { Tool } from '../../../types.js';
/**
* Manages lazy tool discovery for the chat agent loop.
*
* Lazy tools are not sent to the LLM initially. Instead, a synthetic
* "discovery tool" is provided that lets the LLM discover lazy tools
* by name, receiving their full descriptions and schemas on demand.
*/
export declare class LazyToolManager {
private readonly eagerTools;
private readonly lazyToolMap;
private readonly discoveredTools;
private hasNewDiscoveries;
private readonly discoveryTool;
constructor(tools: ReadonlyArray<Tool>, messages: ReadonlyArray<{
role: string;
content?: any;
toolCalls?: Array<{
id: string;
type: string;
function: {
name: string;
arguments: string;
};
}>;
toolCallId?: string;
}>);
/**
* Returns the set of tools that should be sent to the LLM:
* eager tools + discovered lazy tools + discovery tool (if undiscovered tools remain).
* Resets the hasNewDiscoveries flag.
*/
getActiveTools(): Array<Tool>;
/**
* Returns whether new tools have been discovered since the last getActiveTools() call.
*/
hasNewlyDiscoveredTools(): boolean;
/**
* Returns true if the given name is a lazy tool that has not yet been discovered.
*/
isUndiscoveredLazyTool(name: string): boolean;
/**
* Returns a helpful error message for when an undiscovered lazy tool is called.
*/
getUndiscoveredToolError(name: string): string;
/**
* Scans message history to find previously discovered lazy tools.
* Looks for assistant messages with discovery tool calls and their
* corresponding tool result messages.
*/
private scanMessageHistory;
/**
* Creates the synthetic discovery tool that the LLM can call
* to discover lazy tools' descriptions and schemas.
*/
private createDiscoveryTool;
}