@voltagent/core 0.1.17 → 0.1.19

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
@@ -35,6 +35,14 @@ type Toolkit = {
35
35
  */
36
36
  tools: Tool<ToolSchema>[];
37
37
  };
38
+ /**
39
+ * Helper function for creating a new toolkit.
40
+ * Provides default values and ensures the basic structure is met.
41
+ *
42
+ * @param options - The configuration options for the toolkit.
43
+ * @returns A Toolkit object.
44
+ */
45
+ declare const createToolkit: (options: Toolkit) => Toolkit;
38
46
 
39
47
  /**
40
48
  * Status of a tool at any given time
@@ -206,6 +214,131 @@ declare const createTool: <T extends ToolSchema>(options: ToolOptions<T>) => Too
206
214
  */
207
215
  declare const tool: <T extends ToolSchema>(options: ToolOptions<T>) => Tool<T>;
208
216
 
217
+ type EventStatus = AgentStatus;
218
+ type TimelineEventType = "memory" | "tool" | "agent" | "retriever";
219
+ /**
220
+ * Types for tracked event functionality
221
+ */
222
+ type EventUpdater = (updateOptions: {
223
+ status?: AgentStatus;
224
+ data?: Record<string, any>;
225
+ }) => Promise<AgentHistoryEntry | undefined>;
226
+
227
+ interface ExportAgentHistoryPayload {
228
+ agent_id: string;
229
+ project_id: string;
230
+ history_id: string;
231
+ timestamp: string;
232
+ type: string;
233
+ status: string;
234
+ input: Record<string, unknown>;
235
+ output?: Record<string, unknown>;
236
+ error?: Record<string, unknown>;
237
+ usage?: Record<string, unknown>;
238
+ agent_snapshot?: Record<string, unknown>;
239
+ steps?: HistoryStep[];
240
+ userId?: string;
241
+ conversationId?: string;
242
+ }
243
+ interface ExportTimelineEventPayload {
244
+ history_id: string;
245
+ event_id: string;
246
+ event: TimelineEvent;
247
+ }
248
+ interface AgentHistoryUpdatableFields {
249
+ input?: AgentHistoryEntry["input"];
250
+ output?: string;
251
+ status?: AgentStatus;
252
+ usage?: UsageInfo;
253
+ agent_snapshot?: Record<string, unknown>;
254
+ }
255
+ interface TimelineEventUpdatableFields {
256
+ timestamp?: string;
257
+ type?: TimelineEventType;
258
+ name?: string;
259
+ status?: EventStatus;
260
+ error?: Record<string, unknown>;
261
+ input?: Record<string, unknown>;
262
+ output?: Record<string, unknown>;
263
+ }
264
+
265
+ /**
266
+ * Options for configuring the VoltAgentExporter.
267
+ */
268
+ interface VoltAgentExporterOptions {
269
+ /**
270
+ * The base URL for the VoltAgent Edge Functions.
271
+ */
272
+ baseUrl: string;
273
+ /**
274
+ * The public API key for the project, used to identify the project
275
+ * when sending telemetry data.
276
+ */
277
+ publicKey: string;
278
+ /**
279
+ * The client's secret key (obtained once during project creation)
280
+ * used for authenticating requests to the telemetry Edge Functions.
281
+ * This will be sent as 'clientSecretKey' in the request body.
282
+ */
283
+ secretKey: string;
284
+ /**
285
+ * Optional fetch implementation. Defaults to global fetch.
286
+ * Useful for environments where global fetch might not be available or needs to be polyfilled (e.g., some Node.js versions).
287
+ */
288
+ fetch?: typeof fetch;
289
+ }
290
+
291
+ declare class VoltAgentExporter {
292
+ private apiClient;
293
+ readonly publicKey: string;
294
+ constructor(options: VoltAgentExporterOptions);
295
+ /**
296
+ * Exports a single agent history entry.
297
+ * @param historyEntryData - The agent history data to export.
298
+ * This should conform to ExportAgentHistoryPayload.
299
+ * @returns A promise that resolves with the response from the telemetry service,
300
+ * typically including the ID of the created history entry.
301
+ */
302
+ exportHistoryEntry(historyEntryData: ExportAgentHistoryPayload): Promise<{
303
+ historyEntryId: string;
304
+ }>;
305
+ /**
306
+ * Exports a single timeline event.
307
+ * (Placeholder for when the 'export-timeline-event' Edge Function is ready)
308
+ * @param timelineEventData - The timeline event data to export.
309
+ * This should conform to ExportTimelineEventPayload.
310
+ * @returns A promise that resolves with the response from the telemetry service.
311
+ */
312
+ exportTimelineEvent(timelineEventData: ExportTimelineEventPayload): Promise<{
313
+ timelineEventId: string;
314
+ }>;
315
+ /**
316
+ * Exports history steps for a specific agent history entry.
317
+ * @param project_id - The project ID associated with the history entry.
318
+ * @param history_id - The ID of the history entry to export steps for.
319
+ * @param steps - The steps data to export.
320
+ * @returns A promise that resolves with the response from the telemetry service.
321
+ */
322
+ exportHistorySteps(project_id: string, history_id: string, steps: HistoryStep[]): Promise<void>;
323
+ /**
324
+ * Updates specific fields of an agent history entry.
325
+ * @param project_id - The project ID associated with the history entry.
326
+ * @param history_id - The ID of the history entry to update.
327
+ * @param updates - An object containing the fields to update.
328
+ * Should conform to Partial<AgentHistoryUpdatableFields>.
329
+ * @returns A promise that resolves with the response from the telemetry service.
330
+ */
331
+ updateHistoryEntry(project_id: string, history_id: string, updates: Partial<AgentHistoryUpdatableFields>): Promise<void>;
332
+ /**
333
+ * Updates specific fields of a timeline event.
334
+ * @param history_id - The ID of the parent history entry.
335
+ * @param event_id - The ID of the timeline event to update.
336
+ * @param updates - An object containing the fields to update.
337
+ * @returns A promise that resolves when the operation is complete.
338
+ */
339
+ updateTimelineEvent(history_id: string, event_id: string, updates: TimelineEventUpdatableFields): Promise<void>;
340
+ }
341
+
209
342
  /**
210
343
  * Step information for history
211
344
  */
