@voltagent/core 0.1.18 → 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
@@ -214,6 +214,131 @@ declare const createTool: <T extends ToolSchema>(options: ToolOptions<T>) => Too
214
214
  */
215
215
  declare const tool: <T extends ToolSchema>(options: ToolOptions<T>) => Tool<T>;
216
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
+
217
342
  /**
218
343
  * Step information for history
219
344
  */
@@ -221,7 +346,7 @@ interface HistoryStep {
221
346
  type: "message" | "tool_call" | "tool_result" | "text";
222
347
  name?: string;
223
348
  content?: string;
224
- arguments?: Record<string, any>;
349
+ arguments?: Record<string, unknown>;
225
350
  }
226
351
  /**
227
352
  * Timeline event for detailed history
@@ -234,7 +359,7 @@ interface TimelineEvent {
234
359
  /**
235
360
  * Timestamp when the event occurred
236
361
  */
237
- timestamp: Date;
362
+ timestamp: string;
238
363
  /**
239
364
  * Name of the event (e.g., "generating", "tool_calling", "tool_result", etc.)
240
365
  * In the new format, "componentName:operationName" style (e.g.: "memory:getMessages")
@@ -249,11 +374,11 @@ interface TimelineEvent {
249
374
  * Optional additional data specific to the event type
250
375
  * In the new format: { status, input, output, updatedAt etc. }
251
376
  */
252
- data?: Record<string, any>;
377
+ data?: Record<string, unknown>;
253
378
  /**
254
379
  * Optional timestamp for when the event was last updated
255
380
  */
256
- updatedAt?: Date;
381
+ updatedAt?: string;
257
382
  /**
258
383
  * Type of the event
259
384
  */
