@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 +59 -72
- package/dist/index.js +266 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +266 -238
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -8
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
|
|
2115
|
-
declare const FEW_SHOT_EXAMPLES = "\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
|
-
*
|
|
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
|
-
*
|
|
2461
|
+
* Communication channel (transport layer) for MCP interactions.
|
|
2461
2462
|
*/
|
|
2462
2463
|
private transport;
|
|
2463
2464
|
/**
|
|
2464
|
-
*
|
|
2465
|
+
* Tracks the connection status to the server.
|
|
2465
2466
|
*/
|
|
2466
2467
|
private connected;
|
|
2467
2468
|
/**
|
|
2468
|
-
*
|
|
2469
|
+
* Maximum time allowed for requests in milliseconds.
|
|
2469
2470
|
*/
|
|
2470
2471
|
private readonly timeout;
|
|
2471
2472
|
/**
|
|
2472
|
-
*
|
|
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
|
-
*
|
|
2482
|
+
* Sets up handlers for events from the underlying SDK client.
|
|
2481
2483
|
*/
|
|
2482
2484
|
private setupEventHandlers;
|
|
2483
2485
|
/**
|
|
2484
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
2497
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
2554
|
-
* @param options Configuration options including server definitions
|
|
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
|
-
*
|
|
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
|
|
2576
|
+
private isAnyToolConfigStructure;
|
|
2567
2577
|
/**
|
|
2568
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
2597
|
-
* @returns A record where keys are server names and values are records of raw tools
|
|
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
|
-
*
|
|
2614
|
-
*
|
|
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
|
/**
|