@voltagent/core 0.1.39 → 0.1.41
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 +115 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -104
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6424,14 +6424,19 @@ ${agentsMemory || "No previous agent interactions available."}
|
|
|
6424
6424
|
await targetAgent.hooks.onHandoff?.({ agent: targetAgent, source: sourceAgent });
|
|
6425
6425
|
}
|
|
6426
6426
|
const sharedContext = options.sharedContext || [];
|
|
6427
|
-
const
|
|
6428
|
-
|
|
6429
|
-
|
|
6427
|
+
const forwardEvent = options.forwardEvent;
|
|
6428
|
+
let taskContent = task;
|
|
6429
|
+
if (context && Object.keys(context).length > 0) {
|
|
6430
|
+
taskContent = `Task handed off from ${sourceAgent?.name || this.agentName} to ${targetAgent.name}:
|
|
6430
6431
|
${task}
|
|
6431
|
-
|
|
6432
|
+
|
|
6433
|
+
Context: ${JSON.stringify(context, null, 2)}`;
|
|
6434
|
+
}
|
|
6435
|
+
const taskMessage = {
|
|
6436
|
+
role: "system",
|
|
6437
|
+
content: taskContent
|
|
6432
6438
|
};
|
|
6433
|
-
const
|
|
6434
|
-
const streamResponse = await targetAgent.streamText([handoffMessage, ...sharedContext], {
|
|
6439
|
+
const streamResponse = await targetAgent.streamText([...sharedContext, taskMessage], {
|
|
6435
6440
|
conversationId: handoffConversationId,
|
|
6436
6441
|
userId,
|
|
6437
6442
|
parentAgentId: sourceAgent?.id || parentAgentId,
|
|
@@ -6439,115 +6444,121 @@ Context: ${JSON.stringify(context)}`
|
|
|
6439
6444
|
userContext
|
|
6440
6445
|
});
|
|
6441
6446
|
let finalText = "";
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6447
|
+
if (streamResponse.fullStream) {
|
|
6448
|
+
for await (const part of streamResponse.fullStream) {
|
|
6449
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
6450
|
+
switch (part.type) {
|
|
6451
|
+
case "text-delta": {
|
|
6452
|
+
finalText += part.textDelta;
|
|
6453
|
+
const eventData = {
|
|
6454
|
+
type: "text-delta",
|
|
6455
|
+
data: {
|
|
6456
|
+
textDelta: part.textDelta
|
|
6457
|
+
},
|
|
6458
|
+
timestamp,
|
|
6459
|
+
subAgentId: targetAgent.id,
|
|
6460
|
+
subAgentName: targetAgent.name
|
|
6461
|
+
};
|
|
6462
|
+
if (forwardEvent) {
|
|
6463
|
+
await forwardEvent(eventData);
|
|
6464
|
+
}
|
|
6465
|
+
break;
|
|
6458
6466
|
}
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6467
|
+
case "reasoning": {
|
|
6468
|
+
const eventData = {
|
|
6469
|
+
type: "reasoning",
|
|
6470
|
+
data: {
|
|
6471
|
+
reasoning: part.reasoning
|
|
6472
|
+
},
|
|
6473
|
+
timestamp,
|
|
6474
|
+
subAgentId: targetAgent.id,
|
|
6475
|
+
subAgentName: targetAgent.name
|
|
6476
|
+
};
|
|
6477
|
+
if (forwardEvent) {
|
|
6478
|
+
await forwardEvent(eventData);
|
|
6479
|
+
}
|
|
6480
|
+
break;
|
|
6473
6481
|
}
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6482
|
+
case "source": {
|
|
6483
|
+
const eventData = {
|
|
6484
|
+
type: "source",
|
|
6485
|
+
data: {
|
|
6486
|
+
source: part.source
|
|
6487
|
+
},
|
|
6488
|
+
timestamp,
|
|
6489
|
+
subAgentId: targetAgent.id,
|
|
6490
|
+
subAgentName: targetAgent.name
|
|
6491
|
+
};
|
|
6492
|
+
if (forwardEvent) {
|
|
6493
|
+
await forwardEvent(eventData);
|
|
6494
|
+
}
|
|
6495
|
+
break;
|
|
6488
6496
|
}
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6497
|
+
case "tool-call": {
|
|
6498
|
+
const eventData = {
|
|
6499
|
+
type: "tool-call",
|
|
6500
|
+
data: {
|
|
6501
|
+
toolCall: {
|
|
6502
|
+
toolCallId: part.toolCallId,
|
|
6503
|
+
toolName: part.toolName,
|
|
6504
|
+
args: part.args
|
|
6505
|
+
}
|
|
6506
|
+
},
|
|
6507
|
+
timestamp,
|
|
6508
|
+
subAgentId: targetAgent.id,
|
|
6509
|
+
subAgentName: targetAgent.name
|
|
6510
|
+
};
|
|
6511
|
+
if (forwardEvent) {
|
|
6512
|
+
await forwardEvent(eventData);
|
|
6513
|
+
}
|
|
6514
|
+
break;
|
|
6507
6515
|
}
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6516
|
+
case "tool-result": {
|
|
6517
|
+
const eventData = {
|
|
6518
|
+
type: "tool-result",
|
|
6519
|
+
data: {
|
|
6520
|
+
toolResult: {
|
|
6521
|
+
toolCallId: part.toolCallId,
|
|
6522
|
+
toolName: part.toolName,
|
|
6523
|
+
result: part.result
|
|
6524
|
+
}
|
|
6525
|
+
},
|
|
6526
|
+
timestamp,
|
|
6527
|
+
subAgentId: targetAgent.id,
|
|
6528
|
+
subAgentName: targetAgent.name
|
|
6529
|
+
};
|
|
6530
|
+
if (forwardEvent) {
|
|
6531
|
+
await forwardEvent(eventData);
|
|
6532
|
+
}
|
|
6533
|
+
break;
|
|
6526
6534
|
}
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6535
|
+
case "error": {
|
|
6536
|
+
const eventData = {
|
|
6537
|
+
type: "error",
|
|
6538
|
+
data: {
|
|
6539
|
+
error: part.error?.message || "Stream error occurred",
|
|
6540
|
+
code: "STREAM_ERROR"
|
|
6541
|
+
},
|
|
6542
|
+
timestamp,
|
|
6543
|
+
subAgentId: targetAgent.id,
|
|
6544
|
+
subAgentName: targetAgent.name
|
|
6545
|
+
};
|
|
6546
|
+
if (forwardEvent) {
|
|
6547
|
+
await forwardEvent(eventData);
|
|
6548
|
+
}
|
|
6549
|
+
break;
|
|
6542
6550
|
}
|
|
6543
|
-
break;
|
|
6544
6551
|
}
|
|
6545
6552
|
}
|
|
6553
|
+
} else {
|
|
6554
|
+
for await (const part of streamResponse.textStream) {
|
|
6555
|
+
finalText += part;
|
|
6556
|
+
}
|
|
6546
6557
|
}
|
|
6547
6558
|
return {
|
|
6548
6559
|
result: finalText,
|
|
6549
6560
|
conversationId: handoffConversationId,
|
|
6550
|
-
messages: [
|
|
6561
|
+
messages: [taskMessage, { role: "assistant", content: finalText }],
|
|
6551
6562
|
status: "success"
|
|
6552
6563
|
};
|
|
6553
6564
|
} catch (error) {
|
|
@@ -7327,7 +7338,7 @@ ${context}`;
|
|
|
7327
7338
|
});
|
|
7328
7339
|
const opContext = {
|
|
7329
7340
|
operationId: historyEntry.id,
|
|
7330
|
-
userContext: options.userContext
|
|
7341
|
+
userContext: options.userContext ?? /* @__PURE__ */ new Map(),
|
|
7331
7342
|
historyEntry,
|
|
7332
7343
|
isActive: true,
|
|
7333
7344
|
parentAgentId: options.parentAgentId,
|