@voltagent/core 1.1.33 → 1.1.35

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
@@ -3514,6 +3514,14 @@ declare class AgentTraceContext {
3514
3514
  cachedTokens?: number;
3515
3515
  reasoningTokens?: number;
3516
3516
  }): void;
3517
+ /**
3518
+ * Set finish reason on the root span
3519
+ */
3520
+ setFinishReason(finishReason: string | null | undefined): void;
3521
+ /**
3522
+ * Set stop condition metadata when maxSteps is reached
3523
+ */
3524
+ setStopConditionMet(stepCount: number, maxSteps: number): void;
3517
3525
  /**
3518
3526
  * End the root span with a status
3519
3527
  */
@@ -4590,6 +4598,48 @@ declare class Agent {
4590
4598
  * Get Memory instance if available
4591
4599
  */
4592
4600
  getMemory(): Memory | false | undefined;
4601
+ /**
4602
+ * Convert this agent into a tool that can be used by other agents.
4603
+ * This enables supervisor/coordinator patterns where one agent can delegate
4604
+ * work to other specialized agents.
4605
+ *
4606
+ * @param options - Optional configuration for the tool
4607
+ * @param options.name - Custom name for the tool (defaults to `${agent.id}_tool`)
4608
+ * @param options.description - Custom description (defaults to agent's purpose or auto-generated)
4609
+ * @param options.parametersSchema - Custom input schema (defaults to { prompt: string })
4610
+ *
4611
+ * @returns A Tool instance that executes this agent
4612
+ *
4613
+ * @example
4614
+ * ```typescript
4615
+ * const writerAgent = new Agent({
4616
+ * id: "writer",
4617
+ * purpose: "Writes blog posts",
4618
+ * // ... other config
4619
+ * });
4620
+ *
4621
+ * const editorAgent = new Agent({
4622
+ * id: "editor",
4623
+ * purpose: "Edits content",
4624
+ * // ... other config
4625
+ * });
4626
+ *
4627
+ * // Supervisor agent that uses both as tools
4628
+ * const supervisorAgent = new Agent({
4629
+ * id: "supervisor",
4630
+ * instructions: "First call writer, then editor",
4631
+ * tools: [
4632
+ * writerAgent.toTool(),
4633
+ * editorAgent.toTool()
4634
+ * ]
4635
+ * });
4636
+ * ```
4637
+ */
4638
+ toTool(options?: {
4639
+ name?: string;
4640
+ description?: string;
4641
+ parametersSchema?: z.ZodObject<any>;
4642
+ }): Tool<any, any>;
4593
4643
  /**
4594
4644
  * Check if working memory is supported
4595
4645
  */
package/dist/index.d.ts CHANGED
@@ -3514,6 +3514,14 @@ declare class AgentTraceContext {
3514
3514
  cachedTokens?: number;
3515
3515
  reasoningTokens?: number;
3516
3516
  }): void;
3517
+ /**
3518
+ * Set finish reason on the root span
3519
+ */
3520
+ setFinishReason(finishReason: string | null | undefined): void;
3521
+ /**
3522
+ * Set stop condition metadata when maxSteps is reached
3523
+ */
3524
+ setStopConditionMet(stepCount: number, maxSteps: number): void;
3517
3525
  /**
3518
3526
  * End the root span with a status
3519
3527
  */
@@ -4590,6 +4598,48 @@ declare class Agent {
4590
4598
  * Get Memory instance if available
4591
4599
  */
4592
4600
  getMemory(): Memory | false | undefined;
4601
+ /**
4602
+ * Convert this agent into a tool that can be used by other agents.
4603
+ * This enables supervisor/coordinator patterns where one agent can delegate
4604
+ * work to other specialized agents.
4605
+ *
4606
+ * @param options - Optional configuration for the tool
4607
+ * @param options.name - Custom name for the tool (defaults to `${agent.id}_tool`)
4608
+ * @param options.description - Custom description (defaults to agent's purpose or auto-generated)
4609
+ * @param options.parametersSchema - Custom input schema (defaults to { prompt: string })
4610
+ *
4611
+ * @returns A Tool instance that executes this agent
4612
+ *
4613
+ * @example
4614
+ * ```typescript
4615
+ * const writerAgent = new Agent({
4616
+ * id: "writer",
4617
+ * purpose: "Writes blog posts",
4618
+ * // ... other config
4619
+ * });
4620
+ *
4621
+ * const editorAgent = new Agent({
4622
+ * id: "editor",
4623
+ * purpose: "Edits content",
4624
+ * // ... other config
4625
+ * });
4626
+ *
4627
+ * // Supervisor agent that uses both as tools
4628
+ * const supervisorAgent = new Agent({
4629
+ * id: "supervisor",
4630
+ * instructions: "First call writer, then editor",
4631
+ * tools: [
4632
+ * writerAgent.toTool(),
4633
+ * editorAgent.toTool()
4634
+ * ]
4635
+ * });
4636
+ * ```
4637
+ */
4638
+ toTool(options?: {
4639
+ name?: string;
4640
+ description?: string;
4641
+ parametersSchema?: z.ZodObject<any>;
4642
+ }): Tool<any, any>;
4593
4643
  /**
4594
4644
  * Check if working memory is supported
4595
4645
  */
package/dist/index.js CHANGED
@@ -11251,6 +11251,24 @@ var AgentTraceContext = class {
11251
11251
  this.rootSpan.setAttribute("usage.reasoning_tokens", usage.reasoningTokens);
11252
11252
  }
11253
11253
  }
