@voltagent/core 0.1.44 → 0.1.45

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
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { Span } from '@opentelemetry/api';
3
- import { Simplify, LiteralUnion } from 'type-fest';
3
+ import { Simplify, LiteralUnion, MergeDeep } from 'type-fest';
4
4
  import { Context } from 'hono';
5
5
  import { SpanExporter } from '@opentelemetry/sdk-trace-base';
6
6
  import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
@@ -1051,15 +1051,15 @@ type AgentHandoffOptions = {
1051
1051
  * Parent history entry ID
1052
1052
  */
1053
1053
  parentHistoryEntryId?: string;
1054
- /**
1055
- * Optional user-defined context to be passed from the supervisor agent
1056
- */
1057
- userContext?: Map<string | symbol, unknown>;
1058
1054
  /**
1059
1055
  * Optional real-time event forwarder function
1060
1056
  * Used to forward SubAgent events to parent stream in real-time
1061
1057
  */
1062
1058
  forwardEvent?: (event: StreamEvent) => Promise<void>;
1059
+ /**
1060
+ * Parent's operation context to merge SubAgent steps into
1061
+ */
1062
+ parentOperationContext?: OperationContext;
1063
1063
  };
1064
1064
  /**
1065
1065
  * Result of a handoff to another agent
@@ -2873,12 +2873,17 @@ declare class SubAgentManager {
2873
2873
  */
2874
2874
  handoffToMultiple(options: Omit<AgentHandoffOptions, "targetAgent"> & {
2875
2875
  targetAgents: Agent<any>[];
2876
- userContext?: Map<string | symbol, unknown>;
2877
2876
  }): Promise<AgentHandoffResult[]>;
2878
2877
  /**
2879
- * Create a delegate tool for sub-agents
2878
+ * Creates a tool that allows the supervisor agent to delegate a
2879
+ * task to one or more specialized agents
2880
2880
  */
2881
- createDelegateTool(options?: Record<string, any>): BaseTool;
2881
+ createDelegateTool(options: MergeDeep<{
2882
+ sourceAgent: Agent<any>;
2883
+ currentHistoryEntryId?: string;
2884
+ operationContext?: OperationContext;
2885
+ forwardEvent?: (event: StreamEvent) => Promise<void>;
2886
+ }, Record<string, any>>): BaseTool;
2882
2887
  /**
2883
2888
  * Get sub-agent details for API exposure
2884
2889
  */
