@voltagent/core 2.3.7 → 2.3.8

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 CHANGED
@@ -9233,6 +9233,7 @@ declare class Agent {
9233
9233
  * Enrich instructions with additional context and modifiers
9234
9234
  */
9235
9235
  private enrichInstructions;
9236
+ private extractToolkits;
9236
9237
  /**
9237
9238
  * Prepare agents memory for supervisor
9238
9239
  */
package/dist/index.d.ts CHANGED
@@ -9233,6 +9233,7 @@ declare class Agent {
9233
9233
  * Enrich instructions with additional context and modifiers
9234
9234
  */
9235
9235
  private enrichInstructions;
9236
+ private extractToolkits;
9236
9237
  /**
9237
9238
  * Prepare agents memory for supervisor
9238
9239
  */
package/dist/index.js CHANGED
@@ -9115,8 +9115,8 @@ var WorkflowRegistry = class _WorkflowRegistry extends SimpleEventEmitter {
9115
9115
  this.logger.trace(`Added suspension controller for resumed execution ${executionId}`);
9116
9116
  const resumeOptions = {
9117
9117
  executionId,
9118
- userId: workflowState.metadata?.userId,
9119
- conversationId: workflowState.metadata?.conversationId,
9118
+ userId: workflowState.userId ?? workflowState.metadata?.userId,
9119
+ conversationId: workflowState.conversationId ?? workflowState.metadata?.conversationId,
9120
9120
  suspendController,
9121
9121
  resumeFrom: {
9122
9122
  executionId,
@@ -9139,7 +9139,10 @@ var WorkflowRegistry = class _WorkflowRegistry extends SimpleEventEmitter {
9139
9139
  }
9140
9140
  this.logger.debug(`Resuming workflow from step ${resumeOptions.resumeFrom.resumeStepIndex}`);
9141
9141
  try {
9142
- const inputToUse = workflowState.input;
9142
+ const workflowStartEventInput = workflowState.events?.find(
9143
+ (event) => event.type === "workflow-start"
9144
+ )?.input;
9145
+ const inputToUse = workflowState.input ?? workflowStartEventInput;
9143
9146
  if (resumeData !== void 0) {
9144
9147
  resumeOptions.resumeFrom = {
9145
9148
  ...resumeOptions.resumeFrom,
@@ -9755,6 +9758,8 @@ function createWorkflow({
9755
9758
  input: input2,
9756
9759
  context: options?.context ? Array.from(options.context.entries()) : void 0,
9757
9760
  workflowState: workflowStateStore,
9761
+ userId: options?.userId,
9762
+ conversationId: options?.conversationId,
9758
9763
  metadata: {
9759
9764
  traceId: rootSpan.spanContext().traceId,
9760
9765
  spanId: rootSpan.spanContext().spanId
@@ -30016,8 +30021,12 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
30016
30021
  * Common preparation for all execution methods
30017
30022
  */
30018
30023
  async prepareExecution(input, oc, options) {
30024
+ const dynamicToolList = await this.resolveValue(this.dynamicTools, oc) || [];
30025
+ const optionToolsArray = options?.tools || [];
30026
+ const adHocTools = [...dynamicToolList, ...optionToolsArray];
30027
+ const runtimeToolkits = this.extractToolkits(adHocTools);
30019
30028
  const buffer = this.getConversationBuffer(oc);
30020
- const uiMessages = await this.prepareMessages(input, oc, options, buffer);
30029
+ const uiMessages = await this.prepareMessages(input, oc, options, buffer, runtimeToolkits);
30021
30030
  const hooks = this.getMergedHooks(options);
30022
30031
  let messages = await (0, import_ai7.convertToModelMessages)(uiMessages);
30023
30032
  if (hooks.onPrepareModelMessages) {
@@ -30034,9 +30043,6 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
30034
30043
  messages = stripDanglingOpenAIReasoningFromModelMessages(messages);
30035
30044
  const maxSteps = options?.maxSteps ?? this.calculateMaxSteps();
30036
30045
  const modelName = this.getModelName();
30037
- const dynamicToolList = await this.resolveValue(this.dynamicTools, oc) || [];
30038
- const optionToolsArray = options?.tools || [];
30039
- const adHocTools = [...dynamicToolList, ...optionToolsArray];
30040
30046
  const tools = await this.prepareTools(adHocTools, oc, maxSteps, options);
30041
30047
  return {
30042
30048
  messages,
@@ -30607,10 +30613,10 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
30607
30613
  * Prepare messages with system prompt and memory
30608
30614
  */
30609
30615
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: legacy message preparation pipeline
30610
- async prepareMessages(input, oc, options, buffer) {
30616
+ async prepareMessages(input, oc, options, buffer, runtimeToolkits = []) {
30611
30617
  const resolvedInput = await this.validateIncomingUIMessages(input, oc);
30612
30618
  const messages = [];
30613
- const systemMessage = await this.getSystemMessage(resolvedInput, oc, options);
30619
+ const systemMessage = await this.getSystemMessage(resolvedInput, oc, options, runtimeToolkits);
30614
30620
  if (systemMessage) {
30615
30621
  const systemMessagesAsUI = (() => {
30616
30622
  if (typeof systemMessage === "string") {
@@ -30805,7 +30811,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
30805
30811
  * Get system message with dynamic instructions and retriever context
30806
30812
  */
30807
30813
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: legacy system message assembly
30808
- async getSystemMessage(input, oc, options) {
30814
+ async getSystemMessage(input, oc, options, runtimeToolkits = []) {
30809
30815
  const promptHelper = VoltOpsClient.createPromptHelperWithFallback(
30810
30816
  this.id,
30811
30817
  this.name,
@@ -30930,7 +30936,8 @@ ${additionalContext}`
30930
30936
  baseContent2,
30931
30937
  retrieverContext,
30932
30938
  workingMemoryContext,
30933
- oc
30939
+ oc,
30940
+ runtimeToolkits
30934
30941
  );
30935
30942
  return {
30936
30943
  role: "system",
@@ -30943,7 +30950,8 @@ ${additionalContext}`
30943
30950
  baseContent,
30944
30951
  retrieverContext,
30945
30952
  workingMemoryContext,
30946
- oc
30953
+ oc,
30954
+ runtimeToolkits
30947
30955
  );
30948
30956
  return {
30949
30957
  role: "system",
@@ -30953,8 +30961,30 @@ ${additionalContext}`
30953
30961
  /**
30954
30962
  * Add toolkit instructions
30955
30963
  */
30956
- addToolkitInstructions(baseInstructions) {
30957
- const toolkits = this.toolManager.getToolkits();
30964
+ addToolkitInstructions(baseInstructions, runtimeToolkits = []) {
30965
+ const toolkits = this.toolManager.getToolkits().map((toolkit) => ({
30966
+ name: toolkit.name,
30967
+ instructions: toolkit.instructions,
30968
+ addInstructions: toolkit.addInstructions
30969
+ }));
30970
+ const toolkitIndexByName = /* @__PURE__ */ new Map();
30971
+ for (const [index, toolkit] of toolkits.entries()) {
30972
+ toolkitIndexByName.set(toolkit.name, index);
30973
+ }
30974
+ for (const runtimeToolkit of runtimeToolkits) {
30975
+ const runtimeToolkitSource = {
30976
+ name: runtimeToolkit.name,
30977
+ instructions: runtimeToolkit.instructions,
30978
+ addInstructions: runtimeToolkit.addInstructions
30979
+ };
30980
+ const existingIndex = toolkitIndexByName.get(runtimeToolkit.name);
30981
+ if (existingIndex === void 0) {
30982
+ toolkitIndexByName.set(runtimeToolkit.name, toolkits.length);
30983
+ toolkits.push(runtimeToolkitSource);
30984
+ continue;
30985
+ }
30986
+ toolkits[existingIndex] = runtimeToolkitSource;
30987
+ }
30958
30988
  let toolInstructions = "";
30959
30989
  for (const toolkit of toolkits) {
30960
30990
  if (toolkit.addInstructions && toolkit.instructions) {
@@ -30968,9 +30998,9 @@ ${toolkit.instructions}`;
30968
30998
  /**
30969
30999
  * Enrich instructions with additional context and modifiers
30970
31000
  */
30971
- async enrichInstructions(baseContent, retrieverContext, workingMemoryContext, oc) {
31001
+ async enrichInstructions(baseContent, retrieverContext, workingMemoryContext, oc, runtimeToolkits = []) {
30972
31002
  let content = baseContent;
30973
- content = this.addToolkitInstructions(content);
31003
+ content = this.addToolkitInstructions(content, runtimeToolkits);
30974
31004
  if (this.markdown) {
30975
31005
  content = `${content}
30976
31006
 
@@ -30995,6 +31025,11 @@ ${retrieverContext}`;
30995
31025
  }
30996
31026
  return content;
30997
31027
  }
31028
+ extractToolkits(items) {
31029
+ return items.filter(
31030
+ (item) => typeof item === "object" && item !== null && "tools" in item && Array.isArray(item.tools)
31031
+ );
31032
+ }
30998
31033
  /**
30999
31034
  * Prepare agents memory for supervisor
31000
31035
  */