@voltagent/core 0.1.15 → 0.1.17

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.ts CHANGED
@@ -457,6 +457,10 @@ type AgentOptions = {
457
457
  * Sub-agents that this agent can delegate tasks to
458
458
  */
459
459
  subAgents?: any[];
460
+ /**
461
+ * Optional user-defined context to be passed around
462
+ */
463
+ userContext?: Map<string | symbol, unknown>;
460
464
  } & ({
461
465
  /**
462
466
  * @deprecated Use `instructions` instead.
@@ -528,6 +532,7 @@ interface CommonGenerateOptions {
528
532
  signal?: AbortSignal;
529
533
  historyEntryId?: string;
530
534
  operationContext?: OperationContext;
535
+ userContext?: Map<string | symbol, unknown>;
531
536
  }
532
537
  /**
533
538
  * Public-facing generate options for external users
@@ -623,6 +628,10 @@ type AgentHandoffOptions = {
623
628
  * Parent history entry ID
624
629
  */
625
630
  parentHistoryEntryId?: string;
631
+ /**
632
+ * Optional user-defined context to be passed from the supervisor agent
633
+ */
634
+ userContext?: Map<string | symbol, unknown>;
626
635
  };
627
636
  /**
628
637
  * Result of a handoff to another agent
@@ -1805,6 +1814,7 @@ declare class SubAgentManager {
1805
1814
  */
1806
1815
  handoffToMultiple(options: Omit<AgentHandoffOptions, "targetAgent"> & {
1807
1816
  targetAgents: Agent<any>[];
1817
+ userContext?: Map<string | symbol, unknown>;
1808
1818
  }): Promise<AgentHandoffResult[]>;
1809
1819
  /**
1810
1820
  * Create a delegate tool for sub-agents
package/dist/index.js CHANGED
@@ -4380,7 +4380,8 @@ ${agentsMemory || "No previous agent interactions available."}
4380
4380
  userId,
4381
4381
  sourceAgent,
4382
4382
  parentAgentId,
4383
- parentHistoryEntryId
4383
+ parentHistoryEntryId,
4384
+ userContext
4384
4385
  } = options;
4385
4386
  const handoffConversationId = conversationId || crypto.randomUUID();
4386
4387
  try {
@@ -4398,7 +4399,8 @@ Context: ${JSON.stringify(context)}`
4398
4399
  conversationId: handoffConversationId,
4399
4400
  userId,
4400
4401
  parentAgentId: (sourceAgent == null ? void 0 : sourceAgent.id) || parentAgentId,
4401
- parentHistoryEntryId
4402
+ parentHistoryEntryId,
4403
+ userContext
4402
4404
  });
4403
4405
  return {
4404
4406
  result: response.text,
@@ -4429,7 +4431,19 @@ Context: ${JSON.stringify(context)}`
4429
4431
  */
4430
4432
  handoffToMultiple(options) {
4431
4433
  return __async(this, null, function* () {
4432
- const _a = options, { targetAgents, conversationId, parentAgentId, parentHistoryEntryId } = _a, restOptions = __objRest(_a, ["targetAgents", "conversationId", "parentAgentId", "parentHistoryEntryId"]);
4434
+ const _a = options, {
4435
+ targetAgents,
4436
+ conversationId,
4437
+ parentAgentId,
4438
+ parentHistoryEntryId,
4439
+ userContext
4440
+ } = _a, restOptions = __objRest(_a, [
4441
+ "targetAgents",
4442
+ "conversationId",
4443
+ "parentAgentId",
4444
+ "parentHistoryEntryId",
4445
+ "userContext"
4446
+ ]);
4433
4447
  const handoffConversationId = conversationId || crypto.randomUUID();
4434
4448
  const results = yield Promise.all(
4435
4449
  targetAgents.map((agent) => __async(this, null, function* () {
@@ -4438,7 +4452,8 @@ Context: ${JSON.stringify(context)}`
4438
4452
  targetAgent: agent,
4439
4453
  conversationId: handoffConversationId,
4440
4454
  parentAgentId,
4441
- parentHistoryEntryId
4455
+ parentHistoryEntryId,
4456
+ userContext
4442
4457
  }));
4443
4458
  } catch (error) {
4444
4459
  console.error(`Error in handoffToMultiple for agent ${agent.name}:`, error);
@@ -4497,6 +4512,8 @@ Context: ${JSON.stringify(context)}`
4497
4512
  );
4498
4513
  }
4499
4514
  const sourceAgent = options.sourceAgent;
4515
+ const operationContext = options.operationContext;
4516
+ const supervisorUserContext = operationContext == null ? void 0 : operationContext.userContext;
4500
4517
  const currentHistoryEntryId = options.currentHistoryEntryId;
4501
4518
  const results = yield this.handoffToMultiple(__spreadValues({
4502
4519
  task,
@@ -4505,7 +4522,9 @@ Context: ${JSON.stringify(context)}`
4505
4522
  sourceAgent,
4506
4523
  // Pass parent context for event propagation
4507
4524
  parentAgentId: sourceAgent == null ? void 0 : sourceAgent.id,
4508
- parentHistoryEntryId: currentHistoryEntryId
4525
+ parentHistoryEntryId: currentHistoryEntryId,
4526
+ // Pass the supervisor's userContext to the handoff options
4527
+ userContext: supervisorUserContext
4509
4528
  }, options));
4510
4529
  return results.map((result, index) => {
4511
4530
  const status = result.status || "success";
@@ -5137,7 +5156,7 @@ ${context}`;
5137
5156
  });
5138
5157
  const opContext = {
5139
5158
  operationId: historyEntry.id,
5140
- userContext: /* @__PURE__ */ new Map(),
5159
+ userContext: options.userContext ? new Map(options.userContext) : /* @__PURE__ */ new Map(),
5141
5160
  historyEntry,
5142
5161
  eventUpdaters: /* @__PURE__ */ new Map(),
5143
5162
  isActive: true,
@@ -5240,12 +5259,14 @@ ${context}`;
5240
5259
  conversationId: initialConversationId,
5241
5260
  parentAgentId,
5242
5261
  parentHistoryEntryId,
5243
- contextLimit = 10
5262
+ contextLimit = 10,
5263
+ userContext
5244
5264
  } = internalOptions;
5245
5265
  const operationContext = yield this.initializeHistory(input, "working", {
5246
5266
  parentAgentId,
5247
5267
  parentHistoryEntryId,
5248
- operationName: "generateText"
5268
+ operationName: "generateText",
5269
+ userContext
5249
5270
  });
5250
5271
  const { messages: contextMessages, conversationId: finalConversationId } = yield this.memoryManager.prepareConversationContext(
5251
5272
  operationContext,
@@ -5438,12 +5459,14 @@ ${context}`;
5438
5459
  conversationId: initialConversationId,
5439
5460
  parentAgentId,
5440
5461
  parentHistoryEntryId,
5441
- contextLimit = 10
5462
+ contextLimit = 10,
5463
+ userContext
5442
5464
  } = internalOptions;
5443
5465
  const operationContext = yield this.initializeHistory(input, "working", {
5444
5466
  parentAgentId,
5445
5467
  parentHistoryEntryId,
5446
- operationName: "streamText"
5468
+ operationName: "streamText",
5469
+ userContext
5447
5470
  });
5448
5471
  const { messages: contextMessages, conversationId: finalConversationId } = yield this.memoryManager.prepareConversationContext(
5449
5472
  operationContext,
@@ -5687,12 +5710,14 @@ ${context}`;
5687
5710
  conversationId: initialConversationId,
5688
5711
  parentAgentId,
5689
5712
  parentHistoryEntryId,
5690
- contextLimit = 10
5713
+ contextLimit = 10,
5714
+ userContext
5691
5715
  } = internalOptions;
5692
5716
  const operationContext = yield this.initializeHistory(input, "working", {
5693
5717
  parentAgentId,
5694
5718
  parentHistoryEntryId,
5695
- operationName: "generateObject"
5719
+ operationName: "generateObject",
5720
+ userContext
5696
5721
  });
5697
5722
  const { messages: contextMessages, conversationId: finalConversationId } = yield this.memoryManager.prepareConversationContext(
5698
5723
  operationContext,
@@ -5823,12 +5848,14 @@ ${context}`;
5823
5848
  parentAgentId,
5824
5849
  parentHistoryEntryId,
5825
5850
  provider,
5826
- contextLimit = 10
5851
+ contextLimit = 10,
5852
+ userContext
5827
5853
  } = internalOptions;
5828
5854
  const operationContext = yield this.initializeHistory(input, "working", {
5829
5855
  parentAgentId,
5830
5856
  parentHistoryEntryId,
5831
- operationName: "streamObject"
5857
+ operationName: "streamObject",
5858
+ userContext
5832
5859
  });
5833
5860
  const { messages: contextMessages, conversationId: finalConversationId } = yield this.memoryManager.prepareConversationContext(
5834
5861
  operationContext,