@@ -274,7 +399,7 @@ interface AgentHistoryEntry {
274
399
  /**
275
400
  * Original input to the agent
276
401
  */
277
- input: string | Record<string, any> | BaseMessage[];
402
+ input: string | Record<string, unknown> | BaseMessage[];
278
403
  /**
279
404
  * Final output from the agent
280
405
  */
@@ -317,18 +442,33 @@ declare class HistoryManager {
317
442
  * Memory manager for storing history entries
318
443
  */
319
444
  private memoryManager;
445
+ /**
446
+ * Optional VoltAgentExporter for sending telemetry data.
447
+ */
448
+ private voltAgentExporter?;
320
449
  /**
321
450
  * Create a new history manager
322
451
  *
323
- * @param maxEntries - Maximum number of history entries to keep (0 = unlimited)
324
- * @param agentId - Agent ID for emitting events
452
+ * @param agentId - Agent ID for emitting events and for storage
325
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
326
456
  */
327
- constructor(maxEntries: number | undefined, agentId: string, memoryManager: MemoryManager);
457
+ constructor(agentId: string, memoryManager: MemoryManager, maxEntries?: number, voltAgentExporter?: VoltAgentExporter);
328
458
  /**
329
459
  * Set the agent ID for this history manager
330
460
  */
331
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;
332
472
  /**
333
473
  * Add a new history entry
334
474
  *
@@ -337,9 +477,12 @@ declare class HistoryManager {
337
477
  * @param status - Status of the entry
338
478
  * @param steps - Steps taken during generation
339
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
340
483
  * @returns The new history entry
341
484
  */
342
- 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>;
343
486
  /**
344
487
  * Add a timeline event to an existing history entry
345
488
  *
@@ -386,7 +529,9 @@ declare class HistoryManager {
386
529
  * @param updates - Partial entry with fields to update
387
530
  * @returns The updated entry or undefined if not found
388
531
  */
389
- 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>;
390
535
  /**
391
536
  * Get a tracked event by ID
392
537
  *
@@ -405,18 +550,10 @@ declare class HistoryManager {
405
550
  */
406
551
  updateTrackedEvent(historyId: string, eventId: string, updates: {
407
552
  status?: AgentStatus;
408
- data?: Record<string, any>;
553
+ data?: Record<string, unknown>;
409
554
  }): Promise<AgentHistoryEntry | undefined>;
410
555
  }
411
556
 
412
- /**
413
- * Types for tracked event functionality
414
- */
415
- type EventUpdater = (updateOptions: {
416
- status?: AgentStatus;
417
- data?: Record<string, any>;
418
- }) => Promise<AgentHistoryEntry | undefined>;
419
-
420
557
  /**
421
558
  * Provider options type for LLM configurations
422
559
  */
@@ -469,6 +606,11 @@ type AgentOptions = {
469
606
  * Optional user-defined context to be passed around
470
607
  */
471
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;
472
614
  } & ({
473
615
  /**
474
616
  * @deprecated Use `instructions` instead.
@@ -2101,6 +2243,7 @@ declare class Agent<TProvider extends {
2101
2243
  retriever?: BaseRetriever;
2102
2244
  voice?: Voice;
2103
2245
  markdown?: boolean;
2246
+ telemetryExporter?: VoltAgentExporter;
2104
2247
  });
2105
2248
  /**
2106
2249
  * Get the system message for the agent
@@ -2249,6 +2392,11 @@ declare class Agent<TProvider extends {
2249
2392
  * @returns The history manager instance
2250
2393
  */
2251
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;
2252
2400
  /**
2253
2401
  * Add one or more tools or toolkits to the agent.
2254
2402
  * Delegates to ToolManager's addItems method.
@@ -2257,6 +2405,12 @@ declare class Agent<TProvider extends {
2257
2405
  addItems(items: (Tool<any> | Toolkit)[]): {
2258
2406
  added: (Tool<any> | Toolkit)[];
2259
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;
2260
2414
  }
2261
2415
 
2262
2416
  /**
@@ -2286,9 +2440,9 @@ declare const ReasoningStepSchema: z.ZodObject<{
2286
2440
  id: string;
2287
2441
  title: string;
2288
2442
  type: "thought" | "analysis";
2443
+ timestamp: string;
2289
2444
  historyEntryId: string;
2290
2445
  agentId: string;
2291
- timestamp: string;
2292
2446
  reasoning: string;
2293
2447
  confidence: number;
2294
2448
  action?: string | undefined;
@@ -2298,9 +2452,9 @@ declare const ReasoningStepSchema: z.ZodObject<{
2298
2452
  id: string;
2299
2453
  title: string;
2300
2454
  type: "thought" | "analysis";
2455
+ timestamp: string;
2301
2456
  historyEntryId: string;
2302
2457
  agentId: string;
2303
- timestamp: string;
2304
2458
  reasoning: string;
2305
2459
  action?: string | undefined;
2306
2460
  result?: string | undefined;
@@ -2879,6 +3033,7 @@ declare class AgentRegistry {
2879
3033
  private static instance;
2880
3034
  private agents;
2881
3035
  private isInitialized;
3036
+ private globalVoltAgentExporter?;
2882
3037
  /**
2883
3038
  * Track parent-child relationships between agents (child -> parents)
2884
3039
  */
@@ -2939,6 +3094,15 @@ declare class AgentRegistry {
2939
3094
  * Check if registry is initialized
2940
3095
  */
2941
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;
2942
3106
  }
2943
3107
 
2944
3108
  type VoltAgentOptions = {
@@ -2947,12 +3111,13 @@ type VoltAgentOptions = {
2947
3111
  autoStart?: boolean;
2948
3112
  checkDependencies?: boolean;
2949
3113
  /**
2950
- * 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.
2951
3116
  * If provided, VoltAgent will attempt to initialize and register
2952
3117
  * a NodeTracerProvider with a BatchSpanProcessor for the given exporter(s).
2953
3118
  * It's recommended to only provide this in one VoltAgent instance per application process.
2954
3119
  */
2955
- telemetryExporter?: SpanExporter | SpanExporter[];
3120
+ telemetryExporter?: (SpanExporter | VoltAgentExporter) | (SpanExporter | VoltAgentExporter)[];
2956
3121
  };
2957
3122
  /**
2958
3123
  * Main VoltAgent class for managing agents and server
@@ -2993,4 +3158,4 @@ declare class VoltAgent {
2993
3158
  shutdownTelemetry(): Promise<void>;
2994
3159
  }
2995
3160
 
2996
- 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, createToolkit, 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 };