@voltagent/core 2.6.11 → 2.6.12

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.js CHANGED
@@ -287,7 +287,7 @@ __export(index_exports, {
287
287
  context: () => import_api9.context,
288
288
  convertUsage: () => convertUsage,
289
289
  cosineSimilarity: () => cosineSimilarity,
290
- createAsyncIterableStream: () => import_utils40.createAsyncIterableStream,
290
+ createAsyncIterableStream: () => import_utils41.createAsyncIterableStream,
291
291
  createDefaultInputSafetyGuardrails: () => createDefaultInputSafetyGuardrails,
292
292
  createDefaultPIIGuardrails: () => createDefaultPIIGuardrails,
293
293
  createDefaultSafetyGuardrails: () => createDefaultSafetyGuardrails,
@@ -12693,7 +12693,7 @@ __name(createWorkflowChain, "createWorkflowChain");
12693
12693
  // src/agent/agent.ts
12694
12694
  var import_node_util = require("util");
12695
12695
  var import_api16 = require("@opentelemetry/api");
12696
- var import_utils33 = require("@voltagent/internal/utils");
12696
+ var import_utils34 = require("@voltagent/internal/utils");
12697
12697
  var import_ai7 = require("ai");
12698
12698
  var import_zod7 = require("zod");
12699
12699
 
@@ -26521,6 +26521,172 @@ function addModelAttributesToSpan(span, modelName, options, defaultMaxOutputToke
26521
26521
  }
26522
26522
  __name(addModelAttributesToSpan, "addModelAttributesToSpan");
26523
26523
 
26524
+ // src/agent/prompt-context-usage.ts
26525
+ var import_utils29 = require("@voltagent/internal/utils");
26526
+ var ESTIMATED_CHARS_PER_TOKEN = 4;
26527
+ var BINARY_PART_TYPES = /* @__PURE__ */ new Set([
26528
+ "audio",
26529
+ "file",
26530
+ "image",
26531
+ "input_audio",
26532
+ "input_image",
26533
+ "media"
26534
+ ]);
26535
+ var LARGE_BINARY_KEYS = /* @__PURE__ */ new Set(["audio", "base64", "bytes", "data", "image"]);
26536
+ function estimatePromptContextUsage(params) {
26537
+ let systemTokensEstimated = 0;
26538
+ let messageTokensEstimated = 0;
26539
+ let nonSystemMessageTokensEstimated = 0;
26540
+ let systemMessageCount = 0;
26541
+ for (const message of params.messages ?? []) {
26542
+ const serializedMessage = serializePromptMessage(message);
26543
+ if (!serializedMessage) {
26544
+ continue;
26545
+ }
26546
+ const estimatedTokens = estimateTokensFromText(serializedMessage);
26547
+ messageTokensEstimated += estimatedTokens;
26548
+ if (message.role === "system") {
26549
+ systemTokensEstimated += estimatedTokens;
26550
+ systemMessageCount += 1;
26551
+ continue;
26552
+ }
26553
+ nonSystemMessageTokensEstimated += estimatedTokens;
26554
+ }
26555
+ const serializedTools = Object.entries(params.tools ?? {}).map(
26556
+ ([name, tool2]) => serializeToolDefinition(name, tool2)
26557
+ );
26558
+ const toolTokensEstimated = serializedTools.length > 0 ? estimateTokensFromText((0, import_utils29.safeStringify)(serializedTools)) : 0;
26559
+ const totalTokensEstimated = messageTokensEstimated + toolTokensEstimated;
26560
+ if (totalTokensEstimated === 0) {
26561
+ return void 0;
26562
+ }
26563
+ return {
26564
+ systemTokensEstimated,
26565
+ messageTokensEstimated,
26566
+ nonSystemMessageTokensEstimated,
26567
+ toolTokensEstimated,
26568
+ totalTokensEstimated,
26569
+ systemMessageCount,
26570
+ toolCount: serializedTools.length
26571
+ };
26572
+ }
26573
+ __name(estimatePromptContextUsage, "estimatePromptContextUsage");
26574
+ function promptContextUsageEstimateToAttributes(estimate) {
26575
+ return {
26576
+ "usage.prompt_context.system_tokens_estimated": estimate.systemTokensEstimated,
26577
+ "usage.prompt_context.message_tokens_estimated": estimate.messageTokensEstimated,
26578
+ "usage.prompt_context.non_system_message_tokens_estimated": estimate.nonSystemMessageTokensEstimated,
26579
+ "usage.prompt_context.tool_tokens_estimated": estimate.toolTokensEstimated,
26580
+ "usage.prompt_context.total_tokens_estimated": estimate.totalTokensEstimated,
26581
+ "usage.prompt_context.system_message_count": estimate.systemMessageCount,
26582
+ "usage.prompt_context.tool_count": estimate.toolCount
26583
+ };
26584
+ }
26585
+ __name(promptContextUsageEstimateToAttributes, "promptContextUsageEstimateToAttributes");
26586
+ function estimateTokensFromText(text) {
26587
+ if (!text) {
26588
+ return 0;
26589
+ }
26590
+ return Math.ceil(text.length / ESTIMATED_CHARS_PER_TOKEN);
26591
+ }
26592
+ __name(estimateTokensFromText, "estimateTokensFromText");
26593
+ function serializePromptMessage(message) {
26594
+ const content = serializePromptValue(message.content).trim();
26595
+ if (!content) {
26596
+ return "";
26597
+ }
26598
+ const role = typeof message.role === "string" ? message.role.toUpperCase() : "MESSAGE";
26599
+ return `${role}:
26600
+ ${content}`;
26601
+ }
26602
+ __name(serializePromptMessage, "serializePromptMessage");
26603
+ function serializePromptValue(value) {
26604
+ if (typeof value === "string") {
26605
+ return value;
26606
+ }
26607
+ if (typeof value === "number" || typeof value === "boolean") {
26608
+ return String(value);
26609
+ }
26610
+ if (Array.isArray(value)) {
26611
+ return value.map((entry) => serializePromptValue(entry)).filter((entry) => entry.trim().length > 0).join("\n");
26612
+ }
26613
+ if (!value || typeof value !== "object") {
26614
+ return "";
26615
+ }
26616
+ const record = value;
26617
+ const type = typeof record.type === "string" ? record.type : void 0;
26618
+ if (typeof record.text === "string") {
26619
+ return record.text;
26620
+ }
26621
+ if (type && BINARY_PART_TYPES.has(type)) {
26622
+ return `[${type}]`;
26623
+ }
26624
+ if (type === "tool-call") {
26625
+ const toolName = typeof record.toolName === "string" ? record.toolName : "tool";
26626
+ const input = serializePromptValue(record.input);
26627
+ return input ? `tool-call ${toolName}: ${input}` : `tool-call ${toolName}`;
26628
+ }
26629
+ if (type === "tool-result") {
26630
+ const toolName = typeof record.toolName === "string" ? record.toolName : "tool";
26631
+ const output = serializePromptValue(record.output);
26632
+ return output ? `tool-result ${toolName}: ${output}` : `tool-result ${toolName}`;
26633
+ }
26634
+ if ("content" in record) {
26635
+ const nestedContent = serializePromptValue(record.content);
26636
+ if (nestedContent) {
26637
+ return nestedContent;
26638
+ }
26639
+ }
26640
+ return (0, import_utils29.safeStringify)(sanitizeRecord(record));
26641
+ }
26642
+ __name(serializePromptValue, "serializePromptValue");
26643
+ function sanitizeRecord(record) {
26644
+ const sanitized = {};
26645
+ for (const [key, value] of Object.entries(record)) {
26646
+ sanitized[key] = LARGE_BINARY_KEYS.has(key) ? "[omitted]" : value;
26647
+ }
26648
+ return sanitized;
26649
+ }
26650
+ __name(sanitizeRecord, "sanitizeRecord");
26651
+ function serializeToolDefinition(name, tool2) {
26652
+ if (!tool2 || typeof tool2 !== "object") {
26653
+ return { name };
26654
+ }
26655
+ const candidate = tool2;
26656
+ return {
26657
+ name,
26658
+ ...typeof candidate.type === "string" ? { type: candidate.type } : {},
26659
+ ...typeof candidate.id === "string" ? { id: candidate.id } : {},
26660
+ ...typeof candidate.description === "string" ? { description: candidate.description } : {},
26661
+ ...candidate.inputSchema || candidate.parameters || candidate.input_schema || candidate.schema ? {
26662
+ inputSchema: normalizeSchema(
26663
+ candidate.inputSchema ?? candidate.parameters ?? candidate.input_schema ?? candidate.schema
26664
+ )
26665
+ } : {},
26666
+ ...candidate.outputSchema || candidate.output_schema ? {
26667
+ outputSchema: normalizeSchema(candidate.outputSchema ?? candidate.output_schema)
26668
+ } : {},
26669
+ ...candidate.providerOptions ? { providerOptions: candidate.providerOptions } : {},
26670
+ ...candidate.args ? { args: sanitizeRecord(candidate.args) } : {},
26671
+ ...candidate.needsApproval !== void 0 ? { needsApproval: candidate.needsApproval } : {}
26672
+ };
26673
+ }
26674
+ __name(serializeToolDefinition, "serializeToolDefinition");
26675
+ function normalizeSchema(schema) {
26676
+ if (!schema || typeof schema !== "object") {
26677
+ return schema;
26678
+ }
26679
+ try {
26680
+ if ("_def" in schema) {
26681
+ return zodSchemaToJsonUI(schema);
26682
+ }
26683
+ } catch (_error) {
26684
+ return schema;
26685
+ }
26686
+ return schema;
26687
+ }
26688
+ __name(normalizeSchema, "normalizeSchema");
26689
+
26524
26690
  // src/agent/tool-input-coercion.ts
26525
26691
  var isPathSegment = /* @__PURE__ */ __name((value) => typeof value === "string" || typeof value === "number", "isPathSegment");
26526
26692
  var isRecord2 = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isRecord");
@@ -26639,7 +26805,7 @@ var coerceStringifiedJsonToolArgs = /* @__PURE__ */ __name((rawArgs, issues) =>
26639
26805
  var import_ts_pattern2 = require("ts-pattern");
26640
26806
 
26641
26807
  // src/agent/apply-summarization.ts
26642
- var import_utils29 = require("@voltagent/internal/utils");
26808
+ var import_utils30 = require("@voltagent/internal/utils");
26643
26809
  var import_ai5 = require("ai");
26644
26810
  var SUMMARY_METADATA_KEY = "agent";
26645
26811
  var SUMMARY_STATE_CACHE_KEY = Symbol("agentSummaryState");
@@ -26752,7 +26918,7 @@ var applySummarization = /* @__PURE__ */ __name(async ({
26752
26918
  }
26753
26919
  } catch (error) {
26754
26920
  oc.logger.debug("[Agent] Failed to summarize conversation", {
26755
- error: (0, import_utils29.safeStringify)(error)
26921
+ error: (0, import_utils30.safeStringify)(error)
26756
26922
  });
26757
26923
  if (summarySpan) {
26758
26924
  oc.traceContext.endChildSpan(summarySpan, "error", {
@@ -26835,7 +27001,7 @@ async function loadAgentSummaryState(agent, context8) {
26835
27001
  state = readSummaryStateFromMetadata(conversation?.metadata);
26836
27002
  } catch (error) {
26837
27003
  context8.logger.debug("[Agent] Failed to load summary state from memory", {
26838
- error: (0, import_utils29.safeStringify)(error)
27004
+ error: (0, import_utils30.safeStringify)(error)
26839
27005
  });
26840
27006
  }
26841
27007
  }
@@ -26865,7 +27031,7 @@ async function updateAgentSummaryState(agent, context8, updater) {
26865
27031
  }
26866
27032
  } catch (error) {
26867
27033
  context8.logger.debug("[Agent] Failed to persist summary state", {
26868
- error: (0, import_utils29.safeStringify)(error)
27034
+ error: (0, import_utils30.safeStringify)(error)
26869
27035
  });
26870
27036
  }
26871
27037
  }
@@ -26898,11 +27064,11 @@ function removeSystemMessagesWithMarker(messages, marker) {
26898
27064
  });
26899
27065
  }
26900
27066
  __name(removeSystemMessagesWithMarker, "removeSystemMessagesWithMarker");
26901
- function estimateTokensFromText(text) {
27067
+ function estimateTokensFromText2(text) {
26902
27068
  if (!text) return 0;
26903
27069
  return Math.ceil(text.length / SUMMARY_CHAR_PER_TOKEN);
26904
27070
  }
26905
- __name(estimateTokensFromText, "estimateTokensFromText");
27071
+ __name(estimateTokensFromText2, "estimateTokensFromText");
26906
27072
  function summarizePartValue(value) {
26907
27073
  if (typeof value === "string") {
26908
27074
  return truncateText2(value, SUMMARY_MAX_PART_CHARS);
@@ -26910,7 +27076,7 @@ function summarizePartValue(value) {
26910
27076
  if (value === null || value === void 0) {
26911
27077
  return "";
26912
27078
  }
26913
- return truncateText2((0, import_utils29.safeStringify)(value), SUMMARY_MAX_PART_CHARS);
27079
+ return truncateText2((0, import_utils30.safeStringify)(value), SUMMARY_MAX_PART_CHARS);
26914
27080
  }
26915
27081
  __name(summarizePartValue, "summarizePartValue");
26916
27082
  function extractSummaryText(message) {
@@ -26965,7 +27131,7 @@ function estimateTokensFromMessages(messages) {
26965
27131
  for (const message of messages) {
26966
27132
  const formatted = formatMessageForSummary(message);
26967
27133
  if (formatted) {
26968
- total += estimateTokensFromText(formatted);
27134
+ total += estimateTokensFromText2(formatted);
26969
27135
  }
26970
27136
  }
26971
27137
  return total;
@@ -28412,7 +28578,7 @@ var collapseRedundantStepStarts = /* @__PURE__ */ __name((parts) => {
28412
28578
 
28413
28579
  // src/agent/middleware.ts
28414
28580
  var import_api13 = require("@opentelemetry/api");
28415
- var import_utils30 = require("@voltagent/internal/utils");
28581
+ var import_utils31 = require("@voltagent/internal/utils");
28416
28582
  function createInputMiddleware(options) {
28417
28583
  return {
28418
28584
  id: options.id,
@@ -28491,7 +28657,7 @@ function serializeMiddlewareValue(value) {
28491
28657
  if (typeof value === "string") {
28492
28658
  return value;
28493
28659
  }
28494
- return (0, import_utils30.safeStringify)(value);
28660
+ return (0, import_utils31.safeStringify)(value);
28495
28661
  }
28496
28662
  __name(serializeMiddlewareValue, "serializeMiddlewareValue");
28497
28663
  async function runInputMiddlewares(input, oc, middlewares, operation, agent, retryCount) {
@@ -28515,8 +28681,8 @@ async function runInputMiddlewares(input, oc, middlewares, operation, agent, ret
28515
28681
  ...middleware.id ? { "middleware.id": middleware.id } : {},
28516
28682
  "middleware.name": middleware.name,
28517
28683
  ...middleware.description ? { "middleware.description": middleware.description } : {},
28518
- ...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0, import_utils30.safeStringify)(middleware.tags) } : {},
28519
- ...middleware.metadata ? { "middleware.metadata": (0, import_utils30.safeStringify)(middleware.metadata) } : {},
28684
+ ...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0, import_utils31.safeStringify)(middleware.tags) } : {},
28685
+ ...middleware.metadata ? { "middleware.metadata": (0, import_utils31.safeStringify)(middleware.metadata) } : {},
28520
28686
  "middleware.retry_count": retryCount,
28521
28687
  "middleware.input.original": serializeMiddlewareValue(originalInput),
28522
28688
  "middleware.input.current": serializeMiddlewareValue(currentInput)
@@ -28584,8 +28750,8 @@ async function runOutputMiddlewares(output, oc, middlewares, operation, agent, r
28584
28750
  ...middleware.id ? { "middleware.id": middleware.id } : {},
28585
28751
  "middleware.name": middleware.name,
28586
28752
  ...middleware.description ? { "middleware.description": middleware.description } : {},
28587
- ...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0, import_utils30.safeStringify)(middleware.tags) } : {},
28588
- ...middleware.metadata ? { "middleware.metadata": (0, import_utils30.safeStringify)(middleware.metadata) } : {},
28753
+ ...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0, import_utils31.safeStringify)(middleware.tags) } : {},
28754
+ ...middleware.metadata ? { "middleware.metadata": (0, import_utils31.safeStringify)(middleware.metadata) } : {},
28589
28755
  "middleware.retry_count": retryCount,
28590
28756
  "middleware.output.original": serializeMiddlewareValue(originalOutput),
28591
28757
  "middleware.output.current": serializeMiddlewareValue(currentOutput)
@@ -28593,13 +28759,13 @@ async function runOutputMiddlewares(output, oc, middlewares, operation, agent, r
28593
28759
  }
28594
28760
  );
28595
28761
  if (metadata?.usage !== void 0) {
28596
- span.setAttribute("middleware.usage", (0, import_utils30.safeStringify)(metadata.usage));
28762
+ span.setAttribute("middleware.usage", (0, import_utils31.safeStringify)(metadata.usage));
28597
28763
  }
28598
28764
  if (metadata?.finishReason !== void 0 && metadata.finishReason !== null) {
28599
28765
  span.setAttribute("middleware.finish_reason", metadata.finishReason);
28600
28766
  }
28601
28767
  if (metadata?.warnings && metadata.warnings.length > 0) {
28602
- span.setAttribute("middleware.warnings", (0, import_utils30.safeStringify)(metadata.warnings));
28768
+ span.setAttribute("middleware.warnings", (0, import_utils31.safeStringify)(metadata.warnings));
28603
28769
  }
28604
28770
  try {
28605
28771
  const abort = /* @__PURE__ */ __name((reason, options) => {
@@ -28647,7 +28813,7 @@ var import_ai6 = require("ai");
28647
28813
 
28648
28814
  // src/agent/streaming/output-guardrail-stream-runner.ts
28649
28815
  var import_api14 = require("@opentelemetry/api");
28650
- var import_utils31 = require("@voltagent/internal/utils");
28816
+ var import_utils32 = require("@voltagent/internal/utils");
28651
28817
  var isTextDelta = /* @__PURE__ */ __name((part) => part.type === "text-delta", "isTextDelta");
28652
28818
  var extractChunkText = /* @__PURE__ */ __name((part) => {
28653
28819
  if (!isTextDelta(part)) {
@@ -28902,8 +29068,8 @@ var OutputGuardrailStreamRunner = class {
28902
29068
  "guardrail.name": guardrail.name,
28903
29069
  ...guardrail.description ? { "guardrail.description": guardrail.description } : {},
28904
29070
  ...guardrail.severity ? { "guardrail.severity": guardrail.severity } : {},
28905
- ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils31.safeStringify)(guardrail.tags) } : {},
28906
- ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils31.safeStringify)(guardrail.metadata) } : {}
29071
+ ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils32.safeStringify)(guardrail.tags) } : {},
29072
+ ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils32.safeStringify)(guardrail.metadata) } : {}
28907
29073
  }
28908
29074
  }
28909
29075
  );
@@ -29431,7 +29597,7 @@ __name(convertFullStreamChunkToUIMessageStream, "convertFullStreamChunkToUIMessa
29431
29597
 
29432
29598
  // src/agent/subagent/index.ts
29433
29599
  var import_api15 = require("@opentelemetry/api");
29434
- var import_utils32 = require("@voltagent/internal/utils");
29600
+ var import_utils33 = require("@voltagent/internal/utils");
29435
29601
  var import_zod6 = require("zod");
29436
29602
 
29437
29603
  // src/agent/subagent/types.ts
@@ -29737,7 +29903,7 @@ ${guidelinesText}
29737
29903
  taskContent = `Task handed off from ${sourceAgent?.name || this.agentName} to ${targetAgent.name}:
29738
29904
  ${task}
29739
29905
 
29740
- Context: ${(0, import_utils32.safeStringify)(contextObj, { indentation: 2 })}`;
29906
+ Context: ${(0, import_utils33.safeStringify)(contextObj, { indentation: 2 })}`;
29741
29907
  }
29742
29908
  const taskMessage = {
29743
29909
  id: crypto.randomUUID(),
@@ -29795,7 +29961,7 @@ Context: ${(0, import_utils32.safeStringify)(contextObj, { indentation: 2 })}`;
29795
29961
  options2
29796
29962
  );
29797
29963
  const finalObject = await response.object;
29798
- finalResult = (0, import_utils32.safeStringify)(finalObject);
29964
+ finalResult = (0, import_utils33.safeStringify)(finalObject);
29799
29965
  finalMessages = [taskMessage, this.createAssistantMessage(finalResult)];
29800
29966
  } else if (this.isGenerateObjectConfig(targetAgentConfig)) {
29801
29967
  const options2 = { ...baseOptions, ...targetAgentConfig.options };
@@ -29804,7 +29970,7 @@ Context: ${(0, import_utils32.safeStringify)(contextObj, { indentation: 2 })}`;
29804
29970
  targetAgentConfig.schema,
29805
29971
  options2
29806
29972
  );
29807
- finalResult = (0, import_utils32.safeStringify)(response);
29973
+ finalResult = (0, import_utils33.safeStringify)(response);
29808
29974
  usage = response.usage;
29809
29975
  finalMessages = [taskMessage, this.createAssistantMessage(finalResult)];
29810
29976
  } else {
@@ -30709,12 +30875,12 @@ var Agent = class {
30709
30875
  );
30710
30876
  const contextMap = Object.fromEntries(oc.context.entries());
30711
30877
  if (Object.keys(contextMap).length > 0) {
30712
- rootSpan.setAttribute("agent.context", (0, import_utils33.safeStringify)(contextMap));
30878
+ rootSpan.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
30713
30879
  }
30714
- rootSpan.setAttribute("agent.messages", (0, import_utils33.safeStringify)(messages));
30715
- rootSpan.setAttribute("agent.messages.ui", (0, import_utils33.safeStringify)(uiMessages));
30880
+ rootSpan.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
30881
+ rootSpan.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
30716
30882
  const agentState = this.getFullState();
30717
- rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils33.safeStringify)(agentState));
30883
+ rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
30718
30884
  methodLogger.debug(
30719
30885
  buildAgentLogMessage(
30720
30886
  this.name,
@@ -30935,7 +31101,7 @@ var Agent = class {
30935
31101
  operation: "generateText",
30936
31102
  metadata: {
30937
31103
  finishReason: result.finishReason,
30938
- usage: usageForFinish ? JSON.parse((0, import_utils33.safeStringify)(usageForFinish)) : void 0,
31104
+ usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
30939
31105
  toolCalls: aggregatedToolCalls
30940
31106
  }
30941
31107
  });
@@ -31002,7 +31168,7 @@ var Agent = class {
31002
31168
  maxMiddlewareRetries,
31003
31169
  middlewareId: retryError.middlewareId ?? null,
31004
31170
  reason: retryError.message ?? "middleware retry",
31005
- metadata: retryError.metadata !== void 0 ? (0, import_utils33.safeStringify)(retryError.metadata) : void 0
31171
+ metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
31006
31172
  });
31007
31173
  this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
31008
31174
  middlewareRetryCount += 1;
@@ -31183,7 +31349,7 @@ var Agent = class {
31183
31349
  maxMiddlewareRetries,
31184
31350
  middlewareId: retryError.middlewareId ?? null,
31185
31351
  reason: retryError.message ?? "middleware retry",
31186
- metadata: retryError.metadata !== void 0 ? (0, import_utils33.safeStringify)(retryError.metadata) : void 0
31352
+ metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
31187
31353
  });
31188
31354
  this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
31189
31355
  middlewareRetryCount += 1;
@@ -31217,12 +31383,12 @@ var Agent = class {
31217
31383
  );
31218
31384
  const contextMap = Object.fromEntries(oc.context.entries());
31219
31385
  if (Object.keys(contextMap).length > 0) {
31220
- rootSpan2.setAttribute("agent.context", (0, import_utils33.safeStringify)(contextMap));
31386
+ rootSpan2.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
31221
31387
  }
31222
- rootSpan2.setAttribute("agent.messages", (0, import_utils33.safeStringify)(messages));
31223
- rootSpan2.setAttribute("agent.messages.ui", (0, import_utils33.safeStringify)(uiMessages));
31388
+ rootSpan2.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
31389
+ rootSpan2.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
31224
31390
  const agentState = this.getFullState();
31225
- rootSpan2.setAttribute("agent.stateSnapshot", (0, import_utils33.safeStringify)(agentState));
31391
+ rootSpan2.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
31226
31392
  }
31227
31393
  methodLogger.debug(
31228
31394
  buildAgentLogMessage(
@@ -31504,7 +31670,7 @@ var Agent = class {
31504
31670
  operation: "streamText",
31505
31671
  metadata: {
31506
31672
  finishReason: finalResult.finishReason,
31507
- usage: usageForFinish ? JSON.parse((0, import_utils33.safeStringify)(usageForFinish)) : void 0,
31673
+ usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
31508
31674
  toolCalls: finalResult.toolCalls
31509
31675
  }
31510
31676
  });
@@ -31891,12 +32057,12 @@ var Agent = class {
31891
32057
  );
31892
32058
  const contextMap = Object.fromEntries(oc.context.entries());
31893
32059
  if (Object.keys(contextMap).length > 0) {
31894
- rootSpan.setAttribute("agent.context", (0, import_utils33.safeStringify)(contextMap));
32060
+ rootSpan.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
31895
32061
  }
31896
- rootSpan.setAttribute("agent.messages", (0, import_utils33.safeStringify)(messages));
31897
- rootSpan.setAttribute("agent.messages.ui", (0, import_utils33.safeStringify)(uiMessages));
32062
+ rootSpan.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
32063
+ rootSpan.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
31898
32064
  const agentState = this.getFullState();
31899
- rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils33.safeStringify)(agentState));
32065
+ rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
31900
32066
  methodLogger.debug(
31901
32067
  buildAgentLogMessage(
31902
32068
  this.name,
@@ -32005,7 +32171,7 @@ var Agent = class {
32005
32171
  parts: [
32006
32172
  {
32007
32173
  type: "text",
32008
- text: (0, import_utils33.safeStringify)(finalObject)
32174
+ text: (0, import_utils34.safeStringify)(finalObject)
32009
32175
  }
32010
32176
  ]
32011
32177
  };
@@ -32013,7 +32179,7 @@ var Agent = class {
32013
32179
  const step = {
32014
32180
  id: randomUUID(),
32015
32181
  type: "text",
32016
- content: (0, import_utils33.safeStringify)(finalObject),
32182
+ content: (0, import_utils34.safeStringify)(finalObject),
32017
32183
  role: "assistant",
32018
32184
  usage: usageInfo
32019
32185
  };
@@ -32027,7 +32193,7 @@ var Agent = class {
32027
32193
  operation: "generateObject",
32028
32194
  metadata: {
32029
32195
  finishReason: result.finishReason,
32030
- usage: usageForFinish ? JSON.parse((0, import_utils33.safeStringify)(usageForFinish)) : void 0,
32196
+ usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
32031
32197
  schemaName
32032
32198
  }
32033
32199
  });
@@ -32086,7 +32252,7 @@ var Agent = class {
32086
32252
  maxMiddlewareRetries,
32087
32253
  middlewareId: retryError.middlewareId ?? null,
32088
32254
  reason: retryError.message ?? "middleware retry",
32089
- metadata: retryError.metadata !== void 0 ? (0, import_utils33.safeStringify)(retryError.metadata) : void 0
32255
+ metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
32090
32256
  });
32091
32257
  this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
32092
32258
  middlewareRetryCount += 1;
@@ -32156,7 +32322,7 @@ var Agent = class {
32156
32322
  maxMiddlewareRetries,
32157
32323
  middlewareId: retryError.middlewareId ?? null,
32158
32324
  reason: retryError.message ?? "middleware retry",
32159
- metadata: retryError.metadata !== void 0 ? (0, import_utils33.safeStringify)(retryError.metadata) : void 0
32325
+ metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
32160
32326
  });
32161
32327
  this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
32162
32328
  middlewareRetryCount += 1;
@@ -32187,12 +32353,12 @@ var Agent = class {
32187
32353
  );
32188
32354
  const contextMap = Object.fromEntries(oc.context.entries());
32189
32355
  if (Object.keys(contextMap).length > 0) {
32190
- rootSpan.setAttribute("agent.context", (0, import_utils33.safeStringify)(contextMap));
32356
+ rootSpan.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
32191
32357
  }
32192
- rootSpan.setAttribute("agent.messages", (0, import_utils33.safeStringify)(messages));
32193
- rootSpan.setAttribute("agent.messages.ui", (0, import_utils33.safeStringify)(uiMessages));
32358
+ rootSpan.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
32359
+ rootSpan.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
32194
32360
  const agentState = this.getFullState();
32195
- rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils33.safeStringify)(agentState));
32361
+ rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
32196
32362
  methodLogger.debug(
32197
32363
  buildAgentLogMessage(
32198
32364
  this.name,
@@ -32355,7 +32521,7 @@ var Agent = class {
32355
32521
  parts: [
32356
32522
  {
32357
32523
  type: "text",
32358
- text: (0, import_utils33.safeStringify)(finalObject)
32524
+ text: (0, import_utils34.safeStringify)(finalObject)
32359
32525
  }
32360
32526
  ]
32361
32527
  };
@@ -32363,7 +32529,7 @@ var Agent = class {
32363
32529
  const step = {
32364
32530
  id: randomUUID(),
32365
32531
  type: "text",
32366
- content: (0, import_utils33.safeStringify)(finalObject),
32532
+ content: (0, import_utils34.safeStringify)(finalObject),
32367
32533
  role: "assistant",
32368
32534
  usage: usageInfo
32369
32535
  };
@@ -32410,7 +32576,7 @@ var Agent = class {
32410
32576
  operation: "streamObject",
32411
32577
  metadata: {
32412
32578
  finishReason: finalResult.finishReason,
32413
- usage: usageForFinish ? JSON.parse((0, import_utils33.safeStringify)(usageForFinish)) : void 0,
32579
+ usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
32414
32580
  schemaName
32415
32581
  }
32416
32582
  });
@@ -32529,7 +32695,7 @@ var Agent = class {
32529
32695
  let feedback = `[Middleware Feedback] ${baseReason} Please retry with the feedback in mind.`;
32530
32696
  if (metadata !== void 0) {
32531
32697
  feedback = `${feedback}
32532
- Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
32698
+ Metadata: ${(0, import_utils34.safeStringify)(metadata)}`;
32533
32699
  }
32534
32700
  oc.systemContext.set(MIDDLEWARE_RETRY_FEEDBACK_KEY, feedback);
32535
32701
  }
@@ -32629,8 +32795,8 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
32629
32795
  maxSteps,
32630
32796
  configuredToolCount,
32631
32797
  toolCallCount: toolCalls.length,
32632
- usage: usageForFinish ? JSON.parse((0, import_utils33.safeStringify)(usageForFinish)) : void 0,
32633
- providerMetadata: providerMetadata !== void 0 ? JSON.parse((0, import_utils33.safeStringify)(providerMetadata)) : void 0
32798
+ usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
32799
+ providerMetadata: providerMetadata !== void 0 ? JSON.parse((0, import_utils34.safeStringify)(providerMetadata)) : void 0
32634
32800
  }
32635
32801
  }
32636
32802
  );
@@ -32892,7 +33058,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
32892
33058
  for (const responseMessage of responseMessages) {
32893
33059
  const normalizedMessage = responseMessage.role === "assistant" ? { ...responseMessage, id: fallbackAssistantMessageId } : responseMessage;
32894
33060
  const fingerprintMessageId = normalizedMessage.role === "assistant" ? fallbackAssistantMessageId : normalizedMessage.id ?? null;
32895
- const fingerprint = (0, import_utils33.safeStringify)({
33061
+ const fingerprint = (0, import_utils34.safeStringify)({
32896
33062
  role: normalizedMessage.role,
32897
33063
  id: fingerprintMessageId,
32898
33064
  content: normalizedMessage.content
@@ -32967,7 +33133,14 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
32967
33133
  }
32968
33134
  createLLMSpan(oc, params) {
32969
33135
  const { label, ...spanParams } = params;
32970
- const attributes = this.buildLLMSpanAttributes(spanParams);
33136
+ const promptContextUsageEstimate = estimatePromptContextUsage({
33137
+ messages: params.messages,
33138
+ tools: params.tools
33139
+ });
33140
+ const attributes = {
33141
+ ...this.buildLLMSpanAttributes(spanParams),
33142
+ ...promptContextUsageEstimate ? promptContextUsageEstimateToAttributes(promptContextUsageEstimate) : {}
33143
+ };
32971
33144
  const span = oc.traceContext.createChildSpan(`llm:${params.operation}`, "llm", {
32972
33145
  kind: import_api16.SpanKind.CLIENT,
32973
33146
  label,
@@ -33049,12 +33222,12 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33049
33222
  attrs["llm.top_p"] = topP;
33050
33223
  }
33051
33224
  if (callOptions.stop !== void 0) {
33052
- attrs["llm.stop_condition"] = (0, import_utils33.safeStringify)(callOptions.stop);
33225
+ attrs["llm.stop_condition"] = (0, import_utils34.safeStringify)(callOptions.stop);
33053
33226
  }
33054
33227
  if (params.messages && params.messages.length > 0) {
33055
33228
  attrs["llm.messages.count"] = params.messages.length;
33056
33229
  const trimmedMessages = params.messages.slice(-10);
33057
- attrs["llm.messages"] = (0, import_utils33.safeStringify)(
33230
+ attrs["llm.messages"] = (0, import_utils34.safeStringify)(
33058
33231
  trimmedMessages.map((msg) => ({
33059
33232
  role: msg.role,
33060
33233
  content: msg.content
@@ -33069,7 +33242,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33069
33242
  }
33070
33243
  }
33071
33244
  if (params.providerOptions) {
33072
- attrs["llm.provider_options"] = (0, import_utils33.safeStringify)(params.providerOptions);
33245
+ attrs["llm.provider_options"] = (0, import_utils34.safeStringify)(params.providerOptions);
33073
33246
  }
33074
33247
  return attrs;
33075
33248
  }
@@ -33081,7 +33254,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33081
33254
  if (!normalizedUsage) {
33082
33255
  return;
33083
33256
  }
33084
- const { promptTokens, completionTokens, totalTokens } = normalizedUsage;
33257
+ const { promptTokens, completionTokens, totalTokens, cachedInputTokens, reasoningTokens } = normalizedUsage;
33085
33258
  if (promptTokens !== void 0) {
33086
33259
  span.setAttribute("llm.usage.prompt_tokens", promptTokens);
33087
33260
  }
@@ -33091,6 +33264,12 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33091
33264
  if (totalTokens !== void 0) {
33092
33265
  span.setAttribute("llm.usage.total_tokens", totalTokens);
33093
33266
  }
33267
+ if (cachedInputTokens !== void 0) {
33268
+ span.setAttribute("llm.usage.cached_tokens", cachedInputTokens);
33269
+ }
33270
+ if (reasoningTokens !== void 0) {
33271
+ span.setAttribute("llm.usage.reasoning_tokens", reasoningTokens);
33272
+ }
33094
33273
  }
33095
33274
  recordProviderCost(span, providerMetadata) {
33096
33275
  const openRouterUsageCost = extractOpenRouterUsageCost(providerMetadata);
@@ -33336,7 +33515,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33336
33515
  }
33337
33516
  } catch (error) {
33338
33517
  context8.logger.debug("[Memory] Failed to generate conversation title", {
33339
- error: (0, import_utils33.safeStringify)(error)
33518
+ error: (0, import_utils34.safeStringify)(error)
33340
33519
  });
33341
33520
  return null;
33342
33521
  }
@@ -33372,7 +33551,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33372
33551
  attributes: {
33373
33552
  "memory.operation": "read",
33374
33553
  "memory.semantic": isSemanticSearch,
33375
- input: (0, import_utils33.safeStringify)(spanInput),
33554
+ input: (0, import_utils34.safeStringify)(spanInput),
33376
33555
  ...isSemanticSearch && {
33377
33556
  "memory.semantic.limit": semanticLimit,
33378
33557
  "memory.semantic.threshold": semanticThreshold,
@@ -33594,10 +33773,10 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33594
33773
  rootSpan.setAttribute("prompt.version", metadata.version);
33595
33774
  }
33596
33775
  if (metadata.labels && metadata.labels.length > 0) {
33597
- rootSpan.setAttribute("prompt.labels", (0, import_utils33.safeStringify)(metadata.labels));
33776
+ rootSpan.setAttribute("prompt.labels", (0, import_utils34.safeStringify)(metadata.labels));
33598
33777
  }
33599
33778
  if (metadata.tags && metadata.tags.length > 0) {
33600
- rootSpan.setAttribute("prompt.tags", (0, import_utils33.safeStringify)(metadata.tags));
33779
+ rootSpan.setAttribute("prompt.tags", (0, import_utils34.safeStringify)(metadata.tags));
33601
33780
  }
33602
33781
  if (metadata.source) {
33603
33782
  rootSpan.setAttribute("prompt.source", metadata.source);
@@ -33609,7 +33788,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
33609
33788
  rootSpan.setAttribute("prompt.outdated", metadata.outdated);
33610
33789
  }
33611
33790
  if (metadata.config) {
33612
- rootSpan.setAttribute("prompt.config", (0, import_utils33.safeStringify)(metadata.config));
33791
+ rootSpan.setAttribute("prompt.config", (0, import_utils34.safeStringify)(metadata.config));
33613
33792
  }
33614
33793
  }
33615
33794
  }
@@ -33810,7 +33989,7 @@ ${retrieverContext}`;
33810
33989
  label: this.retriever.tool.name || "Retriever",
33811
33990
  attributes: {
33812
33991
  "retriever.name": this.retriever.tool.name || "Retriever",
33813
- input: typeof input === "string" ? input : (0, import_utils33.safeStringify)(input),
33992
+ input: typeof input === "string" ? input : (0, import_utils34.safeStringify)(input),
33814
33993
  ...this.getRetrieverObservabilityAttributes()
33815
33994
  }
33816
33995
  });