11254
+ /**
11255
+ * Set finish reason on the root span
11256
+ */
11257
+ setFinishReason(finishReason) {
11258
+ if (finishReason !== null && finishReason !== void 0) {
11259
+ this.rootSpan.setAttribute("ai.response.finish_reason", finishReason);
11260
+ }
11261
+ }
11262
+ /**
11263
+ * Set stop condition metadata when maxSteps is reached
11264
+ */
11265
+ setStopConditionMet(stepCount, maxSteps) {
11266
+ this.rootSpan.setAttributes({
11267
+ "voltagent.stopped_by_max_steps": true,
11268
+ "voltagent.step_count": stepCount,
11269
+ "voltagent.max_steps": maxSteps
11270
+ });
11271
+ }
11254
11272
  /**
11255
11273
  * End the root span with a status
11256
11274
  */
@@ -14553,6 +14571,10 @@ var Agent = class {
14553
14571
  );
14554
14572
  this.setTraceContextUsage(oc.traceContext, result.usage);
14555
14573
  oc.traceContext.setOutput(finalText);
14574
+ oc.traceContext.setFinishReason(result.finishReason);
14575
+ if (result.steps && result.steps.length >= maxSteps) {
14576
+ oc.traceContext.setStopConditionMet(result.steps.length, maxSteps);
14577
+ }
14556
14578
  oc.output = finalText;
14557
14579
  this.enqueueEvalScoring({
14558
14580
  oc,
@@ -14713,6 +14735,11 @@ var Agent = class {
14713
14735
  }
14714
14736
  const guardrailedResult = guardrailSet.output.length > 0 ? { ...finalResult, text: finalText } : finalResult;
14715
14737
  oc.traceContext.setOutput(finalText);
14738
+ oc.traceContext.setFinishReason(finalResult.finishReason);
14739
+ const steps = finalResult.steps;
14740
+ if (steps && steps.length >= maxSteps) {
14741
+ oc.traceContext.setStopConditionMet(steps.length, maxSteps);
14742
+ }
14716
14743
  oc.output = finalText;
14717
14744
  await this.getMergedHooks(options).onEnd?.({
14718
14745
  conversationId: oc.conversationId || "",
@@ -16615,6 +16642,68 @@ ${toolkit.instructions}`;
16615
16642
  }
16616
16643
  return this.memory ?? this.memoryManager.getMemory();
16617
16644
  }
16645
+ /**
16646
+ * Convert this agent into a tool that can be used by other agents.
16647
+ * This enables supervisor/coordinator patterns where one agent can delegate
16648
+ * work to other specialized agents.
16649
+ *
16650
+ * @param options - Optional configuration for the tool
16651
+ * @param options.name - Custom name for the tool (defaults to `${agent.id}_tool`)
16652
+ * @param options.description - Custom description (defaults to agent's purpose or auto-generated)
16653
+ * @param options.parametersSchema - Custom input schema (defaults to { prompt: string })
16654
+ *
16655
+ * @returns A Tool instance that executes this agent
16656
+ *
16657
+ * @example
16658
+ * ```typescript
16659
+ * const writerAgent = new Agent({
16660
+ * id: "writer",
16661
+ * purpose: "Writes blog posts",
16662
+ * // ... other config
16663
+ * });
16664
+ *
16665
+ * const editorAgent = new Agent({
16666
+ * id: "editor",
16667
+ * purpose: "Edits content",
16668
+ * // ... other config
16669
+ * });
16670
+ *
16671
+ * // Supervisor agent that uses both as tools
16672
+ * const supervisorAgent = new Agent({
16673
+ * id: "supervisor",
16674
+ * instructions: "First call writer, then editor",
16675
+ * tools: [
16676
+ * writerAgent.toTool(),
16677
+ * editorAgent.toTool()
16678
+ * ]
16679
+ * });
16680
+ * ```
16681
+ */
16682
+ toTool(options) {
16683
+ const toolName = options?.name || `${this.id}_tool`;
16684
+ const toolDescription = options?.description || this.purpose || `Executes the ${this.name} agent to complete a task`;
16685
+ const parametersSchema = options?.parametersSchema || import_zod3.z.object({
16686
+ prompt: import_zod3.z.string().describe("The prompt or task to send to the agent")
16687
+ });
16688
+ return createTool({
16689
+ name: toolName,
16690
+ description: toolDescription,
16691
+ parameters: parametersSchema,
16692
+ execute: /* @__PURE__ */ __name(async (args, context8) => {
16693
+ const prompt = args.prompt || args;
16694
+ const result = await this.generateText(prompt, {
16695
+ // Pass through the operation context if available
16696
+ parentOperationContext: context8,
16697
+ conversationId: context8?.conversationId,
16698
+ userId: context8?.userId
16699
+ });
16700
+ return {
16701
+ text: result.text,
16702
+ usage: result.usage
16703
+ };
16704
+ }, "execute")
16705
+ });
16706
+ }
16618
16707
  /**
16619
16708
  * Check if working memory is supported
16620
16709
  */