@voltagent/core 2.2.0 → 2.2.1
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 +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +49 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6929,6 +6929,7 @@ interface TraceContextOptions {
|
|
|
6929
6929
|
conversationId?: string;
|
|
6930
6930
|
operationId: string;
|
|
6931
6931
|
parentSpan?: Span;
|
|
6932
|
+
inheritParentSpan?: boolean;
|
|
6932
6933
|
parentAgentId?: string;
|
|
6933
6934
|
input?: string | UIMessage[] | BaseMessage[];
|
|
6934
6935
|
}
|
|
@@ -7458,6 +7459,11 @@ type AgentOptions = {
|
|
|
7458
7459
|
*/
|
|
7459
7460
|
stopWhen?: StopWhen;
|
|
7460
7461
|
markdown?: boolean;
|
|
7462
|
+
/**
|
|
7463
|
+
* When true, use the active VoltAgent span as the parent if parentSpan is not provided.
|
|
7464
|
+
* Defaults to true.
|
|
7465
|
+
*/
|
|
7466
|
+
inheritParentSpan?: boolean;
|
|
7461
7467
|
voice?: Voice;
|
|
7462
7468
|
logger?: Logger;
|
|
7463
7469
|
voltOpsClient?: VoltOpsClient;
|
|
@@ -8317,6 +8323,7 @@ interface BaseGenerationOptions extends Partial<CallSettings> {
|
|
|
8317
8323
|
parentAgentId?: string;
|
|
8318
8324
|
parentOperationContext?: OperationContext;
|
|
8319
8325
|
parentSpan?: Span;
|
|
8326
|
+
inheritParentSpan?: boolean;
|
|
8320
8327
|
contextLimit?: number;
|
|
8321
8328
|
semanticMemory?: {
|
|
8322
8329
|
enabled?: boolean;
|
|
@@ -8385,6 +8392,7 @@ declare class Agent {
|
|
|
8385
8392
|
readonly maxRetries: number;
|
|
8386
8393
|
readonly stopWhen?: StopWhen;
|
|
8387
8394
|
readonly markdown: boolean;
|
|
8395
|
+
readonly inheritParentSpan: boolean;
|
|
8388
8396
|
readonly voice?: Voice;
|
|
8389
8397
|
readonly retriever?: BaseRetriever;
|
|
8390
8398
|
readonly supervisorConfig?: SupervisorConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -6929,6 +6929,7 @@ interface TraceContextOptions {
|
|
|
6929
6929
|
conversationId?: string;
|
|
6930
6930
|
operationId: string;
|
|
6931
6931
|
parentSpan?: Span;
|
|
6932
|
+
inheritParentSpan?: boolean;
|
|
6932
6933
|
parentAgentId?: string;
|
|
6933
6934
|
input?: string | UIMessage[] | BaseMessage[];
|
|
6934
6935
|
}
|
|
@@ -7458,6 +7459,11 @@ type AgentOptions = {
|
|
|
7458
7459
|
*/
|
|
7459
7460
|
stopWhen?: StopWhen;
|
|
7460
7461
|
markdown?: boolean;
|
|
7462
|
+
/**
|
|
7463
|
+
* When true, use the active VoltAgent span as the parent if parentSpan is not provided.
|
|
7464
|
+
* Defaults to true.
|
|
7465
|
+
*/
|
|
7466
|
+
inheritParentSpan?: boolean;
|
|
7461
7467
|
voice?: Voice;
|
|
7462
7468
|
logger?: Logger;
|
|
7463
7469
|
voltOpsClient?: VoltOpsClient;
|
|
@@ -8317,6 +8323,7 @@ interface BaseGenerationOptions extends Partial<CallSettings> {
|
|
|
8317
8323
|
parentAgentId?: string;
|
|
8318
8324
|
parentOperationContext?: OperationContext;
|
|
8319
8325
|
parentSpan?: Span;
|
|
8326
|
+
inheritParentSpan?: boolean;
|
|
8320
8327
|
contextLimit?: number;
|
|
8321
8328
|
semanticMemory?: {
|
|
8322
8329
|
enabled?: boolean;
|
|
@@ -8385,6 +8392,7 @@ declare class Agent {
|
|
|
8385
8392
|
readonly maxRetries: number;
|
|
8386
8393
|
readonly stopWhen?: StopWhen;
|
|
8387
8394
|
readonly markdown: boolean;
|
|
8395
|
+
readonly inheritParentSpan: boolean;
|
|
8388
8396
|
readonly voice?: Voice;
|
|
8389
8397
|
readonly retriever?: BaseRetriever;
|
|
8390
8398
|
readonly supervisorConfig?: SupervisorConfig;
|
package/dist/index.js
CHANGED
|
@@ -18415,6 +18415,13 @@ var popActiveSpan2 = /* @__PURE__ */ __name((span) => {
|
|
|
18415
18415
|
spanBridge2.___voltagent_pop_span?.(span);
|
|
18416
18416
|
}, "popActiveSpan");
|
|
18417
18417
|
var isPromiseLike3 = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && typeof value.then === "function", "isPromiseLike");
|
|
18418
|
+
var getSpanAttributes = /* @__PURE__ */ __name((span) => span?.attributes ?? {}, "getSpanAttributes");
|
|
18419
|
+
var isWorkflowSpan = /* @__PURE__ */ __name((attributes) => attributes["entity.type"] === "workflow" || attributes["span.type"] === "workflow-step", "isWorkflowSpan");
|
|
18420
|
+
var isAgentSpan = /* @__PURE__ */ __name((attributes) => attributes["entity.type"] === "agent", "isAgentSpan");
|
|
18421
|
+
var getAgentInfo = /* @__PURE__ */ __name((attributes) => ({
|
|
18422
|
+
id: attributes["entity.id"] ?? attributes["eval.source.agent_id"],
|
|
18423
|
+
name: attributes["entity.name"]
|
|
18424
|
+
}), "getAgentInfo");
|
|
18418
18425
|
var AgentTraceContext = class {
|
|
18419
18426
|
static {
|
|
18420
18427
|
__name(this, "AgentTraceContext");
|
|
@@ -18425,11 +18432,13 @@ var AgentTraceContext = class {
|
|
|
18425
18432
|
activeContext;
|
|
18426
18433
|
constructor(observability, operationName, options) {
|
|
18427
18434
|
this.tracer = observability.getTracer();
|
|
18428
|
-
const resolvedParent = this.resolveParentSpan(options.parentSpan);
|
|
18435
|
+
const resolvedParent = this.resolveParentSpan(options.parentSpan, options.inheritParentSpan);
|
|
18429
18436
|
const parentSpan = resolvedParent?.span ?? options.parentSpan;
|
|
18430
|
-
const
|
|
18431
|
-
const
|
|
18432
|
-
const isSubagent = !!parentSpan;
|
|
18437
|
+
const isWorkflowParent = resolvedParent?.parentType === "workflow";
|
|
18438
|
+
const explicitParentAgentId = options.parentAgentId ?? resolvedParent?.agentInfo?.id;
|
|
18439
|
+
const isSubagent = !!parentSpan && !isWorkflowParent && !!explicitParentAgentId;
|
|
18440
|
+
const parentAgentId = isSubagent ? explicitParentAgentId : void 0;
|
|
18441
|
+
const parentAgentName = isSubagent ? resolvedParent?.agentInfo?.name : void 0;
|
|
18433
18442
|
const commonAttributes = {
|
|
18434
18443
|
...options.userId && { "user.id": options.userId },
|
|
18435
18444
|
...options.conversationId && { "conversation.id": options.conversationId },
|
|
@@ -18467,7 +18476,7 @@ var AgentTraceContext = class {
|
|
|
18467
18476
|
const inputStr = typeof options.input === "string" ? options.input : (0, import_internal8.safeStringify)(options.input);
|
|
18468
18477
|
spanAttributes.input = inputStr;
|
|
18469
18478
|
}
|
|
18470
|
-
const spanName =
|
|
18479
|
+
const spanName = isSubagent ? `subagent:${options.agentName || operationName}` : operationName;
|
|
18471
18480
|
this.rootSpan = this.tracer.startSpan(
|
|
18472
18481
|
spanName,
|
|
18473
18482
|
{
|
|
@@ -18476,8 +18485,8 @@ var AgentTraceContext = class {
|
|
|
18476
18485
|
...spanAttributes,
|
|
18477
18486
|
"agent.state": "running",
|
|
18478
18487
|
// Track initial agent state
|
|
18479
|
-
// Mark as subagent
|
|
18480
|
-
...
|
|
18488
|
+
// Mark as subagent only when an explicit agent parent is present
|
|
18489
|
+
...isSubagent && {
|
|
18481
18490
|
"agent.is_subagent": true,
|
|
18482
18491
|
"voltagent.is_subagent": true
|
|
18483
18492
|
}
|
|
@@ -18696,25 +18705,46 @@ var AgentTraceContext = class {
|
|
|
18696
18705
|
}
|
|
18697
18706
|
span.end();
|
|
18698
18707
|
}
|
|
18699
|
-
resolveParentSpan(explicitParent) {
|
|
18708
|
+
resolveParentSpan(explicitParent, inheritParentSpan) {
|
|
18700
18709
|
if (explicitParent) {
|
|
18701
|
-
|
|
18710
|
+
const attributes2 = getSpanAttributes(explicitParent);
|
|
18711
|
+
return {
|
|
18712
|
+
span: explicitParent,
|
|
18713
|
+
parentType: isWorkflowSpan(attributes2) ? "workflow" : isAgentSpan(attributes2) ? "agent" : "unknown",
|
|
18714
|
+
agentInfo: isAgentSpan(attributes2) ? getAgentInfo(attributes2) : void 0
|
|
18715
|
+
};
|
|
18702
18716
|
}
|
|
18703
18717
|
const activeSpan = import_api12.trace.getSpan(import_api12.context.active());
|
|
18704
18718
|
if (!activeSpan) {
|
|
18705
18719
|
return void 0;
|
|
18706
18720
|
}
|
|
18707
|
-
const attributes = activeSpan
|
|
18721
|
+
const attributes = getSpanAttributes(activeSpan);
|
|
18708
18722
|
const spanType = attributes["span.type"];
|
|
18709
18723
|
const scorerId = attributes["eval.scorer.id"];
|
|
18710
|
-
if (spanType
|
|
18724
|
+
if (spanType === "scorer" || scorerId !== void 0) {
|
|
18725
|
+
return {
|
|
18726
|
+
span: activeSpan,
|
|
18727
|
+
parentType: "agent",
|
|
18728
|
+
agentInfo: getAgentInfo(attributes)
|
|
18729
|
+
};
|
|
18730
|
+
}
|
|
18731
|
+
if (!inheritParentSpan) {
|
|
18711
18732
|
return void 0;
|
|
18712
18733
|
}
|
|
18713
|
-
|
|
18714
|
-
|
|
18715
|
-
|
|
18716
|
-
|
|
18717
|
-
|
|
18734
|
+
if (isWorkflowSpan(attributes)) {
|
|
18735
|
+
return {
|
|
18736
|
+
span: activeSpan,
|
|
18737
|
+
parentType: "workflow"
|
|
18738
|
+
};
|
|
18739
|
+
}
|
|
18740
|
+
if (isAgentSpan(attributes)) {
|
|
18741
|
+
return {
|
|
18742
|
+
span: activeSpan,
|
|
18743
|
+
parentType: "agent",
|
|
18744
|
+
agentInfo: getAgentInfo(attributes)
|
|
18745
|
+
};
|
|
18746
|
+
}
|
|
18747
|
+
return void 0;
|
|
18718
18748
|
}
|
|
18719
18749
|
/**
|
|
18720
18750
|
* Get the active context for manual context propagation
|
|
@@ -21949,6 +21979,7 @@ var Agent = class {
|
|
|
21949
21979
|
maxRetries;
|
|
21950
21980
|
stopWhen;
|
|
21951
21981
|
markdown;
|
|
21982
|
+
inheritParentSpan;
|
|
21952
21983
|
voice;
|
|
21953
21984
|
retriever;
|
|
21954
21985
|
supervisorConfig;
|
|
@@ -21992,6 +22023,7 @@ var Agent = class {
|
|
|
21992
22023
|
this.maxRetries = options.maxRetries ?? DEFAULT_LLM_MAX_RETRIES;
|
|
21993
22024
|
this.stopWhen = options.stopWhen;
|
|
21994
22025
|
this.markdown = options.markdown ?? false;
|
|
22026
|
+
this.inheritParentSpan = options.inheritParentSpan ?? true;
|
|
21995
22027
|
this.voice = options.voice;
|
|
21996
22028
|
this.retriever = options.retriever;
|
|
21997
22029
|
this.supervisorConfig = options.supervisorConfig;
|
|
@@ -23903,6 +23935,7 @@ Metadata: ${(0, import_utils28.safeStringify)(metadata)}`;
|
|
|
23903
23935
|
conversationId: options?.conversationId,
|
|
23904
23936
|
operationId,
|
|
23905
23937
|
parentSpan: options?.parentSpan,
|
|
23938
|
+
inheritParentSpan: options?.inheritParentSpan ?? this.inheritParentSpan,
|
|
23906
23939
|
parentAgentId: options?.parentAgentId,
|
|
23907
23940
|
input
|
|
23908
23941
|
});
|