@@ -34057,7 +34236,7 @@ ${retrieverContext}`;
34057
34236
  nextModelIndex: nextCandidate ? index + 1 : void 0
34058
34237
  });
34059
34238
  logger.warn(`[Agent:${this.name}] - Failed to resolve model, falling back`, {
34060
- error: (0, import_utils33.safeStringify)(error),
34239
+ error: (0, import_utils34.safeStringify)(error),
34061
34240
  modelIndex: index,
34062
34241
  operation
34063
34242
  });
@@ -34102,7 +34281,7 @@ ${retrieverContext}`;
34102
34281
  retryEligible,
34103
34282
  isRetryable: error?.isRetryable,
34104
34283
  statusCode: error?.statusCode,
34105
- error: (0, import_utils33.safeStringify)(error)
34284
+ error: (0, import_utils34.safeStringify)(error)
34106
34285
  });
34107
34286
  await hooks.onRetry?.({
34108
34287
  agent: this,
@@ -34134,7 +34313,7 @@ ${retrieverContext}`;
34134
34313
  fallbackEligible,
34135
34314
  retryEligible,
34136
34315
  isLastModel,
34137
- error: (0, import_utils33.safeStringify)(error)
34316
+ error: (0, import_utils34.safeStringify)(error)
34138
34317
  });
34139
34318
  throw error;
34140
34319
  }
@@ -34154,7 +34333,7 @@ ${retrieverContext}`;
34154
34333
  nextModelIndex: nextCandidate ? index + 1 : void 0
34155
34334
  });
34156
34335
  logger.warn(`[Agent:${this.name}] - Model failed, trying fallback`, {
34157
- error: (0, import_utils33.safeStringify)(error),
34336
+ error: (0, import_utils34.safeStringify)(error),
34158
34337
  modelName,
34159
34338
  modelIndex: index,
34160
34339
  operation,
@@ -34374,9 +34553,9 @@ ${retrieverContext}`;
34374
34553
  "tool.name": tool2.name,
34375
34554
  "tool.call.id": toolCallId,
34376
34555
  "tool.description": tool2.description,
34377
- ...toolTags && toolTags.length > 0 ? { "tool.tags": (0, import_utils33.safeStringify)(toolTags) } : {},
34378
- "tool.parameters": (0, import_utils33.safeStringify)(tool2.parameters),
34379
- input: args ? (0, import_utils33.safeStringify)(args) : void 0
34556
+ ...toolTags && toolTags.length > 0 ? { "tool.tags": (0, import_utils34.safeStringify)(toolTags) } : {},
34557
+ "tool.parameters": (0, import_utils34.safeStringify)(tool2.parameters),
34558
+ input: args ? (0, import_utils34.safeStringify)(args) : void 0
34380
34559
  },
34381
34560
  kind: import_api16.SpanKind.CLIENT
34382
34561
  });
@@ -34817,7 +34996,7 @@ ${retrieverContext}`;
34817
34996
  output: selections,
34818
34997
  attributes: {
34819
34998
  "tool.search.selection.count": selections.length,
34820
- "tool.search.selection.names": (0, import_utils33.safeStringify)(
34999
+ "tool.search.selection.names": (0, import_utils34.safeStringify)(
34821
35000
  selections.map((selection) => selection.name)
34822
35001
  )
34823
35002
  }
@@ -34825,7 +35004,7 @@ ${retrieverContext}`;
34825
35004
  oc.logger.debug("Tool search selections computed", {
34826
35005
  tool: TOOL_ROUTING_SEARCH_TOOL_NAME,
34827
35006
  query,
34828
- selections: (0, import_utils33.safeStringify)(selections)
35007
+ selections: (0, import_utils34.safeStringify)(selections)
34829
35008
  });
34830
35009
  } catch (error) {
34831
35010
  oc.traceContext.endChildSpan(selectionSpan, "error", {
@@ -34971,7 +35150,7 @@ ${retrieverContext}`;
34971
35150
  const tools = {
34972
35151
  [tool2.name]: tool2
34973
35152
  };
34974
- const argsInstruction = `Use these tool arguments exactly: ${(0, import_utils33.safeStringify)(args)}`;
35153
+ const argsInstruction = `Use these tool arguments exactly: ${(0, import_utils34.safeStringify)(args)}`;
34975
35154
  const result = await this.runInternalGenerateText({
34976
35155
  oc,
34977
35156
  messages: [
@@ -35316,7 +35495,7 @@ ${retrieverContext}`;
35316
35495
  oc.conversationSteps?.push({
35317
35496
  id: toolCall.toolCallId || randomUUID(),
35318
35497
  type: "tool_call",
35319
- content: (0, import_utils33.safeStringify)(toolCall.input ?? {}),
35498
+ content: (0, import_utils34.safeStringify)(toolCall.input ?? {}),
35320
35499
  role: "assistant",
35321
35500
  name: toolCall.toolName,
35322
35501
  arguments: toolCall.input || {},
@@ -35348,7 +35527,7 @@ ${retrieverContext}`;
35348
35527
  oc.conversationSteps?.push({
35349
35528
  id: toolResult.toolCallId || randomUUID(),
35350
35529
  type: "tool_result",
35351
- content: (0, import_utils33.safeStringify)(toolResult.output),
35530
+ content: (0, import_utils34.safeStringify)(toolResult.output),
35352
35531
  role: "assistant",
35353
35532
  name: toolResult.toolName,
35354
35533
  result: toolResult.output,
@@ -36230,7 +36409,7 @@ ${retrieverContext}`;
36230
36409
  };
36231
36410
 
36232
36411
  // src/planagent/plan-agent.ts
36233
- var import_utils38 = require("@voltagent/internal/utils");
36412
+ var import_utils39 = require("@voltagent/internal/utils");
36234
36413
  var import_zod10 = require("zod");
36235
36414
 
36236
36415
  // src/planagent/context-keys.ts
@@ -36242,7 +36421,7 @@ var import_internal11 = require("@voltagent/internal");
36242
36421
  var import_zod8 = require("zod");
36243
36422
 
36244
36423
  // src/planagent/state.ts
36245
- var import_utils35 = require("@voltagent/internal/utils");
36424
+ var import_utils36 = require("@voltagent/internal/utils");
36246
36425
  var PLANAGENT_METADATA_KEY = "planagent";
36247
36426
  var STATE_CACHE_KEY = Symbol("planagentState");
36248
36427
  var fallbackState = /* @__PURE__ */ new Map();
@@ -36254,13 +36433,13 @@ function readStateFromMetadata(metadata) {
36254
36433
  if (!metadata) return null;
36255
36434
  const entry = metadata[PLANAGENT_METADATA_KEY];
36256
36435
  if (!entry || typeof entry !== "object") return null;
36257
- return (0, import_utils35.deepClone)(entry);
36436
+ return (0, import_utils36.deepClone)(entry);
36258
36437
  }
36259
36438
  __name(readStateFromMetadata, "readStateFromMetadata");
36260
36439
  async function loadPlanAgentState(agent, context8) {
36261
36440
  const cached = context8.systemContext.get(STATE_CACHE_KEY);
36262
36441
  if (cached) {
36263
- return (0, import_utils35.deepClone)(cached);
36442
+ return (0, import_utils36.deepClone)(cached);
36264
36443
  }
36265
36444
  let state = null;
36266
36445
  const memory = agent.getMemory();
@@ -36270,23 +36449,23 @@ async function loadPlanAgentState(agent, context8) {
36270
36449
  state = readStateFromMetadata(conversation?.metadata);
36271
36450
  } catch (error) {
36272
36451
  context8.logger.debug("[PlanAgent] Failed to load state from memory", {
36273
- error: (0, import_utils35.safeStringify)(error)
36452
+ error: (0, import_utils36.safeStringify)(error)
36274
36453
  });
36275
36454
  }
36276
36455
  }
36277
36456
  if (!state) {
36278
- state = (0, import_utils35.deepClone)(fallbackState.get(getConversationKey(context8)) || {});
36457
+ state = (0, import_utils36.deepClone)(fallbackState.get(getConversationKey(context8)) || {});
36279
36458
  }
36280
36459
  context8.systemContext.set(STATE_CACHE_KEY, state);
36281
- return (0, import_utils35.deepClone)(state);
36460
+ return (0, import_utils36.deepClone)(state);
36282
36461
  }
36283
36462
  __name(loadPlanAgentState, "loadPlanAgentState");
36284
36463
  async function updatePlanAgentState(agent, context8, updater) {
36285
36464
  const current = await loadPlanAgentState(agent, context8);
36286
- const nextState = updater((0, import_utils35.deepClone)(current));
36465
+ const nextState = updater((0, import_utils36.deepClone)(current));
36287
36466
  const normalized = nextState || {};
36288
36467
  context8.systemContext.set(STATE_CACHE_KEY, normalized);
36289
- fallbackState.set(getConversationKey(context8), (0, import_utils35.deepClone)(normalized));
36468
+ fallbackState.set(getConversationKey(context8), (0, import_utils36.deepClone)(normalized));
36290
36469
  const memory = agent.getMemory();
36291
36470
  if (memory && context8.conversationId) {
36292
36471
  try {
@@ -36294,17 +36473,17 @@ async function updatePlanAgentState(agent, context8, updater) {
36294
36473
  if (conversation) {
36295
36474
  const metadata = {
36296
36475
  ...conversation.metadata,
36297
- [PLANAGENT_METADATA_KEY]: (0, import_utils35.deepClone)(normalized)
36476
+ [PLANAGENT_METADATA_KEY]: (0, import_utils36.deepClone)(normalized)
36298
36477
  };
36299
36478
  await memory.updateConversation(context8.conversationId, { metadata });
36300
36479
  }
36301
36480
  } catch (error) {
36302
36481
  context8.logger.debug("[PlanAgent] Failed to persist state", {
36303
- error: (0, import_utils35.safeStringify)(error)
36482
+ error: (0, import_utils36.safeStringify)(error)
36304
36483
  });
36305
36484
  }
36306
36485
  }
36307
- return (0, import_utils35.deepClone)(normalized);
36486
+ return (0, import_utils36.deepClone)(normalized);
36308
36487
  }
36309
36488
  __name(updatePlanAgentState, "updatePlanAgentState");
36310
36489
 
@@ -36714,7 +36893,7 @@ function createToolResultEvictor(options) {
36714
36893
  __name(createToolResultEvictor, "createToolResultEvictor");
36715
36894
 
36716
36895
  // src/planagent/planning/index.ts
36717
- var import_utils37 = require("@voltagent/internal/utils");
36896
+ var import_utils38 = require("@voltagent/internal/utils");
36718
36897
  var import_zod9 = require("zod");
36719
36898
 
36720
36899
  // src/planagent/planning/backend.ts
@@ -36858,7 +37037,7 @@ function createPlanningToolkit(agent, options = {}) {
36858
37037
  toolSpan.setAttribute("planagent.todos.done", doneCount);
36859
37038
  toolSpan.setAttribute("planagent.todos.truncated", snapshot.truncated);
36860
37039
  toolSpan.setAttribute("planagent.todos.blocked_done", blockedCount);
36861
- toolSpan.setAttribute("planagent.todos", (0, import_utils37.safeStringify)(snapshot.todos));
37040
+ toolSpan.setAttribute("planagent.todos", (0, import_utils38.safeStringify)(snapshot.todos));
36862
37041
  }
36863
37042
  return {
36864
37043
  todos: guardedTodos,
@@ -37434,7 +37613,7 @@ function createTaskToolkit(options) {
37434
37613
  parentSpan: toolSpan
37435
37614
  });
37436
37615
  if (toolSpan) {
37437
- const responsePreview = typeof result.result === "string" ? truncateText3(result.result, 500) : truncateText3((0, import_utils38.safeStringify)(result.result), 500);
37616
+ const responsePreview = typeof result.result === "string" ? truncateText3(result.result, 500) : truncateText3((0, import_utils39.safeStringify)(result.result), 500);
37438
37617
  toolSpan.setAttribute("planagent.task.status", result.bailed ? "bailed" : "completed");
37439
37618
  toolSpan.setAttribute("planagent.task.response_preview", responsePreview);
37440
37619
  }
@@ -41167,7 +41346,7 @@ var import_node_crypto = __toESM(require("crypto"));
41167
41346
  var import_node_fs3 = __toESM(require("fs"));
41168
41347
  var import_node_os = __toESM(require("os"));
41169
41348
  var import_node_path3 = __toESM(require("path"));
41170
- var import_utils39 = require("@voltagent/internal/utils");
41349
+ var import_utils40 = require("@voltagent/internal/utils");
41171
41350
  var getEnvPaths = /* @__PURE__ */ __name((name) => {
41172
41351
  const homedir = import_node_os.default.homedir();
41173
41352
  const tmpdir = import_node_os.default.tmpdir();
@@ -41237,7 +41416,7 @@ var writeUpdateCache = /* @__PURE__ */ __name(async (projectPath, cache) => {
41237
41416
  try {
41238
41417
  ensureCacheDir();
41239
41418
  const cacheFilePath = getCacheFilePath(projectPath);
41240
- import_node_fs3.default.writeFileSync(cacheFilePath, (0, import_utils39.safeStringify)(cache, { indentation: 2 }), "utf8");
41419
+ import_node_fs3.default.writeFileSync(cacheFilePath, (0, import_utils40.safeStringify)(cache, { indentation: 2 }), "utf8");
41241
41420
  } catch (error) {
41242
41421
  const logger = new LoggerProxy({ component: "update-cache" });
41243
41422
  logger.error("Error writing update cache", { error });
@@ -42292,7 +42471,7 @@ var VoltAgent = class {
42292
42471
  };
42293
42472
 
42294
42473
  // src/index.ts
42295
- var import_utils40 = require("@voltagent/internal/utils");
42474
+ var import_utils41 = require("@voltagent/internal/utils");
42296
42475
  var import_ai9 = require("ai");
42297
42476
  // Annotate the CommonJS export names for ESM import in node:
42298
42477
  0 && (module.exports = {