@voltagent/core 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2111,8 +2111,8 @@ interface ReasoningToolExecuteOptions extends ToolExecuteOptions {
2111
2111
  historyEntryId: string;
2112
2112
  }
2113
2113
 
2114
- declare const DEFAULT_INSTRUCTIONS = "\nYou have access to the 'think' and 'analyze' tools to work through problems step-by-step and structure your thought process. You should ALWAYS 'think' before making tool calls or generating a response.\n\n1. **Think** (scratchpad):\n * Purpose: Use the 'think' tool as a scratchpad to break down complex problems, outline steps, and decide on immediate actions within your reasoning flow. Use this to structure your internal monologue.\n * Usage: Call 'think' multiple times if needed to break down the problem. Explain your reasoning and specify the intended action (e.g., \"make a tool call\", \"perform calculation\", \"ask clarifying question\").\n\n2. **Analyze** (evaluation):\n * Purpose: Evaluate the result of a think step or a set of tool calls. Assess if the result is expected, sufficient, or requires further investigation.\n * Usage: Call 'analyze' AFTER a set of tool calls or a thought process. Determine the 'next_action' based on your analysis: 'continue' (more reasoning needed), 'validate' (seek external confirmation/validation if possible), or 'final_answer' (ready to conclude).\n * Explain your reasoning highlighting whether the result is correct/sufficient.\n\n## IMPORTANT GUIDELINES\n* **Always Think First:** You MUST use the 'think' tool before making other tool calls or generating a response, unless the request is extremely simple. Use 'think' multiple times to break down complex problems.\n* **Iterate to Solve:** Use the 'think' and 'analyze' tools iteratively to build a clear reasoning path. The typical flow is Think -> [Think -> ...] -> [Tool Calls if needed] -> [Analyze if needed] -> ... -> final_answer. Repeat this cycle until you reach a satisfactory conclusion.\n* **Make multiple tool calls in parallel:** After a 'think' step, you can make multiple tool calls in parallel if needed.\n* **Keep Thoughts Internal:** The reasoning steps (thoughts and analyses) are for your internal process only. Do not share them directly with the user unless asked to explain your reasoning.\n* **Conclude Clearly:** When your analysis determines the 'next_action' is 'final_answer', provide a concise and accurate final answer to the user based on your reasoning steps.\n";
2115
- declare const FEW_SHOT_EXAMPLES = "\n## Examples\n\n**Example 1: Simple Fact Retrieval**\n\n*User Request:* How many continents are there on Earth?\n\n*Agent's Internal Process:*\n```json\n{\n \"tool_call\": {\n \"name\": \"think\",\n \"arguments\": {\n \"title\": \"Understand Request\",\n \"thought\": \"The user wants to know the standard number of continents on Earth. This is a common piece of knowledge.\",\n \"action\": \"Recall or verify the number of continents.\",\n \"confidence\": 0.95\n }\n }\n}\n```\n*--(Agent internally recalls the fact)--*\n```json\n{\n \"tool_call\": {\n \"name\": \"analyze\",\n \"arguments\": {\n \"title\": \"Evaluate Fact\",\n \"result\": \"Standard geographical models list 7 continents: Africa, Antarctica, Asia, Australia, Europe, North America, South America.\",\n \"analysis\": \"The recalled information directly answers the user's question accurately.\",\n \"next_action\": \"final_answer\",\n \"confidence\": 1.0\n }\n }\n}\n```\n\n*Agent's Final Answer to User:*\nThere are 7 continents on Earth: Africa, Antarctica, Asia, Australia, Europe, North America, and South America.\n\n**Example 2: Multi-Step Information Gathering**\n\n*User Request:* What is the capital of France and its current population?\n\n*Agent's Internal Process:*\n```json\n{\n \"tool_call\": {\n \"name\": \"think\",\n \"arguments\": {\n \"title\": \"Plan Information Retrieval\",\n \"thought\": \"The user needs two pieces of information: the capital of France and its current population. I should break this down. First, find the capital.\",\n \"action\": \"Search for the capital of France.\",\n \"confidence\": 0.95\n }\n }\n}\n```\n*--(Tool call: search(query=\"capital of France\"))--*\n*--(Tool Result: \"Paris\")--*\n```json\n{\n \"tool_call\": {\n \"name\": \"analyze\",\n \"arguments\": {\n \"title\": \"Analyze Capital Search Result\",\n \"result\": \"The search result indicates Paris is the capital of France.\",\n \"analysis\": \"This provides the first piece of requested information. Now I need to find the population of Paris.\",\n \"next_action\": \"continue\",\n \"confidence\": 1.0\n }\n }\n}\n```\n```json\n{\n \"tool_call\": {\n \"name\": \"think\",\n \"arguments\": {\n \"title\": \"Plan Population Retrieval\",\n \"thought\": \"The next step is to find the current population of Paris.\",\n \"action\": \"Search for the population of Paris.\",\n \"confidence\": 0.95\n }\n }\n}\n```\n*--(Tool call: search(query=\"population of Paris current\"))--*\n*--(Tool Result: \"Approximately 2.1 million (city proper, estimate for early 2024)\")--*\n```json\n{\n \"tool_call\": {\n \"name\": \"analyze\",\n \"arguments\": {\n \"title\": \"Analyze Population Search Result\",\n \"result\": \"The search provided an estimated population figure for Paris.\",\n \"analysis\": \"I now have both the capital and its estimated population. I can provide the final answer.\",\n \"next_action\": \"final_answer\",\n \"confidence\": 0.9\n }\n }\n}\n```\n\n*Agent's Final Answer to User:*\nThe capital of France is Paris. Its estimated population (city proper) is approximately 2.1 million as of early 2024.\n";
2114
+ declare const DEFAULT_INSTRUCTIONS = "\nYou are equipped with 'think' and 'analyze' capabilities to methodically tackle problems and organize your reasoning process. ALWAYS utilize 'think' before initiating any tool calls or formulating a response.\n\n1. **Think** (Internal Workspace):\n * Objective: Employ the 'think' tool as an internal workspace to dissect complex issues, chart out solution paths, and determine the next steps in your reasoning. Use this to organize your internal thought process.\n * Method: Invoke 'think' repeatedly if necessary for problem decomposition. Articulate your rationale and specify the planned next step (e.g., \"initiate tool call,\" \"compute value,\" \"request clarification\").\n\n2. **Analyze** (Assessment):\n * Objective: Assess the outcome of a thinking phase or a sequence of tool interactions. Determine if the outcome aligns with expectations, is adequate, or necessitates further exploration.\n * Method: Call 'analyze' following a series of tool uses or a completed thought sequence. Define the 'next_action' based on your assessment: 'continue' (further reasoning is required), 'validate' (if possible, seek external verification), or 'final_answer' (prepared to deliver the conclusion).\n * Justify your assessment, indicating whether the result is accurate/sufficient.\n\n## Core Principles\n* **Initiate with Thought:** It is MANDATORY to use the 'think' tool prior to other tool interactions or response generation, except for trivial requests. Use 'think' multiple times for intricate problems.\n* **Iterative Problem Solving:** Employ 'think' and 'analyze' in cycles to construct a transparent reasoning trajectory. The standard sequence is Think -> [Think -> ...] -> [Tool Calls if needed] -> [Analyze if needed] -> ... -> final_answer. Repeat this loop until a satisfactory resolution is achieved.\n* **Parallel Tool Execution:** Following a 'think' step, multiple tool calls can be executed concurrently if required.\n* **Maintain Internal Reasoning:** The steps involving 'think' and 'analyze' constitute your internal cognitive process. Do not expose these steps directly to the user unless specifically asked to elaborate on your reasoning.\n* **Deliver Concise Conclusions:** Once your analysis concludes with 'next_action: final_answer', present a clear and precise final answer to the user, synthesized from your reasoning steps.\n";
2115
+ declare const FEW_SHOT_EXAMPLES = "\n## Illustrations\n\n**Illustration 1: Basic Knowledge Retrieval**\n\n*User Query:* What is the tallest mountain in the world?\n\n*Agent's Internal Processing:*\n```json\n{\n \"tool_call\": {\n \"name\": \"think\",\n \"arguments\": {\n \"title\": \"Parse Request\",\n \"thought\": \"The user is asking for the name of the world's highest peak. This is well-known geographical data.\",\n \"action\": \"Recall or look up the tallest mountain.\",\n \"confidence\": 0.98\n }\n }\n}\n```\n*--(Agent internally accesses the information)--*\n```json\n{\n \"tool_call\": {\n \"name\": \"analyze\",\n \"arguments\": {\n \"title\": \"Assess Information\",\n \"result\": \"Mount Everest is recognized as the tallest mountain above sea level.\",\n \"analysis\": \"The retrieved data directly answers the user's query accurately.\",\n \"next_action\": \"final_answer\",\n \"confidence\": 1.0\n }\n }\n}\n```\n\n*Agent's Final Response to User:*\nThe tallest mountain in the world is Mount Everest.\n\n**Illustration 2: Sequential Information Gathering**\n\n*User Query:* Who directed the movie 'Inception' and what year was it released?\n\n*Agent's Internal Processing:*\n```json\n{\n \"tool_call\": {\n \"name\": \"think\",\n \"arguments\": {\n \"title\": \"Outline Information Needs\",\n \"thought\": \"The request asks for two specific details about the movie 'Inception': its director and release year. I'll handle these sequentially. First, find the director.\",\n \"action\": \"Search for the director of 'Inception'.\",\n \"confidence\": 0.95\n }\n }\n}\n```\n*--(Tool interaction: search(query=\"director of Inception\"))--*\n*--(Tool Outcome: \"Christopher Nolan\")--*\n```json\n{\n \"tool_call\": {\n \"name\": \"analyze\",\n \"arguments\": {\n \"title\": \"Evaluate Director Search\",\n \"result\": \"The search identified Christopher Nolan as the director.\",\n \"analysis\": \"This fulfills the first part of the request. Next, I need the release year.\",\n \"next_action\": \"continue\",\n \"confidence\": 1.0\n }\n }\n}\n```\n```json\n{\n \"tool_call\": {\n \"name\": \"think\",\n \"arguments\": {\n \"title\": \"Plan Release Year Retrieval\",\n \"thought\": \"The subsequent step is to determine the release year for 'Inception'.\",\n \"action\": \"Search for the release year of 'Inception'.\",\n \"confidence\": 0.95\n }\n }\n}\n```\n*--(Tool interaction: search(query=\"release year of Inception\"))--*\n*--(Tool Outcome: \"2010\")--*\n```json\n{\n \"tool_call\": {\n \"name\": \"analyze\",\n \"arguments\": {\n \"title\": \"Evaluate Release Year Search\",\n \"result\": \"The search indicated the release year was 2010.\",\n \"analysis\": \"I have now obtained both the director's name and the release year. I am ready to formulate the final response.\",\n \"next_action\": \"final_answer\",\n \"confidence\": 1.0\n }\n }\n}\n```\n\n*Agent's Final Response to User:*\nThe movie 'Inception' was directed by Christopher Nolan and released in 2010.\n";
2116
2116
  type CreateReasoningToolsOptions = {
2117
2117
  addInstructions?: boolean;
2118
2118
  think?: boolean;
@@ -2448,85 +2448,103 @@ type ToolsetWithTools = Record<string, AnyToolConfig> & {
2448
2448
  type AnyToolConfig = Tool<any>;
2449
2449
 
2450
2450
  /**
2451
- * Client for interacting with Model Context Protocol (MCP) servers
2452
- * Implements MCP specification using the official SDK
2451
+ * Client for interacting with Model Context Protocol (MCP) servers.
2452
+ * Wraps the official MCP SDK client to provide a higher-level interface.
2453
+ * Internal implementation differs from original source.
2453
2454
  */
2454
2455
  declare class MCPClient extends EventEmitter {
2455
2456
  /**
2456
- * Underlying MCP client instance from SDK
2457
+ * Underlying MCP client instance from the SDK.
2457
2458
  */
2458
2459
  private client;
2459
2460
  /**
2460
- * Transport layer for MCP communication
2461
+ * Communication channel (transport layer) for MCP interactions.
2461
2462
  */
2462
2463
  private transport;
2463
2464
  /**
2464
- * Whether the client is connected to the server
2465
+ * Tracks the connection status to the server.
2465
2466
  */
2466
2467
  private connected;
2467
2468
  /**
2468
- * Request timeout in milliseconds
2469
+ * Maximum time allowed for requests in milliseconds.
2469
2470
  */
2470
2471
  private readonly timeout;
2471
2472
  /**
2472
- * Client information used for identification
2473
+ * Information identifying this client to the server.
2473
2474
  */
2474
2475
  private readonly clientInfo;
2475
2476
  /**
2476
- * Creates a new MCP client
2477
+ * Creates a new MCP client instance.
2478
+ * @param config Configuration for the client, including server details and client identity.
2477
2479
  */
2478
2480
  constructor(config: MCPClientConfig);
2479
2481
  /**
2480
- * Set up MCP client event handlers
2482
+ * Sets up handlers for events from the underlying SDK client.
2481
2483
  */
2482
2484
  private setupEventHandlers;
2483
2485
  /**
2484
- * Connect to the MCP server
2486
+ * Establishes a connection to the configured MCP server.
2487
+ * Idempotent: does nothing if already connected.
2485
2488
  */
2486
2489
  connect(): Promise<void>;
2487
2490
  /**
2488
- * Disconnect from the MCP server
2491
+ * Closes the connection to the MCP server.
2492
+ * Idempotent: does nothing if not connected.
2489
2493
  */
2490
2494
  disconnect(): Promise<void>;
2491
2495
  /**
2492
- * List available tools from the MCP server
2496
+ * Fetches the definitions of available tools from the server.
2497
+ * @returns A record mapping tool names to their definitions (schema, description).
2493
2498
  */
2494
2499
  listTools(): Promise<Record<string, unknown>>;
2495
2500
  /**
2496
- * Get tools converted to AgentTools with execute functions
2497
- * This method transforms MCP tool definitions into AgentTools that can be used directly by an Agent
2501
+ * Builds executable Tool objects from the server's tool definitions.
2502
+ * These tools include an `execute` method for calling the remote tool.
2503
+ * @returns A record mapping namespaced tool names (`clientName_toolName`) to executable Tool objects.
2498
2504
  */
2499
2505
  getAgentTools(): Promise<Record<string, Tool<any>>>;
2500
2506
  /**
2501
- * Call a tool on the MCP server
2507
+ * Executes a specified tool on the remote MCP server.
2508
+ * @param toolCall Details of the tool to call, including name and arguments.
2509
+ * @returns The result content returned by the tool.
2502
2510
  */
2503
2511
  callTool(toolCall: MCPToolCall): Promise<MCPToolResult>;
2504
2512
  /**
2505
- * Get the list of available resources from the MCP server
2513
+ * Retrieves a list of resource identifiers available on the server.
2514
+ * @returns A promise resolving to an array of resource ID strings.
2506
2515
  */
2507
2516
  listResources(): Promise<string[]>;
2508
2517
  /**
2509
- * Ensure the client is connected before making requests
2518
+ * Ensures the client is connected before proceeding with an operation.
2519
+ * Attempts to connect if not currently connected.
2520
+ * @throws Error if connection attempt fails.
2510
2521
  */
2511
2522
  private ensureConnected;
2512
2523
  /**
2513
- * Convert and emit error events in a type-safe way
2524
+ * Emits an 'error' event, ensuring the payload is always an Error object.
2525
+ * @param error The error encountered, can be of any type.
2514
2526
  */
2515
2527
  private emitError;
2516
2528
  /**
2517
- * Check if the server config is HTTP-based
2529
+ * Type guard to check if a server configuration is for an HTTP server.
2530
+ * @param server The server configuration object.
2531
+ * @returns True if the configuration type is 'http', false otherwise.
2518
2532
  */
2519
2533
  private isHTTPServer;
2520
2534
  /**
2521
- * Type guard to check if the server config is stdio-based
2535
+ * Type guard to check if a server configuration is for a Stdio server.
2536
+ * @param server The server configuration object.
2537
+ * @returns True if the configuration type is 'stdio', false otherwise.
2522
2538
  */
2523
2539
  private isStdioServer;
2524
2540
  /**
2525
- * Override EventEmitter's on method to provide type safety
2541
+ * Overrides EventEmitter's 'on' method for type-safe event listening.
2542
+ * Uses the original `MCPClientEvents` for event types.
2526
2543
  */
2527
2544
  on<E extends keyof MCPClientEvents>(event: E, listener: MCPClientEvents[E]): this;
2528
2545
  /**
2529
- * Override EventEmitter's emit method to provide type safety
2546
+ * Overrides EventEmitter's 'emit' method for type-safe event emission.
2547
+ * Uses the original `MCPClientEvents` for event types.
2530
2548
  */
2531
2549
  emit<E extends keyof MCPClientEvents>(event: E, ...args: Parameters<MCPClientEvents[E]>): boolean;
2532
2550
  }
@@ -2534,96 +2552,65 @@ declare class MCPClient extends EventEmitter {
2534
2552
  /**
2535
2553
  * Configuration manager for Model Context Protocol (MCP).
2536
2554
  * Handles multiple MCP server connections and tool management.
2537
- * Ensures unique configuration instances based on server settings or provided ID.
2555
+ * NOTE: This version does NOT manage singleton instances automatically.
2538
2556
  */
2539
2557
  declare class MCPConfiguration<TServerKeys extends string = string> {
2540
- /**
2541
- * Unique identifier for this configuration, generated based on server configurations.
2542
- */
2543
- private readonly id;
2544
2558
  /**
2545
2559
  * Map of server configurations keyed by server names.
2546
2560
  */
2547
2561
  private readonly serverConfigs;
2548
2562
  /**
2549
- * Map of connected MCP clients keyed by server names.
2563
+ * Map of connected MCP clients keyed by server names (local cache).
2550
2564
  */
2551
2565
  private readonly mcpClientsById;
2552
2566
  /**
2553
- * Creates a new MCP configuration or returns an existing one if configuration matches.
2554
- * @param options Configuration options including server definitions and an optional unique ID.
2555
- * @throws Error if initialized multiple times with the same configuration without a unique ID.
2567
+ * Creates a new, independent MCP configuration instance.
2568
+ * @param options Configuration options including server definitions.
2556
2569
  */
2557
2570
  constructor(options: {
2558
- id?: string;
2559
2571
  servers: Record<TServerKeys, MCPServerConfig>;
2560
2572
  });
2561
2573
  /**
2562
- * Generates a unique ID for the configuration based on server settings.
2563
- * Uses UUIDv5 to create a deterministic ID from the JSON representation of servers.
2564
- * @returns A unique string identifier.
2574
+ * Type guard to check if an object conforms to the basic structure of AnyToolConfig.
2565
2575
  */
2566
- private generateId;
2576
+ private isAnyToolConfigStructure;
2567
2577
  /**
2568
- * Adds the current instance to the global cache if not already present.
2569
- */
2570
- private addToInstanceCache;
2571
- /**
2572
- * Disconnects all associated MCP clients and removes this configuration instance from the cache.
2573
- * Ensures cleanup of resources.
2578
+ * Disconnects all associated MCP clients for THIS instance.
2574
2579
  */
2575
2580
  disconnect(): Promise<void>;
2576
2581
  /**
2577
- * Retrieves agent-ready tools from all configured MCP servers.
2578
- * Tools are namespaced with their server name (e.g., "serverName.toolName").
2579
- * Agent-ready tools include executable functions.
2582
+ * Retrieves agent-ready tools from all configured MCP servers for this instance.
2580
2583
  * @returns A flat array of all agent-ready tools.
2581
2584
  */
2582
2585
  getTools(): Promise<Tool<any>[]>;
2583
2586
  /**
2584
- * Retrieves raw tool definitions (without execute functions) from all configured MCP servers.
2585
- * Tools are namespaced with their server name (e.g., "serverName.toolName").
2587
+ * Retrieves raw tool definitions from all configured MCP servers for this instance.
2586
2588
  * @returns A flat record of all raw tools keyed by their namespaced name.
2587
2589
  */
2588
2590
  getRawTools(): Promise<Record<string, AnyToolConfig>>;
2589
2591
  /**
2590
- * Retrieves agent-ready toolsets grouped by server name.
2591
- * Each toolset contains tools with executable functions for a specific server.
2592
- * @returns A record where keys are server names and values are records of agent-ready tools for that server.
2592
+ * Retrieves agent-ready toolsets grouped by server name for this instance.
2593
+ * @returns A record where keys are server names and values are agent-ready toolsets.
2593
2594
  */
2594
2595
  getToolsets(): Promise<Record<TServerKeys, ToolsetWithTools>>;
2595
2596
  /**
2596
- * Retrieves raw tool definitions (without execute functions) grouped by server name.
2597
- * @returns A record where keys are server names and values are records of raw tools for that server.
2597
+ * Retrieves raw tool definitions grouped by server name for this instance.
2598
+ * @returns A record where keys are server names and values are records of raw tools.
2598
2599
  */
2599
2600
  getRawToolsets(): Promise<Record<TServerKeys, Record<string, AnyToolConfig>>>;
2600
2601
  /**
2601
- * Retrieves a specific connected MCP client by its server name.
2602
- * Connects the client if it's not already connected.
2603
- * @param serverName The name of the server/client to retrieve.
2604
- * @returns The connected MCPClient instance or undefined if the server name is not configured.
2602
+ * Retrieves a specific connected MCP client by its server name for this instance.
2605
2603
  */
2606
2604
  getClient(serverName: TServerKeys): Promise<MCPClient | undefined>;
2607
2605
  /**
2608
- * Retrieves all configured MCP clients, ensuring they are connected.
2609
- * @returns A record of connected MCPClient instances keyed by server name.
2606
+ * Retrieves all configured MCP clients for this instance, ensuring they are connected.
2610
2607
  */
2611
2608
  getClients(): Promise<Record<TServerKeys, MCPClient>>;
2612
2609
  /**
2613
- * Gets or creates an MCP client connection for a given server configuration.
2614
- * Ensures the client is connected before returning. Handles connection errors.
2615
- * @param name The server name (key).
2616
- * @param config The server configuration.
2617
- * @returns A promise resolving to the connected MCPClient.
2618
- * @throws Error if connection fails.
2610
+ * Internal helper to get/create/connect a client for this instance.
2611
+ * Manages the local mcpClientsById cache.
2619
2612
  */
2620
2613
  private getConnectedClient;
2621
- /**
2622
- * Executes a callback for each configured server, providing the raw tools listed by the client.
2623
- * Handles connection and tool listing errors internally.
2624
- * @param callback Async function to execute for each server's raw tools.
2625
- */
2626
- private forEachClientRawTools;
2627
2614
  }
2628
2615
 
2629
2616
  /**