@@ -213,7 +346,7 @@ interface HistoryStep {
213
346
  type: "message" | "tool_call" | "tool_result" | "text";
214
347
  name?: string;
215
348
  content?: string;
216
- arguments?: Record<string, any>;
349
+ arguments?: Record<string, unknown>;
217
350
  }
218
351
  /**
219
352
  * Timeline event for detailed history
@@ -226,7 +359,7 @@ interface TimelineEvent {
226
359
  /**
227
360
  * Timestamp when the event occurred
228
361
  */
229
- timestamp: Date;
362
+ timestamp: string;
230
363
  /**
231
364
  * Name of the event (e.g., "generating", "tool_calling", "tool_result", etc.)
232
365
  * In the new format, "componentName:operationName" style (e.g.: "memory:getMessages")
@@ -241,11 +374,11 @@ interface TimelineEvent {
241
374
  * Optional additional data specific to the event type
242
375
  * In the new format: { status, input, output, updatedAt etc. }
243
376
  */
244
- data?: Record<string, any>;
377
+ data?: Record<string, unknown>;
245
378
  /**
246
379
  * Optional timestamp for when the event was last updated
247
380
  */
248
- updatedAt?: Date;
381
+ updatedAt?: string;
249
382
  /**
250
383
  * Type of the event
251
384
  */
