UNPKG

jorel

Version:

The easiest way to use LLMs, including streams, images, documents, tools and various agent scenarios.

124 lines (123 loc) 4.18 kB
import { LlmTool, LlmToolConfiguration, LLmToolContextSegment } from "./llm-tool"; import { MaybeUndefined, Nullable } from "../shared"; import { LlmFunction, LlmToolCall } from "../providers"; interface LlmToolKitConfiguration { allowParallelCalls?: boolean; } /** * A toolkit for managing one or more LLM tools. */ export declare class LlmToolKit { readonly tools: LlmTool[]; allowParallelCalls: boolean; constructor(tools: (LlmTool | LlmToolConfiguration)[], config?: LlmToolKitConfiguration); /** * Whether the toolkit has any tools */ get hasTools(): boolean; /** * Get all tools as LlmFunction objects */ get asLlmFunctions(): MaybeUndefined<LlmFunction[]>; /** * Deserialize strings * @param input */ static deserialize(input: string): object; /** * Serialize objects * @param input */ static serialize(input: object): string; /** * Create a new toolkit with only selected (allowed) tools * @param allowedToolIds */ withAllowedToolsOnly(allowedToolIds: string[]): LlmToolKit; /** * Get the next tool call that requires processing * @param input */ getNextToolCall(input: LlmToolCall[]): Nullable<{ toolCall: LlmToolCall; tool: LlmTool; }>; /** * Register one or more tools * @param tools */ registerTools(tools: (LlmTool | LlmToolConfiguration)[]): void; /** * Register a new tool * @param tool Tool or tool configuration */ registerTool(tool: LlmTool | LlmToolConfiguration): void; /** * Unregister a tool * @param id Tool name */ unregisterTool(id: string): void; /** * Get a tool by name * @param id Tool name */ getTool(id: string): Nullable<LlmTool>; /** * Reject one or more tool calls * @param input Object containing tool calls (e.g. llm "assistant_with_tools" message) * @param idOrIds ID or array of IDs of tool calls to reject. If not provided, all tool calls will be rejected. */ rejectCalls<T extends { toolCalls: LlmToolCall[]; }>(input: T, idOrIds?: string | string[]): T; /** * Approve one or more tool calls * @param input Object containing tool calls (e.g. llm "assistant_with_tools" message) * @param idOrIds ID or array of IDs of tool calls to approve. If not provided, all tool calls will be approved. */ approveCalls<T extends { toolCalls: LlmToolCall[]; }>(input: T, idOrIds?: string | string[]): T; /** * Classify what type of tool calls are present * @param toolCalls */ classifyToolCalls(toolCalls: LlmToolCall[]): "approvalPending" | "transferPending" | "executionPending" | "completed" | "missingExecutor"; /** * Process a single tool call and return the updated tool call * @param toolCall * @param config * @returns Object containing the updated tool call and a boolean indicating whether the tool call was handled * If the tool call was not handled, it requires additional processing (e.g. approval or delegation) */ processToolCall(toolCall: LlmToolCall, config?: { retryFailed?: boolean; context?: LLmToolContextSegment; secureContext?: LLmToolContextSegment; }): Promise<{ toolCall: LlmToolCall; handled: boolean; }>; /** * Process tool calls * * This method will execute the tools and return the results. * All tool calls must be approved or rejected before processing. * * @param input Object containing tool calls (e.g. llm "assistant_with_tools" message) * @param config * @returns Object containing tool calls with results * @throws Error if a tool is not found or if any tool calls still require approval */ processCalls<T extends { toolCalls?: LlmToolCall[]; }>(input: T, config?: { retryFailed?: boolean; context?: LLmToolContextSegment; secureContext?: LLmToolContextSegment; maxErrors?: number; maxCalls?: number; }): Promise<T>; private setCallToError; } export {};