@voltagent/core 1.1.36 → 1.1.38

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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ModelMessage, DataContent as DataContent$1, UserContent, AssistantContent, ToolContent, ProviderOptions as ProviderOptions$1 } from '@ai-sdk/provider-utils';
1
+ import { ModelMessage, ToolCallOptions, DataContent as DataContent$1, UserContent, AssistantContent, ToolContent, ProviderOptions as ProviderOptions$1 } from '@ai-sdk/provider-utils';
2
2
  export { AssistantContent, FilePart, ImagePart, TextPart, ToolContent, UserContent } from '@ai-sdk/provider-utils';
3
3
  import { Tool as Tool$1, TextStreamPart, generateText, UIMessage, StreamTextResult, LanguageModel, CallSettings, Output, ToolSet, GenerateTextResult, GenerateObjectResult, AsyncIterableStream as AsyncIterableStream$1, CallWarning, LanguageModelUsage, FinishReason, EmbeddingModel } from 'ai';
4
4
  export { LanguageModel, Tool as VercelTool, hasToolCall, stepCountIs } from 'ai';
@@ -58,95 +58,164 @@ type Toolkit = {
58
58
  */
59
59
  declare const createToolkit: (options: Toolkit) => Toolkit;
60
60
 
61
- /**
62
- * Status of a tool at any given time
63
- */
64
- type ToolStatus = "idle" | "working" | "error" | "completed";
65
- /**
66
- * Tool status information
67
- */
68
- type ToolStatusInfo = {
69
- name: string;
70
- status: ToolStatus;
71
- result?: any;
72
- error?: any;
73
- input?: any;
74
- output?: any;
75
- timestamp: Date;
76
- parameters?: any;
77
- };
78
- /**
79
- * Manager class to handle all tool-related operations, including Toolkits.
80
- */
81
- declare class ToolManager {
61
+ declare abstract class BaseToolManager<TItems extends AgentTool | Tool$1 | Toolkit = AgentTool | Tool$1 | Toolkit, TToolkitManager extends BaseToolManager<TItems, never> | never = BaseToolManager<TItems, never>> {
82
62
  /**
83
63
  * User tools managed by this manager.
84
64
  * Includes server-side and client-side tools (no server execute) managed separately from server-executable tools.
85
65
  */
86
- private baseTools;
66
+ protected baseTools: Map<string, BaseTool>;
87
67
  /**
88
68
  * Provider-defined tools managed by providers
89
69
  */
90
- private providerTools;
70
+ protected providerTools: Map<string, ProviderTool>;
91
71
  /**
92
72
  * Toolkits managed by this manager.
93
73
  */
94
- private toolkits;
74
+ protected toolkits: Map<string, TToolkitManager>;
95
75
  /**
96
76
  * Logger instance
97
77
  */
98
- private logger;
78
+ protected logger: Logger;
99
79
  /**
100
80
  * Creates a new ToolManager.
101
81
  * Accepts individual tools, provider-defined tools, and toolkits.
102
82
  */
103
- constructor(items?: (AgentTool | Tool$1 | Toolkit)[], logger?: Logger);
83
+ protected constructor(items?: TItems[], logger?: Logger);
84
+ /** Not all inheritances of BaseToolManager support toolkits - thus this is abstract */
85
+ abstract addToolkit(toolkit: Toolkit): boolean;
86
+ /**
87
+ * Add multiple tools or toolkits to the manager.
88
+ */
89
+ addItems(items: TItems[]): void;
90
+ addStandaloneTool(tool: AgentTool | Tool$1): boolean;
91
+ /**
92
+ * Remove a standalone tool by name. Does not remove tools from toolkits.
93
+ * @returns true if the tool was removed, false if it wasn't found.
94
+ */
95
+ removeTool(toolName: string): boolean;
96
+ /**
97
+ * Remove a toolkit by name.
98
+ * @returns true if the toolkit was removed, false if it wasn't found.
99
+ */
100
+ removeToolkit(toolkitName: string): boolean;
104
101
  /**
105
102
  * Get all toolkits managed by this manager.
106
103
  */
107
- getToolkits(): Toolkit[];
104
+ getToolkits(): TToolkitManager[];
105
+ /**
106
+ * Get standalone tools and standalone tools within toolkits as a flattened list.
107
+ */
108
+ getAllBaseTools(): BaseTool[];
108
109
  /**
109
110
  * Get provider-defined tools managed externally by providers.
110
111
  */
111
- getProviderTools(): ProviderTool[];
112
- addTool(tool: AgentTool | Tool$1): boolean;
113
- hasTool(toolName: string): boolean;
112
+ getAllProviderTools(): ProviderTool[];
114
113
  /**
115
- * Add multiple tools or toolkits to the manager.
114
+ * Get all kinds of tools, owned by this manager and inside toolkits as a flattened list.
115
+ * */
116
+ getAllTools(): (BaseTool | ProviderTool)[];
117
+ /**
118
+ * Get names of all tools (standalone and inside toolkits), deduplicated.
116
119
  */
117
- addItems(items: (AgentTool | Tool$1 | Toolkit)[]): void;
120
+ getAllToolNames(): string[];
118
121
  /**
119
- * Get all individual tools and tools within toolkits as a flattened list.
122
+ * Returns tools owned directly by this manager (standalone tools), excluding tools inside toolkits.
120
123
  */
121
- getTools(): BaseTool[];
124
+ protected getStandaloneTools(): (BaseTool | ProviderTool)[];
122
125
  /**
123
- * Add a toolkit to the manager.
124
- * If a toolkit with the same name already exists, it will be replaced.
125
- * Also checks if any tool within the toolkit conflicts with existing standalone tools or tools in other toolkits.
126
- * @returns true if the toolkit was successfully added or replaced.
126
+ * Check if any tool with the given name exists in this manager or nested toolkits.
127
127
  */
128
- addToolkit(toolkit: Toolkit): boolean;
129
- findInToolkits(toolName: string): Tool | ProviderTool | false;
128
+ hasToolInAny(toolName: string): boolean;
129
+ }
130
+
131
+ declare class ToolkitManager extends BaseToolManager<AgentTool | Tool$1, never> {
132
+ readonly name: string;
130
133
  /**
131
- * Remove a standalone tool by name. Does not remove tools from toolkits.
132
- * @returns true if the tool was removed, false if it wasn't found.
134
+ * A brief description of what the toolkit does or what tools it contains.
135
+ * Optional.
133
136
  */
134
- removeTool(toolName: string): boolean;
137
+ readonly description?: string | undefined;
135
138
  /**
136
- * Remove a toolkit by name.
137
- * @returns true if the toolkit was removed, false if it wasn't found.
139
+ * Shared instructions for the LLM on how to use the tools within this toolkit.
140
+ * These instructions are intended to be added to the system prompt if `addInstructions` is true.
141
+ * Optional.
138
142
  */
139
- removeToolkit(toolkitName: string): boolean;
143
+ readonly instructions?: string | undefined;
144
+ /**
145
+ * Whether to automatically add the toolkit's `instructions` to the agent's system prompt.
146
+ * If true, the instructions from individual tools within this toolkit might be ignored
147
+ * by the Agent's system message generation logic to avoid redundancy.
148
+ * Defaults to false.
149
+ */
150
+ readonly addInstructions: boolean;
151
+ /**
152
+ * Constructor does not accept toolkits - only tools
153
+ * */
154
+ constructor(name: string, items?: (AgentTool | Tool$1)[],
155
+ /**
156
+ * A brief description of what the toolkit does or what tools it contains.
157
+ * Optional.
158
+ */
159
+ description?: string | undefined,
160
+ /**
161
+ * Shared instructions for the LLM on how to use the tools within this toolkit.
162
+ * These instructions are intended to be added to the system prompt if `addInstructions` is true.
163
+ * Optional.
164
+ */
165
+ instructions?: string | undefined,
166
+ /**
167
+ * Whether to automatically add the toolkit's `instructions` to the agent's system prompt.
168
+ * If true, the instructions from individual tools within this toolkit might be ignored
169
+ * by the Agent's system message generation logic to avoid redundancy.
170
+ * Defaults to false.
171
+ */
172
+ addInstructions?: boolean, logger?: Logger);
173
+ /**
174
+ * Toolkits are not supported inside a ToolkitManager (toolkits contain tools only).
175
+ * Keep the same signature as BaseToolManager.addToolkit to preserve type compatibility,
176
+ * but implement as a no-op (or warn) so callers won't crash.
177
+ */
178
+ addToolkit(toolkit: Toolkit): boolean;
179
+ }
180
+
181
+ declare class ToolManager extends BaseToolManager<AgentTool | Tool$1 | Toolkit, ToolkitManager> {
140
182
  /**
141
- * Combine static base tools with runtime tools (includes tools from toolkits).
183
+ * Creates a new ToolManager.
184
+ * Accepts individual tools, provider-defined tools, and toolkits.
142
185
  */
143
- combineStaticAndRuntimeBaseTools(runtimeTools?: (BaseTool | Toolkit)[]): BaseTool[];
186
+ constructor(items?: (AgentTool | Tool$1 | Toolkit)[], logger?: Logger);
187
+ /**
188
+ * Add a toolkit to the manager.
189
+ * If a toolkit with the same name already exists, it will be replaced.
190
+ * Also checks if any tool within the toolkit conflicts with existing standalone tools or tools in other toolkits.
191
+ * @returns true if the toolkit was successfully added or replaced.
192
+ */
193
+ addToolkit(toolkit: Toolkit): boolean;
194
+ prepareToolsForExecution(createToolExecuteFunction: (tool: AgentTool) => (args: any, options?: ToolExecuteOptions) => Promise<any>): Record<string, any>;
144
195
  /**
145
196
  * Get agent's tools (including those in toolkits) for API exposure.
146
197
  */
147
198
  getToolsForApi(): ApiToolInfo[];
148
199
  }
149
200
 
201
+ /**
202
+ * Status of a tool at any given time
203
+ */
204
+ type ToolStatus = "idle" | "working" | "error" | "completed";
205
+ /**
206
+ * Tool status information
207
+ */
208
+ type ToolStatusInfo = {
209
+ name: string;
210
+ status: ToolStatus;
211
+ result?: any;
212
+ error?: any;
213
+ input?: any;
214
+ output?: any;
215
+ timestamp: Date;
216
+ parameters?: any;
217
+ };
218
+
150
219
  /**
151
220
  * Tool definition compatible with Vercel AI SDK
152
221
  */
@@ -184,7 +253,7 @@ type ToolOptions<T extends ToolSchema = ToolSchema, O extends ToolSchema | undef
184
253
  /**
185
254
  * Function to execute when the tool is called
186
255
  */
187
- execute?: (args: z.infer<T>, context?: OperationContext) => Promise<O extends ToolSchema ? z.infer<O> : unknown>;
256
+ execute?: (args: z.infer<T>, context?: OperationContext, options?: ToolExecuteOptions) => Promise<O extends ToolSchema ? z.infer<O> : unknown>;
188
257
  };
189
258
  /**
190
259
  * Tool class for defining tools that agents can use
@@ -218,7 +287,7 @@ declare class Tool<T extends ToolSchema = ToolSchema, O extends ToolSchema | und
218
287
  /**
219
288
  * Function to execute when the tool is called
220
289
  */
221
- readonly execute?: (args: z.infer<T>, context?: OperationContext) => Promise<O extends ToolSchema ? z.infer<O> : unknown>;
290
+ readonly execute?: (args: z.infer<T>, context?: OperationContext, options?: ToolExecuteOptions) => Promise<O extends ToolSchema ? z.infer<O> : unknown>;
222
291
  /**
223
292
  * Whether this tool should be executed on the client side.
224
293
  * Returns true when no server-side execute handler is provided.
@@ -416,24 +485,23 @@ type MessageRole = "user" | "assistant" | "system" | "tool";
416
485
  */
417
486
  type BaseMessage = ModelMessage;
418
487
  type ToolSchema = z.ZodType;
419
- type ToolExecuteOptions = {
488
+ type ToolExecuteOptions = ToolCallOptions & {
420
489
  /**
421
- * Optional AbortController for cancelling the execution and accessing the signal
490
+ * Optional AbortController for cancelling the execution and accessing the signal.
491
+ * Prefer using the provided abortSignal, but we keep this for backward compatibility.
422
492
  */
423
493
  abortController?: AbortController;
424
494
  /**
425
- * @deprecated Use abortController.signal instead. This field will be removed in a future version.
426
- * Optional AbortSignal to abort the execution
495
+ * @deprecated Use abortController.signal or options.abortSignal instead. This field will be removed in a future version.
427
496
  */
428
497
  signal?: AbortSignal;
429
498
  /**
430
499
  * The operation context associated with the agent invocation triggering this tool execution.
431
- * Provides access to operation-specific state like context.
432
- * The context includes a logger with full execution context (userId, conversationId, executionId).
500
+ * Provides access to operation-specific state like context and logging metadata.
433
501
  */
434
502
  operationContext?: OperationContext;
435
503
  /**
436
- * Additional options can be added in the future
504
+ * Additional options can be added in the future.
437
505
  */
438
506
  [key: string]: any;
439
507
  };
@@ -666,6 +734,30 @@ interface WorkflowStateEntry {
666
734
  };
667
735
  suspendData?: any;
668
736
  };
737
+ /**
738
+ * Stream events collected during execution
739
+ * Used for timeline visualization in UI
740
+ */
741
+ events?: Array<{
742
+ id: string;
743
+ type: string;
744
+ name?: string;
745
+ from?: string;
746
+ startTime: string;
747
+ endTime?: string;
748
+ status?: string;
749
+ input?: any;
750
+ output?: any;
751
+ metadata?: Record<string, unknown>;
752
+ context?: Record<string, unknown>;
753
+ }>;
754
+ /** Final output of the workflow execution */
755
+ output?: unknown;
756
+ /** Cancellation metadata */
757
+ cancellation?: {
758
+ cancelledAt: Date;
759
+ reason?: string;
760
+ };
669
761
  /** User ID if applicable */
670
762
  userId?: string;
671
763
  /** Conversation ID if applicable */
@@ -809,10 +901,10 @@ interface VectorItem$1 {
809
901
  * Handles persistence of conversations and messages
810
902
  */
811
903
  interface StorageAdapter {
812
- addMessage(message: UIMessage, userId: string, conversationId: string): Promise<void>;
813
- addMessages(messages: UIMessage[], userId: string, conversationId: string): Promise<void>;
814
- getMessages(userId: string, conversationId: string, options?: GetMessagesOptions): Promise<UIMessage[]>;
815
- clearMessages(userId: string, conversationId?: string): Promise<void>;
904
+ addMessage(message: UIMessage, userId: string, conversationId: string, context?: OperationContext): Promise<void>;
905
+ addMessages(messages: UIMessage[], userId: string, conversationId: string, context?: OperationContext): Promise<void>;
906
+ getMessages(userId: string, conversationId: string, options?: GetMessagesOptions, context?: OperationContext): Promise<UIMessage[]>;
907
+ clearMessages(userId: string, conversationId?: string, context?: OperationContext): Promise<void>;
816
908
  createConversation(input: CreateConversationInput): Promise<Conversation>;
817
909
  getConversation(id: string): Promise<Conversation | null>;
818
910
  getConversations(resourceId: string): Promise<Conversation[]>;
@@ -1071,7 +1163,7 @@ declare class Memory {
1071
1163
  /**
1072
1164
  * Get messages from a conversation
1073
1165
  */
1074
- getMessages(userId: string, conversationId: string, options?: GetMessagesOptions): Promise<UIMessage[]>;
1166
+ getMessages(userId: string, conversationId: string, options?: GetMessagesOptions, context?: OperationContext): Promise<UIMessage[]>;
1075
1167
  /**
1076
1168
  * Save a single message
1077
1169
  */
@@ -1079,15 +1171,15 @@ declare class Memory {
1079
1171
  /**
1080
1172
  * Add a single message (alias for consistency with existing API)
1081
1173
  */
1082
- addMessage(message: UIMessage, userId: string, conversationId: string): Promise<void>;
1174
+ addMessage(message: UIMessage, userId: string, conversationId: string, context?: OperationContext): Promise<void>;
1083
1175
  /**
1084
1176
  * Add multiple messages in batch
1085
1177
  */
1086
- addMessages(messages: UIMessage[], userId: string, conversationId: string): Promise<void>;
1178
+ addMessages(messages: UIMessage[], userId: string, conversationId: string, context?: OperationContext): Promise<void>;
1087
1179
  /**
1088
1180
  * Clear messages for a user
1089
1181
  */
1090
- clearMessages(userId: string, conversationId?: string): Promise<void>;
1182
+ clearMessages(userId: string, conversationId?: string, context?: OperationContext): Promise<void>;
1091
1183
  /**
1092
1184
  * Get a conversation by ID
1093
1185
  */
@@ -1235,7 +1327,7 @@ declare class Memory {
1235
1327
  */
1236
1328
  saveMessageWithContext(message: UIMessage, userId: string, conversationId: string, context?: {
1237
1329
  logger?: Logger;
1238
- }): Promise<void>;
1330
+ }, operationContext?: OperationContext): Promise<void>;
1239
1331
  /**
1240
1332
  * Get messages with semantic search support
1241
1333
  * Simple version without event publishing (handled by MemoryManagerV2)
@@ -1249,7 +1341,7 @@ declare class Memory {
1249
1341
  semanticLimit?: number;
1250
1342
  semanticThreshold?: number;
1251
1343
  mergeStrategy?: "prepend" | "append" | "interleave";
1252
- }): Promise<UIMessage[]>;
1344
+ }, operationContext?: OperationContext): Promise<UIMessage[]>;
1253
1345
  /**
1254
1346
  * Internal: Set resource ID (agent ID)
1255
1347
  */
@@ -3366,6 +3458,7 @@ interface OnToolStartHookArgs {
3366
3458
  tool: AgentTool;
3367
3459
  context: OperationContext;
3368
3460
  args: any;
3461
+ options?: ToolExecuteOptions;
3369
3462
  }
3370
3463
  interface OnToolEndHookArgs {
3371
3464
  agent: Agent;
@@ -3375,6 +3468,7 @@ interface OnToolEndHookArgs {
3375
3468
  /** The error if the tool execution failed. */
3376
3469
  error: VoltAgentError | AbortError | undefined;
3377
3470
  context: OperationContext;
3471
+ options?: ToolExecuteOptions;
3378
3472
  }
3379
3473
  interface OnPrepareMessagesHookArgs {
3380
3474
  /** The messages that will be sent to the LLM (AI SDK UIMessage). */
@@ -4505,10 +4599,7 @@ declare class Agent {
4505
4599
  * Validate tool output against optional output schema.
4506
4600
  */
4507
4601
  private validateToolOutput;
4508
- /**
4509
- * Convert VoltAgent tools to AI SDK format with context injection
4510
- */
4511
- private convertTools;
4602
+ private createToolExecutionFactory;
4512
4603
  /**
4513
4604
  * Create step handler for memory and hooks
4514
4605
  */
@@ -6598,9 +6689,9 @@ declare const ReasoningStepSchema: z.ZodObject<{
6598
6689
  agentId: z.ZodString;
6599
6690
  }, "strip", z.ZodTypeAny, {
6600
6691
  type: "thought" | "analysis";
6601
- title: string;
6602
6692
  id: string;
6603
6693
  reasoning: string;
6694
+ title: string;
6604
6695
  historyEntryId: string;
6605
6696
  agentId: string;
6606
6697
  timestamp: string;
@@ -6610,9 +6701,9 @@ declare const ReasoningStepSchema: z.ZodObject<{
6610
6701
  next_action?: NextAction | undefined;
6611
6702
  }, {
6612
6703
  type: "thought" | "analysis";
6613
- title: string;
6614
6704
  id: string;
6615
6705
  reasoning: string;
6706
+ title: string;
6616
6707
  historyEntryId: string;
6617
6708
  agentId: string;
6618
6709
  timestamp: string;
@@ -6769,19 +6860,19 @@ declare class InMemoryStorageAdapter implements StorageAdapter {
6769
6860
  /**
6770
6861
  * Add a single message
6771
6862
  */
6772
- addMessage(message: UIMessage, userId: string, conversationId: string): Promise<void>;
6863
+ addMessage(message: UIMessage, userId: string, conversationId: string, _context?: OperationContext): Promise<void>;
6773
6864
  /**
6774
6865
  * Add multiple messages
6775
6866
  */
6776
- addMessages(messages: UIMessage[], userId: string, conversationId: string): Promise<void>;
6867
+ addMessages(messages: UIMessage[], userId: string, conversationId: string, context?: OperationContext): Promise<void>;
6777
6868
  /**
6778
6869
  * Get messages with optional filtering
6779
6870
  */
6780
- getMessages(userId: string, conversationId: string, options?: GetMessagesOptions): Promise<UIMessage[]>;
6871
+ getMessages(userId: string, conversationId: string, options?: GetMessagesOptions, _context?: OperationContext): Promise<UIMessage[]>;
6781
6872
  /**
6782
6873
  * Clear messages for a user
6783
6874
  */
6784
- clearMessages(userId: string, conversationId?: string): Promise<void>;
6875
+ clearMessages(userId: string, conversationId?: string, _context?: OperationContext): Promise<void>;
6785
6876
  /**
6786
6877
  * Create a new conversation
6787
6878
  */