package/dist/index.js CHANGED
@@ -6898,15 +6898,15 @@ ${agentsMemory || "No previous agent interactions available."}
6898
6898
  async handoffTask(options) {
6899
6899
  const {
6900
6900
  task,
6901
- targetAgent,
6902
- context = {},
6903
6901
  conversationId,
6904
6902
  userId,
6905
- sourceAgent,
6906
6903
  parentAgentId,
6907
6904
  parentHistoryEntryId,
6908
- userContext
6905
+ parentOperationContext
6909
6906
  } = options;
6907
+ const context = options.context;
6908
+ const sourceAgent = options.sourceAgent;
6909
+ const targetAgent = options.targetAgent;
6910
6910
  const handoffConversationId = conversationId || crypto.randomUUID();
6911
6911
  try {
6912
6912
  if (sourceAgent && targetAgent.hooks) {
@@ -6922,15 +6922,17 @@ ${task}
6922
6922
  Context: ${JSON.stringify(context, null, 2)}`;
6923
6923
  }
6924
6924
  const taskMessage = {
6925
- role: "system",
6925
+ role: "user",
6926
6926
  content: taskContent
6927
6927
  };
6928
6928
  const streamResponse = await targetAgent.streamText([...sharedContext, taskMessage], {
6929
6929
  conversationId: handoffConversationId,
6930
6930
  userId,
6931
+ // TODO: Fix the types here
6932
+ // @ts-expect-error - bad types
6931
6933
  parentAgentId: sourceAgent?.id || parentAgentId,
6932
6934
  parentHistoryEntryId,
6933
- userContext
6935
+ parentOperationContext
6934
6936
  });
6935
6937
  let finalText = "";
6936
6938
  if (streamResponse.fullStream) {
@@ -7021,8 +7023,8 @@ Context: ${JSON.stringify(context, null, 2)}`;
7021
7023
  const eventData = {
7022
7024
  type: "error",
7023
7025
  data: {
7026
+ // @ts-expect-error - fix bad type
7024
7027
  error: part.error?.message || "Stream error occurred",
7025
- // @ts-expect-error - code is not part of the StreamEventError type currently
7026
7028
  code: "STREAM_ERROR"
7027
7029
  },
7028
7030
  timestamp,
@@ -7073,7 +7075,7 @@ Context: ${JSON.stringify(context, null, 2)}`;
7073
7075
  conversationId,
7074
7076
  parentAgentId,
7075
7077
  parentHistoryEntryId,
7076
- userContext,
7078
+ parentOperationContext,
7077
7079
  ...restOptions
7078
7080
  } = options;
7079
7081
  const handoffConversationId = conversationId || crypto.randomUUID();
@@ -7086,7 +7088,7 @@ Context: ${JSON.stringify(context, null, 2)}`;
7086
7088
  conversationId: handoffConversationId,
7087
7089
  parentAgentId,
7088
7090
  parentHistoryEntryId,
7089
- userContext
7091
+ parentOperationContext
7090
7092
  });
7091
7093
  } catch (error) {
7092
7094
  import_dev13.devLogger.error(`Error in handoffToMultiple for agent ${agent.name}:`, error);
@@ -7109,9 +7111,11 @@ Context: ${JSON.stringify(context, null, 2)}`;
7109
7111
  return results;
7110
7112
  }
7111
7113
  /**
7112
- * Create a delegate tool for sub-agents
7114
+ * Creates a tool that allows the supervisor agent to delegate a
7115
+ * task to one or more specialized agents
7113
7116
  */
7114
- createDelegateTool(options = {}) {
7117
+ createDelegateTool(options) {
7118
+ const { sourceAgent, forwardEvent, operationContext, currentHistoryEntryId, ...restOptions } = options;
7115
7119
  return createTool({
7116
7120
  id: "delegate_task",
7117
7121
  name: "delegate_task",
@@ -7143,11 +7147,6 @@ Context: ${JSON.stringify(context, null, 2)}`;
7143
7147
  `No valid target agents found. Available agents: ${this.subAgents.map((a) => a.name).join(", ")}`
7144
7148
  );
7145
7149
  }
7146
- const sourceAgent = options.sourceAgent;
7147
- const operationContext = options.operationContext;
7148
- const supervisorUserContext = operationContext?.userContext;
7149
- const currentHistoryEntryId = options.currentHistoryEntryId;
7150
- const forwardEvent = options.forwardEvent;
7151
7150
  const results = await this.handoffToMultiple({
7152
7151
  task,
7153
7152
  targetAgents: agents,
@@ -7155,12 +7154,13 @@ Context: ${JSON.stringify(context, null, 2)}`;
7155
7154
  sourceAgent,
7156
7155
  // Pass parent context for event propagation
7157
7156
  parentAgentId: sourceAgent?.id,
7157
+ // Get current history entry ID for parent context
7158
+ // This is passed from the Agent class via options when the tool is called
7158
7159
  parentHistoryEntryId: currentHistoryEntryId,
7159
- // Pass the supervisor's userContext to the handoff options
7160
- userContext: supervisorUserContext,
7160
+ parentOperationContext: operationContext,
7161
7161
  // Pass the real-time event forwarder
7162
7162
  forwardEvent,
7163
- ...options
7163
+ ...restOptions
7164
7164
  });
7165
7165
  const structuredResults = results.map((result, index) => {
7166
7166
  const status = result.status || "success";
@@ -7663,13 +7663,14 @@ ${context}`;
7663
7663
  });
