@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 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 handoffMessage = {
6428
- role: "system",
6429
- content: `Task handed off from ${sourceAgent?.name || this.agentName} to ${targetAgent.name}:
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
- Context: ${JSON.stringify(context)}`
6432
+
6433
+ Context: ${JSON.stringify(context, null, 2)}`;
6434
+ }
6435
+ const taskMessage = {
6436
+ role: "system",
6437
+ content: taskContent
6432
6438
  };
6433
- const forwardEvent = options.forwardEvent;
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
- for await (const part of streamResponse.fullStream) {
6443
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
6444
- switch (part.type) {
6445
- case "text-delta": {
6446
- finalText += part.textDelta;
6447
- const eventData = {
6448
- type: "text-delta",
6449
- data: {
6450
- textDelta: part.textDelta
6451
- },
6452
- timestamp,
6453
- subAgentId: targetAgent.id,
6454
- subAgentName: targetAgent.name
6455
- };
6456
- if (forwardEvent) {
6457
- await forwardEvent(eventData);
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
- break;
6460
- }
6461
- case "reasoning": {
6462
- const eventData = {
6463
- type: "reasoning",
6464
- data: {
6465
- reasoning: part.reasoning
6466
- },
6467
- timestamp,
6468
- subAgentId: targetAgent.id,
6469
- subAgentName: targetAgent.name
6470
- };
6471
- if (forwardEvent) {
6472
- await forwardEvent(eventData);
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
- break;
6475
- }
6476
- case "source": {
6477
- const eventData = {
6478
- type: "source",
6479
- data: {
6480
- source: part.source
6481
- },
6482
- timestamp,
6483
- subAgentId: targetAgent.id,
6484
- subAgentName: targetAgent.name
6485
- };
6486
- if (forwardEvent) {
6487
- await forwardEvent(eventData);
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
- break;
6490
- }
6491
- case "tool-call": {
6492
- const eventData = {
6493
- type: "tool-call",
6494
- data: {
6495
- toolCall: {
6496
- toolCallId: part.toolCallId,
6497
- toolName: part.toolName,
6498
- args: part.args
6499
- }
6500
- },
6501
- timestamp,
6502
- subAgentId: targetAgent.id,
6503
- subAgentName: targetAgent.name
6504
- };
6505
- if (forwardEvent) {
6506
- await forwardEvent(eventData);
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
- break;
6509
- }
6510
- case "tool-result": {
6511
- const eventData = {
6512
- type: "tool-result",
6513
- data: {
6514
- toolResult: {
6515
- toolCallId: part.toolCallId,
6516
- toolName: part.toolName,
6517
- result: part.result
6518
- }
6519
- },
6520
- timestamp,
6521
- subAgentId: targetAgent.id,
6522
- subAgentName: targetAgent.name
6523
- };
6524
- if (forwardEvent) {
6525
- await forwardEvent(eventData);
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
- break;
6528
- }
6529
- case "error": {
6530
- const eventData = {
6531
- type: "error",
6532
- data: {
6533
- error: part.error?.message || "Stream error occurred",
6534
- code: "STREAM_ERROR"
6535
- },
6536
- timestamp,
6537
- subAgentId: targetAgent.id,
6538
- subAgentName: targetAgent.name
6539
- };
6540
- if (forwardEvent) {
6541
- await forwardEvent(eventData);
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: [handoffMessage, { role: "assistant", content: finalText }],
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 ? new Map(options.userContext) : /* @__PURE__ */ new Map(),
7341
+ userContext: options.userContext ?? /* @__PURE__ */ new Map(),
7331
7342
  historyEntry,
7332
7343
  isActive: true,
7333
7344
  parentAgentId: options.parentAgentId,