@@ -266,7 +399,7 @@ interface AgentHistoryEntry {
266
399
  /**
267
400
  * Original input to the agent
268
401
  */
269
- input: string | Record<string, any> | BaseMessage[];
402
+ input: string | Record<string, unknown> | BaseMessage[];
270
403
  /**
271
404
  * Final output from the agent
272
405
  */
@@ -309,18 +442,33 @@ declare class HistoryManager {
309
442
  * Memory manager for storing history entries
310
443
  */
311
444
  private memoryManager;
445
+ /**
446
+ * Optional VoltAgentExporter for sending telemetry data.
447
+ */
448
+ private voltAgentExporter?;
312
449
  /**
313
450
  * Create a new history manager
314
451
  *
315
- * @param maxEntries - Maximum number of history entries to keep (0 = unlimited)
316
- * @param agentId - Agent ID for emitting events
452
+ * @param agentId - Agent ID for emitting events and for storage
317
453
  * @param memoryManager - Memory manager instance to use
454
+ * @param maxEntries - Maximum number of history entries to keep (0 = unlimited)
455
+ * @param voltAgentExporter - Optional exporter for telemetry
318
456
  */
319
- constructor(maxEntries: number | undefined, agentId: string, memoryManager: MemoryManager);
457
+ constructor(agentId: string, memoryManager: MemoryManager, maxEntries?: number, voltAgentExporter?: VoltAgentExporter);
320
458
  /**
321
459
  * Set the agent ID for this history manager
322
460
  */
323
461
  setAgentId(agentId: string): void;
462
+ /**
463
+ * Sets the VoltAgentExporter for this history manager instance.
464
+ * This allows the exporter to be set after the HistoryManager is created.
465
+ */
466
+ setExporter(exporter: VoltAgentExporter): void;
467
+ /**
468
+ * Checks if a VoltAgentExporter is configured for this history manager.
469
+ * @returns True if an exporter is configured, false otherwise.
470
+ */
471
+ isExporterConfigured(): boolean;
324
472
  /**
325
473
  * Add a new history entry
326
474
  *
@@ -329,9 +477,12 @@ declare class HistoryManager {
329
477
  * @param status - Status of the entry
330
478
  * @param steps - Steps taken during generation
331
479
  * @param options - Additional options for the entry
480
+ * @param agentSnapshot - Optional agent snapshot for telemetry
481
+ * @param userId - Optional userId for telemetry
482
+ * @param conversationId - Optional conversationId for telemetry
332
483
  * @returns The new history entry
333
484
  */
334
- addEntry(input: string | Record<string, any> | BaseMessage[], output: string, status: AgentStatus, steps?: HistoryStep[], options?: Partial<Omit<AgentHistoryEntry, "id" | "timestamp" | "input" | "output" | "status" | "steps">>): Promise<AgentHistoryEntry>;
485
+ addEntry(input: string | Record<string, unknown> | BaseMessage[], output: string, status: AgentStatus, steps?: HistoryStep[], options?: Partial<Omit<AgentHistoryEntry, "id" | "timestamp" | "input" | "output" | "status" | "steps">>, agentSnapshot?: Record<string, unknown>, userId?: string, conversationId?: string): Promise<AgentHistoryEntry>;
335
486
  /**
336
487
  * Add a timeline event to an existing history entry
337
488
  *
@@ -378,7 +529,9 @@ declare class HistoryManager {
378
529
  * @param updates - Partial entry with fields to update
379
530
  * @returns The updated entry or undefined if not found
380
531
  */
381
- updateEntry(id: string, updates: Partial<Omit<AgentHistoryEntry, "id" | "timestamp">>): Promise<AgentHistoryEntry | undefined>;
532
+ updateEntry(id: string, updates: Partial<Omit<AgentHistoryEntry, "id" | "timestamp"> & {
533
+ agent_snapshot?: Record<string, unknown>;
534
+ }>): Promise<AgentHistoryEntry | undefined>;
382
535
  /**
383
536
  * Get a tracked event by ID
384
537
  *
@@ -397,18 +550,10 @@ declare class HistoryManager {
397
550
  */
398
551
  updateTrackedEvent(historyId: string, eventId: string, updates: {
399
552
  status?: AgentStatus;
400
- data?: Record<string, any>;
553
+ data?: Record<string, unknown>;
401
554
  }): Promise<AgentHistoryEntry | undefined>;
402
555
  }
403
556
 
404
- /**
405
- * Types for tracked event functionality
406
- */
407
- type EventUpdater = (updateOptions: {
408
- status?: AgentStatus;
409
- data?: Record<string, any>;
410
- }) => Promise<AgentHistoryEntry | undefined>;
411
-
412
557
  /**
413
558
  * Provider options type for LLM configurations
414
559
  */
@@ -461,6 +606,11 @@ type AgentOptions = {
461
606
  * Optional user-defined context to be passed around
462
607
  */
463
608
  userContext?: Map<string | symbol, unknown>;
609
+ /**
610
+ * Telemetry exporter for the agent
611
+ * Used to send telemetry data to an external service
612
+ */
613
+ telemetryExporter?: VoltAgentExporter;
464
614
  } & ({
465
615
  /**
466
616
  * @deprecated Use `instructions` instead.
@@ -2093,6 +2243,7 @@ declare class Agent<TProvider extends {
2093
2243
  retriever?: BaseRetriever;
2094
2244
  voice?: Voice;
2095
2245
  markdown?: boolean;
2246
+ telemetryExporter?: VoltAgentExporter;
2096
2247
  });
2097
2248
  /**
2098
2249
  * Get the system message for the agent
@@ -2241,6 +2392,11 @@ declare class Agent<TProvider extends {
2241
2392
  * @returns The history manager instance
2242
2393
  */
2243
2394
  getHistoryManager(): HistoryManager;
2395
+ /**
2396
+ * Checks if telemetry (VoltAgentExporter) is configured for this agent.
2397
+ * @returns True if telemetry is configured, false otherwise.
2398
+ */
2399
+ isTelemetryConfigured(): boolean;
2244
2400
  /**
2245
2401
  * Add one or more tools or toolkits to the agent.
2246
2402
  * Delegates to ToolManager's addItems method.
@@ -2249,6 +2405,12 @@ declare class Agent<TProvider extends {
2249
2405
  addItems(items: (Tool<any> | Toolkit)[]): {
2250
2406
  added: (Tool<any> | Toolkit)[];
2251
2407
  };
2408
+ /**
2409
+ * @internal
2410
+ * Internal method to set the VoltAgentExporter on the agent's HistoryManager.
2411
+ * This is typically called by the main VoltAgent instance after it has initialized its exporter.
2412
+ */
2413
+ _INTERNAL_setVoltAgentExporter(exporter: VoltAgentExporter): void;
2252
2414
  }
2253
2415
 
2254
2416
  /**
@@ -2278,9 +2440,9 @@ declare const ReasoningStepSchema: z.ZodObject<{
2278
2440
  id: string;
2279
2441
  title: string;
2280
2442
  type: "thought" | "analysis";
2443
+ timestamp: string;
2281
2444
  historyEntryId: string;
2282
2445
  agentId: string;
2283
- timestamp: string;
2284
2446
  reasoning: string;
2285
2447
  confidence: number;
2286
2448
  action?: string | undefined;
@@ -2290,9 +2452,9 @@ declare const ReasoningStepSchema: z.ZodObject<{
2290
2452
  id: string;
2291
2453
  title: string;
2292
2454
  type: "thought" | "analysis";
2455
+ timestamp: string;
2293
2456
  historyEntryId: string;
2294
2457
  agentId: string;
2295
- timestamp: string;
2296
2458
  reasoning: string;
2297
2459
  action?: string | undefined;
2298
2460
  result?: string | undefined;
@@ -2871,6 +3033,7 @@ declare class AgentRegistry {
2871
3033
  private static instance;
2872
3034
  private agents;
2873
3035
  private isInitialized;
3036
+ private globalVoltAgentExporter?;
2874
3037
  /**
2875
3038
  * Track parent-child relationships between agents (child -> parents)
2876
3039
  */
@@ -2931,6 +3094,15 @@ declare class AgentRegistry {
2931
3094
  * Check if registry is initialized
2932
3095
  */
2933
3096
  isRegistryInitialized(): boolean;
3097
+ /**
3098
+ * Set the global VoltAgentExporter instance.
3099
+ * This is typically called by the main VoltAgent instance.
3100
+ */
3101
+ setGlobalVoltAgentExporter(exporter: VoltAgentExporter): void;
3102
+ /**
3103
+ * Get the global VoltAgentExporter instance.
3104
+ */
3105
+ getGlobalVoltAgentExporter(): VoltAgentExporter | undefined;
2934
3106
  }
2935
3107
 
2936
3108
  type VoltAgentOptions = {
@@ -2939,12 +3111,13 @@ type VoltAgentOptions = {
2939
3111
  autoStart?: boolean;
2940
3112
  checkDependencies?: boolean;
2941
3113
  /**
2942
- * Optional OpenTelemetry SpanExporter instance or array of instances.
3114
+ * Optional OpenTelemetry SpanExporter instance or array of instances,
3115
+ * or a VoltAgentExporter instance or array of instances.
2943
3116
  * If provided, VoltAgent will attempt to initialize and register
2944
3117
  * a NodeTracerProvider with a BatchSpanProcessor for the given exporter(s).
2945
3118
  * It's recommended to only provide this in one VoltAgent instance per application process.
2946
3119
  */
2947
- telemetryExporter?: SpanExporter | SpanExporter[];
3120
+ telemetryExporter?: (SpanExporter | VoltAgentExporter) | (SpanExporter | VoltAgentExporter)[];
2948
3121
  };
2949
3122
  /**
2950
3123
  * Main VoltAgent class for managing agents and server
@@ -2985,4 +3158,4 @@ declare class VoltAgent {
2985
3158
  shutdownTelemetry(): Promise<void>;
2986
3159
  }
2987
3160
 
2988
- export { Agent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentTool, AllowedVariableValue, AnyToolConfig, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTool, BaseToolCall, ClientInfo, Conversation, CreateConversationInput, CreateReasoningToolsOptions, DEFAULT_INSTRUCTIONS, DataContent, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryManager, MemoryMessage, MemoryOptions, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NextAction, NodeType, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptCreator, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningToolExecuteOptions, Retriever, RetrieverOptions, RetryConfig, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, TemplateVariables, TextPart, Tool, ToolCall, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolSchema, ToolStatus, ToolStatusInfo, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, checkForUpdates, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createTool, VoltAgent as default, getNodeTypeFromNodeId, serializeValueForDebug, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };
3161
+ export { Agent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentTool, AllowedVariableValue, AnyToolConfig, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTool, BaseToolCall, ClientInfo, Conversation, CreateConversationInput, CreateReasoningToolsOptions, DEFAULT_INSTRUCTIONS, DataContent, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryManager, MemoryMessage, MemoryOptions, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NextAction, NodeType, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptCreator, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningToolExecuteOptions, Retriever, RetrieverOptions, RetryConfig, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, TemplateVariables, TextPart, Tool, ToolCall, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolSchema, ToolStatus, ToolStatusInfo, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, checkForUpdates, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, serializeValueForDebug, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };