@voltagent/core 1.1.34 → 1.1.36

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
@@ -1307,6 +1307,10 @@ declare class LoggerProxy implements Logger {
1307
1307
  * Get the actual logger instance with bindings applied
1308
1308
  */
1309
1309
  private getActualLogger;
1310
+ /**
1311
+ * Check if a log level should be logged based on the configured level
1312
+ */
1313
+ private shouldLog;
1310
1314
  /**
1311
1315
  * Emit log via OpenTelemetry Logs API if available
1312
1316
  */
@@ -3514,6 +3518,14 @@ declare class AgentTraceContext {
3514
3518
  cachedTokens?: number;
3515
3519
  reasoningTokens?: number;
3516
3520
  }): void;
3521
+ /**
3522
+ * Set finish reason on the root span
3523
+ */
3524
+ setFinishReason(finishReason: string | null | undefined): void;
3525
+ /**
3526
+ * Set stop condition metadata when maxSteps is reached
3527
+ */
3528
+ setStopConditionMet(stepCount: number, maxSteps: number): void;
3517
3529
  /**
3518
3530
  * End the root span with a status
3519
3531
  */
package/dist/index.d.ts CHANGED
@@ -1307,6 +1307,10 @@ declare class LoggerProxy implements Logger {
1307
1307
  * Get the actual logger instance with bindings applied
1308
1308
  */
1309
1309
  private getActualLogger;
1310
+ /**
1311
+ * Check if a log level should be logged based on the configured level
1312
+ */
1313
+ private shouldLog;
1310
1314
  /**
1311
1315
  * Emit log via OpenTelemetry Logs API if available
1312
1316
  */
@@ -3514,6 +3518,14 @@ declare class AgentTraceContext {
3514
3518
  cachedTokens?: number;
3515
3519
  reasoningTokens?: number;
3516
3520
  }): void;
3521
+ /**
3522
+ * Set finish reason on the root span
3523
+ */
3524
+ setFinishReason(finishReason: string | null | undefined): void;
3525
+ /**
3526
+ * Set stop condition metadata when maxSteps is reached
3527
+ */
3528
+ setStopConditionMet(stepCount: number, maxSteps: number): void;
3517
3529
  /**
3518
3530
  * End the root span with a status
3519
3531
  */
package/dist/index.js CHANGED
@@ -1190,10 +1190,10 @@ var ConsoleLogger = class _ConsoleLogger {
1190
1190
  msg = args[0] || "";
1191
1191
  obj = msgOrObj;
1192
1192
  }
1193
+ this.emitOtelLog(level, msg, obj);
1193
1194
  if (this.shouldLog(level)) {
1194
1195
  consoleFn(this.formatMessage(level, msg, obj));
1195
1196
  }
1196
- this.emitOtelLog(level, msg, obj);
1197
1197
  };
1198
1198
  }
1199
1199
  trace = this.createLogFn("trace", console.debug);
@@ -1377,6 +1377,28 @@ var LoggerProxy = class _LoggerProxy {
1377
1377
  const baseLogger = this.externalLogger || getGlobalLogger();
1378
1378
  return Object.keys(this.bindings).length > 0 ? baseLogger.child(this.bindings) : baseLogger;
1379
1379
  }
1380
+ /**
1381
+ * Check if a log level should be logged based on the configured level
1382
+ */
1383
+ shouldLog(messageLevel) {
1384
+ const logger = this.getActualLogger();
1385
+ let configuredLevel;
1386
+ if (logger._pinoInstance?.level) {
1387
+ configuredLevel = logger._pinoInstance.level;
1388
+ } else if (logger.level !== void 0) {
1389
+ configuredLevel = logger.level;
1390
+ }
1391
+ if (!configuredLevel) {
1392
+ return true;
1393
+ }
1394
+ const levels = ["trace", "debug", "info", "warn", "error", "fatal"];
1395
+ const configuredLevelIndex = levels.indexOf(configuredLevel.toLowerCase());
1396
+ const messageLevelIndex = levels.indexOf(messageLevel.toLowerCase());
1397
+ if (configuredLevelIndex === -1 || messageLevelIndex === -1) {
1398
+ return true;
1399
+ }
1400
+ return messageLevelIndex >= configuredLevelIndex;
1401
+ }
1380
1402
  /**
1381
1403
  * Emit log via OpenTelemetry Logs API if available
1382
1404
  */
@@ -1414,34 +1436,40 @@ var LoggerProxy = class _LoggerProxy {
1414
1436
  }
1415
1437
  }
1416
1438
  trace = /* @__PURE__ */ __name((msg, context8) => {
1439
+ this.emitOtelLog("trace", msg, context8);
1440
+ if (!this.shouldLog("trace")) return;
1417
1441
  const logger = this.getActualLogger();
1418
1442
  logger.trace(msg, context8);
1419
- this.emitOtelLog("trace", msg, context8);
1420
1443
  }, "trace");
1421
1444
  debug = /* @__PURE__ */ __name((msg, context8) => {
1445
+ this.emitOtelLog("debug", msg, context8);
1446
+ if (!this.shouldLog("debug")) return;
1422
1447
  const logger = this.getActualLogger();
1423
1448
  logger.debug(msg, context8);
1424
- this.emitOtelLog("debug", msg, context8);
1425
1449
  }, "debug");
1426
1450
  info = /* @__PURE__ */ __name((msg, context8) => {
1451
+ this.emitOtelLog("info", msg, context8);
1452
+ if (!this.shouldLog("info")) return;
1427
1453
  const logger = this.getActualLogger();
1428
1454
  logger.info(msg, context8);
1429
- this.emitOtelLog("info", msg, context8);
1430
1455
  }, "info");
1431
1456
  warn = /* @__PURE__ */ __name((msg, context8) => {
1457
+ this.emitOtelLog("warn", msg, context8);
1458
+ if (!this.shouldLog("warn")) return;
1432
1459
  const logger = this.getActualLogger();
1433
1460
  logger.warn(msg, context8);
1434
- this.emitOtelLog("warn", msg, context8);
1435
1461
  }, "warn");
1436
1462
  error = /* @__PURE__ */ __name((msg, context8) => {
1463
+ this.emitOtelLog("error", msg, context8);
1464
+ if (!this.shouldLog("error")) return;
1437
1465
  const logger = this.getActualLogger();
1438
1466
  logger.error(msg, context8);
1439
- this.emitOtelLog("error", msg, context8);
1440
1467
  }, "error");
1441
1468
  fatal = /* @__PURE__ */ __name((msg, context8) => {
1469
+ this.emitOtelLog("fatal", msg, context8);
1470
+ if (!this.shouldLog("fatal")) return;
1442
1471
  const logger = this.getActualLogger();
1443
1472
  logger.fatal(msg, context8);
1444
- this.emitOtelLog("fatal", msg, context8);
1445
1473
  }, "fatal");
1446
1474
  /**
1447
1475
  * Create a child logger with additional bindings
@@ -11251,6 +11279,24 @@ var AgentTraceContext = class {
11251
11279
  this.rootSpan.setAttribute("usage.reasoning_tokens", usage.reasoningTokens);
11252
11280
  }
11253
11281
  }
11282
+ /**
11283
+ * Set finish reason on the root span
11284
+ */
11285
+ setFinishReason(finishReason) {
11286
+ if (finishReason !== null && finishReason !== void 0) {
11287
+ this.rootSpan.setAttribute("ai.response.finish_reason", finishReason);
11288
+ }
11289
+ }
11290
+ /**
11291
+ * Set stop condition metadata when maxSteps is reached
11292
+ */
11293
+ setStopConditionMet(stepCount, maxSteps) {
11294
+ this.rootSpan.setAttributes({
11295
+ "voltagent.stopped_by_max_steps": true,
11296
+ "voltagent.step_count": stepCount,
11297
+ "voltagent.max_steps": maxSteps
11298
+ });
11299
+ }
11254
11300
  /**
11255
11301
  * End the root span with a status
11256
11302
  */
@@ -14553,6 +14599,10 @@ var Agent = class {
14553
14599
  );
14554
14600
  this.setTraceContextUsage(oc.traceContext, result.usage);
14555
14601
  oc.traceContext.setOutput(finalText);
14602
+ oc.traceContext.setFinishReason(result.finishReason);
14603
+ if (result.steps && result.steps.length >= maxSteps) {
14604
+ oc.traceContext.setStopConditionMet(result.steps.length, maxSteps);
14605
+ }
14556
14606
  oc.output = finalText;
14557
14607
  this.enqueueEvalScoring({
14558
14608
  oc,
@@ -14713,6 +14763,11 @@ var Agent = class {
14713
14763
  }
14714
14764
  const guardrailedResult = guardrailSet.output.length > 0 ? { ...finalResult, text: finalText } : finalResult;
14715
14765
  oc.traceContext.setOutput(finalText);
14766
+ oc.traceContext.setFinishReason(finalResult.finishReason);
14767
+ const steps = finalResult.steps;
14768
+ if (steps && steps.length >= maxSteps) {
14769
+ oc.traceContext.setStopConditionMet(steps.length, maxSteps);
14770
+ }
14716
14771
  oc.output = finalText;
14717
14772
  await this.getMergedHooks(options).onEnd?.({
14718
14773
  conversationId: oc.conversationId || "",