7664
7664
  const opContext = {
7665
7665
  operationId: historyEntry.id,
7666
- userContext: options.userContext ?? /* @__PURE__ */ new Map(),
7666
+ userContext: (options.parentOperationContext?.userContext || options.userContext) ?? /* @__PURE__ */ new Map(),
7667
7667
  historyEntry,
7668
7668
  isActive: true,
7669
7669
  parentAgentId: options.parentAgentId,
7670
7670
  parentHistoryEntryId: options.parentHistoryEntryId,
7671
7671
  otelSpan,
7672
- conversationSteps: []
7672
+ // Use parent's conversationSteps if available (for SubAgents), otherwise create new array
7673
+ conversationSteps: options.parentOperationContext?.conversationSteps || []
7673
7674
  };
7674
7675
  return opContext;
7675
7676
  }
@@ -7850,6 +7851,7 @@ ${context}`;
7850
7851
  conversationId: initialConversationId,
7851
7852
  parentAgentId,
7852
7853
  parentHistoryEntryId,
7854
+ parentOperationContext,
7853
7855
  contextLimit = 10,
7854
7856
  userContext
7855
7857
  } = internalOptions;
@@ -7859,7 +7861,8 @@ ${context}`;
7859
7861
  operationName: "generateText",
7860
7862
  userContext,
7861
7863
  userId,
7862
- conversationId: initialConversationId
7864
+ conversationId: initialConversationId,
7865
+ parentOperationContext
7863
7866
  });
7864
7867
  const { messages: contextMessages, conversationId: finalConversationId } = await this.memoryManager.prepareConversationContext(
7865
7868
  operationContext,
@@ -8194,6 +8197,7 @@ ${context}`;
8194
8197
  conversationId: initialConversationId,
8195
8198
  parentAgentId,
8196
8199
  parentHistoryEntryId,
8200
+ parentOperationContext,
8197
8201
  contextLimit = 10,
8198
8202
  userContext
8199
8203
  } = internalOptions;
@@ -8203,7 +8207,8 @@ ${context}`;
8203
8207
  operationName: "streamText",
8204
8208
  userContext,
8205
8209
  userId,
8206
- conversationId: initialConversationId
8210
+ conversationId: initialConversationId,
8211
+ parentOperationContext
8207
8212
  });
8208
8213
  const { messages: contextMessages, conversationId: finalConversationId } = await this.memoryManager.prepareConversationContext(
8209
8214
  operationContext,
@@ -8637,6 +8642,7 @@ ${context}`;
8637
8642
  conversationId: initialConversationId,
8638
8643
  parentAgentId,
8639
8644
  parentHistoryEntryId,
8645
+ parentOperationContext,
8640
8646
  contextLimit = 10,
8641
8647
  userContext
8642
8648
  } = internalOptions;
@@ -8646,7 +8652,8 @@ ${context}`;
8646
8652
  operationName: "generateObject",
8647
8653
  userContext,
8648
8654
  userId,
8649
- conversationId: initialConversationId
8655
+ conversationId: initialConversationId,
8656
+ parentOperationContext
8650
8657
  });
8651
8658
  const { messages: contextMessages, conversationId: finalConversationId } = await this.memoryManager.prepareConversationContext(
8652
8659
  operationContext,
@@ -8866,6 +8873,7 @@ ${context}`;
8866
8873
  conversationId: initialConversationId,
8867
8874
  parentAgentId,
8868
8875
  parentHistoryEntryId,
8876
+ parentOperationContext,
8869
8877
  provider,
8870
8878
  contextLimit = 10,
8871
8879
  userContext
@@ -8876,7 +8884,8 @@ ${context}`;
8876
8884
  operationName: "streamObject",
8877
8885
  userContext,
8878
8886
  userId,
8879
- conversationId: initialConversationId
8887
+ conversationId: initialConversationId,
8888
+ parentOperationContext
8880
8889
  });
8881
8890
  const { messages: contextMessages, conversationId: finalConversationId } = await this.memoryManager.prepareConversationContext(
8882
8891
  operationContext,