@opperai/agents 0.7.1 → 0.8.0

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.cjs CHANGED
@@ -945,6 +945,10 @@ var BaseAgent = class {
945
945
  * Whether streaming is enabled
946
946
  */
947
947
  enableStreaming;
948
+ /**
949
+ * Whether to execute tool calls in parallel
950
+ */
951
+ parallelToolExecution;
948
952
  /**
949
953
  * Memory instance for persistent storage (null if disabled or initialization failed)
950
954
  */
@@ -1009,6 +1013,7 @@ var BaseAgent = class {
1009
1013
  this.outputSchema = config.outputSchema;
1010
1014
  this.enableMemory = config.enableMemory ?? false;
1011
1015
  this.enableStreaming = config.enableStreaming ?? false;
1016
+ this.parallelToolExecution = config.parallelToolExecution ?? false;
1012
1017
  this.metadata = { ...config.metadata ?? {} };
1013
1018
  this.hooks = new HookManager();
1014
1019
  this.tools = /* @__PURE__ */ new Map();
@@ -1656,7 +1661,7 @@ var mergeSchemaDefaults = (schema, value) => {
1656
1661
 
1657
1662
  // package.json
1658
1663
  var package_default = {
1659
- version: "0.7.1"};
1664
+ version: "0.8.0"};
1660
1665
 
1661
1666
  // src/utils/version.ts
1662
1667
  var SDK_NAME = "@opperai/agents";
@@ -2648,89 +2653,105 @@ The memory you write persists across all process() calls on this agent.`;
2648
2653
  return [];
2649
2654
  }
2650
2655
  this.log(`Executing ${decision.toolCalls.length} tool call(s)`);
2656
+ if (this.parallelToolExecution && decision.toolCalls.length > 1) {
2657
+ this.log("Executing tool calls in parallel");
2658
+ return Promise.all(
2659
+ decision.toolCalls.map(
2660
+ (toolCall) => this.executeSingleToolCall(toolCall, context, parentSpanId)
2661
+ )
2662
+ );
2663
+ }
2651
2664
  const results = [];
2652
2665
  for (const toolCall of decision.toolCalls) {
2653
- this.log(`Action: ${toolCall.toolName}`, {
2654
- parameters: toolCall.arguments
2655
- });
2656
- const startTime = /* @__PURE__ */ new Date();
2657
- const tool2 = this.tools.get(toolCall.toolName);
2658
- const isAgentTool = tool2?.metadata?.["isAgent"] === true;
2659
- const spanType = isAgentTool ? "\u{1F916} agent" : "\u{1F527} tool";
2660
- const toolSpan = await this.opperClient.createSpan({
2661
- name: `tool_${toolCall.toolName}`,
2662
- input: toolCall.arguments,
2663
- type: spanType,
2664
- ...parentSpanId ? { parentSpanId } : context.parentSpanId ? { parentSpanId: context.parentSpanId } : {}
2665
- });
2666
- try {
2667
- const result = await this.executeTool(
2668
- toolCall.toolName,
2669
- toolCall.arguments,
2670
- context,
2671
- { spanId: toolSpan.id }
2672
- );
2673
- if (result.usage) {
2674
- context.updateUsageWithSource(toolCall.toolName, result.usage);
2675
- }
2676
- const endTime = /* @__PURE__ */ new Date();
2677
- const durationMs = endTime.getTime() - startTime.getTime();
2678
- if (result.success) {
2679
- this.queueSpanUpdate(context, {
2680
- spanId: toolSpan.id,
2681
- output: result.output,
2682
- startTime,
2683
- endTime,
2684
- meta: { durationMs }
2685
- });
2686
- } else {
2687
- this.queueSpanUpdate(context, {
2688
- spanId: toolSpan.id,
2689
- error: result.error instanceof Error ? result.error.message : String(result.error),
2690
- startTime,
2691
- endTime,
2692
- meta: { durationMs }
2693
- });
2694
- }
2695
- const summary = {
2696
- toolName: toolCall.toolName,
2697
- success: result.success,
2698
- ...result.success && { output: result.output },
2699
- ...!result.success && {
2700
- error: result.error instanceof Error ? result.error.message : String(result.error)
2701
- }
2702
- };
2703
- results.push(ToolExecutionSummarySchema.parse(summary));
2704
- this.log(
2705
- `Tool ${toolCall.toolName} ${result.success ? "succeeded" : "failed"}`,
2706
- {
2707
- success: result.success,
2708
- durationMs
2709
- }
2710
- );
2711
- } catch (error) {
2712
- const endTime = /* @__PURE__ */ new Date();
2713
- const durationMs = endTime.getTime() - startTime.getTime();
2666
+ results.push(
2667
+ await this.executeSingleToolCall(toolCall, context, parentSpanId)
2668
+ );
2669
+ }
2670
+ return results;
2671
+ }
2672
+ /**
2673
+ * Execute a single tool call with span tracking and error handling
2674
+ */
2675
+ async executeSingleToolCall(toolCall, context, parentSpanId) {
2676
+ this.log(`Action: ${toolCall.toolName}`, {
2677
+ parameters: toolCall.arguments
2678
+ });
2679
+ const startTime = /* @__PURE__ */ new Date();
2680
+ const tool2 = this.tools.get(toolCall.toolName);
2681
+ const isAgentTool = tool2?.metadata?.["isAgent"] === true;
2682
+ const spanType = isAgentTool ? "\u{1F916} agent" : "\u{1F527} tool";
2683
+ const toolSpan = await this.opperClient.createSpan({
2684
+ name: `tool_${toolCall.toolName}`,
2685
+ input: toolCall.arguments,
2686
+ type: spanType,
2687
+ ...parentSpanId ? { parentSpanId } : context.parentSpanId ? { parentSpanId: context.parentSpanId } : {}
2688
+ });
2689
+ try {
2690
+ const result = await this.executeTool(
2691
+ toolCall.toolName,
2692
+ toolCall.arguments,
2693
+ context,
2694
+ { spanId: toolSpan.id }
2695
+ );
2696
+ if (result.usage) {
2697
+ context.updateUsageWithSource(toolCall.toolName, result.usage);
2698
+ }
2699
+ const endTime = /* @__PURE__ */ new Date();
2700
+ const durationMs = endTime.getTime() - startTime.getTime();
2701
+ if (result.success) {
2714
2702
  this.queueSpanUpdate(context, {
2715
2703
  spanId: toolSpan.id,
2716
- error: error instanceof Error ? error.message : String(error),
2704
+ output: result.output,
2717
2705
  startTime,
2718
2706
  endTime,
2719
2707
  meta: { durationMs }
2720
2708
  });
2721
- const summary = {
2722
- toolName: toolCall.toolName,
2723
- success: false,
2724
- error: error instanceof Error ? error.message : String(error)
2725
- };
2726
- results.push(ToolExecutionSummarySchema.parse(summary));
2727
- this.logger.warn(`Tool ${toolCall.toolName} threw error`, {
2728
- error: error instanceof Error ? error.message : String(error),
2729
- durationMs
2709
+ } else {
2710
+ this.queueSpanUpdate(context, {
2711
+ spanId: toolSpan.id,
2712
+ error: result.error instanceof Error ? result.error.message : String(result.error),
2713
+ startTime,
2714
+ endTime,
2715
+ meta: { durationMs }
2730
2716
  });
2731
2717
  }
2718
+ const summary = {
2719
+ toolName: toolCall.toolName,
2720
+ success: result.success,
2721
+ ...result.success && { output: result.output },
2722
+ ...!result.success && {
2723
+ error: result.error instanceof Error ? result.error.message : String(result.error)
2724
+ }
2725
+ };
2726
+ this.log(
2727
+ `Tool ${toolCall.toolName} ${result.success ? "succeeded" : "failed"}`,
2728
+ {
2729
+ success: result.success,
2730
+ durationMs
2731
+ }
2732
+ );
2733
+ return ToolExecutionSummarySchema.parse(summary);
2734
+ } catch (error) {
2735
+ const endTime = /* @__PURE__ */ new Date();
2736
+ const durationMs = endTime.getTime() - startTime.getTime();
2737
+ this.queueSpanUpdate(context, {
2738
+ spanId: toolSpan.id,
2739
+ error: error instanceof Error ? error.message : String(error),
2740
+ startTime,
2741
+ endTime,
2742
+ meta: { durationMs }
2743
+ });
2744
+ const summary = {
2745
+ toolName: toolCall.toolName,
2746
+ success: false,
2747
+ error: error instanceof Error ? error.message : String(error)
2748
+ };
2749
+ this.logger.warn(`Tool ${toolCall.toolName} threw error`, {
2750
+ error: error instanceof Error ? error.message : String(error),
2751
+ durationMs
2752
+ });
2753
+ return ToolExecutionSummarySchema.parse(summary);
2732
2754
  }
2733
- return results;
2734
2755
  }
2735
2756
  /**
2736
2757
  * Handle memory operations from a decision