@voltagent/core 1.1.32 → 1.1.34

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
@@ -4590,6 +4590,48 @@ declare class Agent {
4590
4590
  * Get Memory instance if available
4591
4591
  */
4592
4592
  getMemory(): Memory | false | undefined;
4593
+ /**
4594
+ * Convert this agent into a tool that can be used by other agents.
4595
+ * This enables supervisor/coordinator patterns where one agent can delegate
4596
+ * work to other specialized agents.
4597
+ *
4598
+ * @param options - Optional configuration for the tool
4599
+ * @param options.name - Custom name for the tool (defaults to `${agent.id}_tool`)
4600
+ * @param options.description - Custom description (defaults to agent's purpose or auto-generated)
4601
+ * @param options.parametersSchema - Custom input schema (defaults to { prompt: string })
4602
+ *
4603
+ * @returns A Tool instance that executes this agent
4604
+ *
4605
+ * @example
4606
+ * ```typescript
4607
+ * const writerAgent = new Agent({
4608
+ * id: "writer",
4609
+ * purpose: "Writes blog posts",
4610
+ * // ... other config
4611
+ * });
4612
+ *
4613
+ * const editorAgent = new Agent({
4614
+ * id: "editor",
4615
+ * purpose: "Edits content",
4616
+ * // ... other config
4617
+ * });
4618
+ *
4619
+ * // Supervisor agent that uses both as tools
4620
+ * const supervisorAgent = new Agent({
4621
+ * id: "supervisor",
4622
+ * instructions: "First call writer, then editor",
4623
+ * tools: [
4624
+ * writerAgent.toTool(),
4625
+ * editorAgent.toTool()
4626
+ * ]
4627
+ * });
4628
+ * ```
4629
+ */
4630
+ toTool(options?: {
4631
+ name?: string;
4632
+ description?: string;
4633
+ parametersSchema?: z.ZodObject<any>;
4634
+ }): Tool<any, any>;
4593
4635
  /**
4594
4636
  * Check if working memory is supported
4595
4637
  */
package/dist/index.d.ts CHANGED
@@ -4590,6 +4590,48 @@ declare class Agent {
4590
4590
  * Get Memory instance if available
4591
4591
  */
4592
4592
  getMemory(): Memory | false | undefined;
4593
+ /**
4594
+ * Convert this agent into a tool that can be used by other agents.
4595
+ * This enables supervisor/coordinator patterns where one agent can delegate
4596
+ * work to other specialized agents.
4597
+ *
4598
+ * @param options - Optional configuration for the tool
4599
+ * @param options.name - Custom name for the tool (defaults to `${agent.id}_tool`)
4600
+ * @param options.description - Custom description (defaults to agent's purpose or auto-generated)
4601
+ * @param options.parametersSchema - Custom input schema (defaults to { prompt: string })
4602
+ *
4603
+ * @returns A Tool instance that executes this agent
4604
+ *
4605
+ * @example
4606
+ * ```typescript
4607
+ * const writerAgent = new Agent({
4608
+ * id: "writer",
4609
+ * purpose: "Writes blog posts",
4610
+ * // ... other config
4611
+ * });
4612
+ *
4613
+ * const editorAgent = new Agent({
4614
+ * id: "editor",
4615
+ * purpose: "Edits content",
4616
+ * // ... other config
4617
+ * });
4618
+ *
4619
+ * // Supervisor agent that uses both as tools
4620
+ * const supervisorAgent = new Agent({
4621
+ * id: "supervisor",
4622
+ * instructions: "First call writer, then editor",
4623
+ * tools: [
4624
+ * writerAgent.toTool(),
4625
+ * editorAgent.toTool()
4626
+ * ]
4627
+ * });
4628
+ * ```
4629
+ */
4630
+ toTool(options?: {
4631
+ name?: string;
4632
+ description?: string;
4633
+ parametersSchema?: z.ZodObject<any>;
4634
+ }): Tool<any, any>;
4593
4635
  /**
4594
4636
  * Check if working memory is supported
4595
4637
  */
package/dist/index.js CHANGED
@@ -14280,20 +14280,23 @@ function toContextMap(context8) {
14280
14280
  return context8 instanceof Map ? context8 : new Map(Object.entries(context8));
14281
14281
  }
14282
14282
  __name(toContextMap, "toContextMap");
14283
- function stripExcessiveFieldsInUIMessages(uiMessages) {
14284
- function isTextUIPart(p) {
14285
- return typeof p === "object" && p !== null && p.type === "text";
14286
- }
14287
- __name(isTextUIPart, "isTextUIPart");
14288
- return uiMessages.map((msg) => {
14289
- if (!Array.isArray(msg.parts)) return msg;
14290
- const parts = msg.parts?.map(
14291
- (part) => isTextUIPart(part) ? { type: "text", text: part.text } : part
14292
- );
14293
- return { ...msg, parts };
14283
+ var convertToModelMessagesFix = /* @__PURE__ */ __name((uiMessages) => {
14284
+ return renameProviderOptions((0, import_ai4.convertToModelMessages)(uiMessages));
14285
+ }, "convertToModelMessagesFix");
14286
+ function renameProviderOptions(messages) {
14287
+ return messages.map((msg) => {
14288
+ if (!Array.isArray(msg.content)) return msg;
14289
+ const content = msg.content.map((part) => {
14290
+ if (part && typeof part === "object" && "providerOptions" in part) {
14291
+ const { providerOptions, ...rest } = part;
14292
+ return { ...rest, providerMetadata: providerOptions };
14293
+ }
14294
+ return part;
14295
+ });
14296
+ return { ...msg, content };
14294
14297
  });
14295
14298
  }
14296
- __name(stripExcessiveFieldsInUIMessages, "stripExcessiveFieldsInUIMessages");
14299
+ __name(renameProviderOptions, "renameProviderOptions");
14297
14300
  function cloneGenerateTextResultWithContext(result, overrides) {
14298
14301
  const prototype = Object.getPrototypeOf(result);
14299
14302
  const clone = Object.create(prototype);
@@ -15347,7 +15350,7 @@ var Agent = class {
15347
15350
  const buffer = this.getConversationBuffer(oc);
15348
15351
  const uiMessages = await this.prepareMessages(input, oc, options, buffer);
15349
15352
  const hooks = this.getMergedHooks(options);
15350
- let messages = (0, import_ai4.convertToModelMessages)(stripExcessiveFieldsInUIMessages(uiMessages));
15353
+ let messages = convertToModelMessagesFix(uiMessages);
15351
15354
  if (hooks.onPrepareModelMessages) {
15352
15355
  const result = await hooks.onPrepareModelMessages({
15353
15356
  modelMessages: messages,
@@ -15982,7 +15985,7 @@ ${toolkit.instructions}`;
15982
15985
  }
15983
15986
  });
15984
15987
  try {
15985
- const retrieverInput = typeof input === "string" ? input : Array.isArray(input) && input[0]?.content !== void 0 ? input : (0, import_ai4.convertToModelMessages)(stripExcessiveFieldsInUIMessages(input));
15988
+ const retrieverInput = typeof input === "string" ? input : Array.isArray(input) && input[0]?.content !== void 0 ? input : convertToModelMessagesFix(input);
15986
15989
  const retrievedContent = await oc.traceContext.withSpan(retrieverSpan, async () => {
15987
15990
  if (!this.retriever) return null;
15988
15991
  return await this.retriever.retrieve(retrieverInput, {
@@ -16612,6 +16615,68 @@ ${toolkit.instructions}`;
16612
16615
  }
16613
16616
  return this.memory ?? this.memoryManager.getMemory();
16614
16617
  }
16618
+ /**
16619
+ * Convert this agent into a tool that can be used by other agents.
16620
+ * This enables supervisor/coordinator patterns where one agent can delegate
16621
+ * work to other specialized agents.
16622
+ *
16623
+ * @param options - Optional configuration for the tool
16624
+ * @param options.name - Custom name for the tool (defaults to `${agent.id}_tool`)
16625
+ * @param options.description - Custom description (defaults to agent's purpose or auto-generated)
16626
+ * @param options.parametersSchema - Custom input schema (defaults to { prompt: string })
16627
+ *
16628
+ * @returns A Tool instance that executes this agent
16629
+ *
16630
+ * @example
16631
+ * ```typescript
16632
+ * const writerAgent = new Agent({
16633
+ * id: "writer",
16634
+ * purpose: "Writes blog posts",
16635
+ * // ... other config
16636
+ * });
16637
+ *
16638
+ * const editorAgent = new Agent({
16639
+ * id: "editor",
16640
+ * purpose: "Edits content",
16641
+ * // ... other config
16642
+ * });
16643
+ *
16644
+ * // Supervisor agent that uses both as tools
16645
+ * const supervisorAgent = new Agent({
16646
+ * id: "supervisor",
16647
+ * instructions: "First call writer, then editor",
16648
+ * tools: [
16649
+ * writerAgent.toTool(),
16650
+ * editorAgent.toTool()
16651
+ * ]
16652
+ * });
16653
+ * ```
16654
+ */
16655
+ toTool(options) {
16656
+ const toolName = options?.name || `${this.id}_tool`;
16657
+ const toolDescription = options?.description || this.purpose || `Executes the ${this.name} agent to complete a task`;
16658
+ const parametersSchema = options?.parametersSchema || import_zod3.z.object({
16659
+ prompt: import_zod3.z.string().describe("The prompt or task to send to the agent")
16660
+ });
16661
+ return createTool({
16662
+ name: toolName,
16663
+ description: toolDescription,
16664
+ parameters: parametersSchema,
16665
+ execute: /* @__PURE__ */ __name(async (args, context8) => {
16666
+ const prompt = args.prompt || args;
16667
+ const result = await this.generateText(prompt, {
16668
+ // Pass through the operation context if available
16669
+ parentOperationContext: context8,
16670
+ conversationId: context8?.conversationId,
16671
+ userId: context8?.userId
16672
+ });
16673
+ return {
16674
+ text: result.text,
16675
+ usage: result.usage
16676
+ };
16677
+ }, "execute")
16678
+ });
16679
+ }
16615
16680
  /**
16616
16681
  * Check if working memory is supported
16617
16682
  */