@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.d.cts CHANGED
@@ -984,6 +984,12 @@ interface BaseAgentConfig<TInput, TOutput> {
984
984
  * Custom memory implementation (defaults to InMemoryStore if enableMemory is true)
985
985
  */
986
986
  memory?: Memory;
987
+ /**
988
+ * Execute tool calls in parallel when the LLM returns multiple tool calls
989
+ * in a single response. When false (default), tools execute sequentially.
990
+ * @default false
991
+ */
992
+ parallelToolExecution?: boolean;
987
993
  /**
988
994
  * Additional metadata for the agent
989
995
  */
@@ -1054,6 +1060,10 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
1054
1060
  * Whether streaming is enabled
1055
1061
  */
1056
1062
  readonly enableStreaming: boolean;
1063
+ /**
1064
+ * Whether to execute tool calls in parallel
1065
+ */
1066
+ readonly parallelToolExecution: boolean;
1057
1067
  /**
1058
1068
  * Memory instance for persistent storage (null if disabled or initialization failed)
1059
1069
  */
@@ -1494,6 +1504,10 @@ declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInpu
1494
1504
  * Execute all tool calls from a decision
1495
1505
  */
1496
1506
  private executeToolCalls;
1507
+ /**
1508
+ * Execute a single tool call with span tracking and error handling
1509
+ */
1510
+ private executeSingleToolCall;
1497
1511
  /**
1498
1512
  * Handle memory operations from a decision
1499
1513
  * Supports read and write operations with graceful degradation
package/dist/index.d.ts CHANGED
@@ -984,6 +984,12 @@ interface BaseAgentConfig<TInput, TOutput> {
984
984
  * Custom memory implementation (defaults to InMemoryStore if enableMemory is true)
985
985
  */
986
986
  memory?: Memory;
987
+ /**
988
+ * Execute tool calls in parallel when the LLM returns multiple tool calls
989
+ * in a single response. When false (default), tools execute sequentially.
990
+ * @default false
991
+ */
992
+ parallelToolExecution?: boolean;
987
993
  /**
988
994
  * Additional metadata for the agent
989
995
  */
@@ -1054,6 +1060,10 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
1054
1060
  * Whether streaming is enabled
1055
1061
  */
1056
1062
  readonly enableStreaming: boolean;
1063
+ /**
1064
+ * Whether to execute tool calls in parallel
1065
+ */
1066
+ readonly parallelToolExecution: boolean;
1057
1067
  /**
1058
1068
  * Memory instance for persistent storage (null if disabled or initialization failed)
1059
1069
  */
@@ -1494,6 +1504,10 @@ declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInpu
1494
1504
  * Execute all tool calls from a decision
1495
1505
  */
1496
1506
  private executeToolCalls;
1507
+ /**
1508
+ * Execute a single tool call with span tracking and error handling
1509
+ */
1510
+ private executeSingleToolCall;
1497
1511
  /**
1498
1512
  * Handle memory operations from a decision
1499
1513
  * Supports read and write operations with graceful degradation
package/dist/index.js CHANGED
@@ -924,6 +924,10 @@ var BaseAgent = class {
924
924
  * Whether streaming is enabled
925
925
  */
926
926
  enableStreaming;
927
+ /**
928
+ * Whether to execute tool calls in parallel
929
+ */
930
+ parallelToolExecution;
927
931
  /**
928
932
  * Memory instance for persistent storage (null if disabled or initialization failed)
929
933
  */
@@ -988,6 +992,7 @@ var BaseAgent = class {
988
992
  this.outputSchema = config.outputSchema;
989
993
  this.enableMemory = config.enableMemory ?? false;
990
994
  this.enableStreaming = config.enableStreaming ?? false;
995
+ this.parallelToolExecution = config.parallelToolExecution ?? false;
991
996
  this.metadata = { ...config.metadata ?? {} };
992
997
  this.hooks = new HookManager();
993
998
  this.tools = /* @__PURE__ */ new Map();
@@ -1635,7 +1640,7 @@ var mergeSchemaDefaults = (schema, value) => {
1635
1640
 
1636
1641
  // package.json
1637
1642
  var package_default = {
1638
- version: "0.7.1"};
1643
+ version: "0.8.0"};
1639
1644
 
1640
1645
  // src/utils/version.ts
1641
1646
  var SDK_NAME = "@opperai/agents";
@@ -2627,89 +2632,105 @@ The memory you write persists across all process() calls on this agent.`;
2627
2632
  return [];
2628
2633
  }
2629
2634
  this.log(`Executing ${decision.toolCalls.length} tool call(s)`);
2635
+ if (this.parallelToolExecution && decision.toolCalls.length > 1) {
2636
+ this.log("Executing tool calls in parallel");
2637
+ return Promise.all(
2638
+ decision.toolCalls.map(
2639
+ (toolCall) => this.executeSingleToolCall(toolCall, context, parentSpanId)
2640
+ )
2641
+ );
2642
+ }
2630
2643
  const results = [];
2631
2644
  for (const toolCall of decision.toolCalls) {
2632
- this.log(`Action: ${toolCall.toolName}`, {
2633
- parameters: toolCall.arguments
2634
- });
2635
- const startTime = /* @__PURE__ */ new Date();
2636
- const tool2 = this.tools.get(toolCall.toolName);
2637
- const isAgentTool = tool2?.metadata?.["isAgent"] === true;
2638
- const spanType = isAgentTool ? "\u{1F916} agent" : "\u{1F527} tool";
2639
- const toolSpan = await this.opperClient.createSpan({
2640
- name: `tool_${toolCall.toolName}`,
2641
- input: toolCall.arguments,
2642
- type: spanType,
2643
- ...parentSpanId ? { parentSpanId } : context.parentSpanId ? { parentSpanId: context.parentSpanId } : {}
2644
- });
2645
- try {
2646
- const result = await this.executeTool(
2647
- toolCall.toolName,
2648
- toolCall.arguments,
2649
- context,
2650
- { spanId: toolSpan.id }
2651
- );
2652
- if (result.usage) {
2653
- context.updateUsageWithSource(toolCall.toolName, result.usage);
2654
- }
2655
- const endTime = /* @__PURE__ */ new Date();
2656
- const durationMs = endTime.getTime() - startTime.getTime();
2657
- if (result.success) {
2658
- this.queueSpanUpdate(context, {
2659
- spanId: toolSpan.id,
2660
- output: result.output,
2661
- startTime,
2662
- endTime,
2663
- meta: { durationMs }
2664
- });
2665
- } else {
2666
- this.queueSpanUpdate(context, {
2667
- spanId: toolSpan.id,
2668
- error: result.error instanceof Error ? result.error.message : String(result.error),
2669
- startTime,
2670
- endTime,
2671
- meta: { durationMs }
2672
- });
2673
- }
2674
- const summary = {
2675
- toolName: toolCall.toolName,
2676
- success: result.success,
2677
- ...result.success && { output: result.output },
2678
- ...!result.success && {
2679
- error: result.error instanceof Error ? result.error.message : String(result.error)
2680
- }
2681
- };
2682
- results.push(ToolExecutionSummarySchema.parse(summary));
2683
- this.log(
2684
- `Tool ${toolCall.toolName} ${result.success ? "succeeded" : "failed"}`,
2685
- {
2686
- success: result.success,
2687
- durationMs
2688
- }
2689
- );
2690
- } catch (error) {
2691
- const endTime = /* @__PURE__ */ new Date();
2692
- const durationMs = endTime.getTime() - startTime.getTime();
2645
+ results.push(
2646
+ await this.executeSingleToolCall(toolCall, context, parentSpanId)
2647
+ );
2648
+ }
2649
+ return results;
2650
+ }
2651
+ /**
2652
+ * Execute a single tool call with span tracking and error handling
2653
+ */
2654
+ async executeSingleToolCall(toolCall, context, parentSpanId) {
2655
+ this.log(`Action: ${toolCall.toolName}`, {
2656
+ parameters: toolCall.arguments
2657
+ });
2658
+ const startTime = /* @__PURE__ */ new Date();
2659
+ const tool2 = this.tools.get(toolCall.toolName);
2660
+ const isAgentTool = tool2?.metadata?.["isAgent"] === true;
2661
+ const spanType = isAgentTool ? "\u{1F916} agent" : "\u{1F527} tool";
2662
+ const toolSpan = await this.opperClient.createSpan({
2663
+ name: `tool_${toolCall.toolName}`,
2664
+ input: toolCall.arguments,
2665
+ type: spanType,
2666
+ ...parentSpanId ? { parentSpanId } : context.parentSpanId ? { parentSpanId: context.parentSpanId } : {}
2667
+ });
2668
+ try {
2669
+ const result = await this.executeTool(
2670
+ toolCall.toolName,
2671
+ toolCall.arguments,
2672
+ context,
2673
+ { spanId: toolSpan.id }
2674
+ );
2675
+ if (result.usage) {
2676
+ context.updateUsageWithSource(toolCall.toolName, result.usage);
2677
+ }
2678
+ const endTime = /* @__PURE__ */ new Date();
2679
+ const durationMs = endTime.getTime() - startTime.getTime();
2680
+ if (result.success) {
2693
2681
  this.queueSpanUpdate(context, {
2694
2682
  spanId: toolSpan.id,
2695
- error: error instanceof Error ? error.message : String(error),
2683
+ output: result.output,
2696
2684
  startTime,
2697
2685
  endTime,
2698
2686
  meta: { durationMs }
2699
2687
  });
2700
- const summary = {
2701
- toolName: toolCall.toolName,
2702
- success: false,
2703
- error: error instanceof Error ? error.message : String(error)
2704
- };
2705
- results.push(ToolExecutionSummarySchema.parse(summary));
2706
- this.logger.warn(`Tool ${toolCall.toolName} threw error`, {
2707
- error: error instanceof Error ? error.message : String(error),
2708
- durationMs
2688
+ } else {
2689
+ this.queueSpanUpdate(context, {
2690
+ spanId: toolSpan.id,
2691
+ error: result.error instanceof Error ? result.error.message : String(result.error),
2692
+ startTime,
2693
+ endTime,
2694
+ meta: { durationMs }
2709
2695
  });
2710
2696
  }
2697
+ const summary = {
2698
+ toolName: toolCall.toolName,
2699
+ success: result.success,
2700
+ ...result.success && { output: result.output },
2701
+ ...!result.success && {
2702
+ error: result.error instanceof Error ? result.error.message : String(result.error)
2703
+ }
2704
+ };
2705
+ this.log(
2706
+ `Tool ${toolCall.toolName} ${result.success ? "succeeded" : "failed"}`,
2707
+ {
2708
+ success: result.success,
2709
+ durationMs
2710
+ }
2711
+ );
2712
+ return ToolExecutionSummarySchema.parse(summary);
2713
+ } catch (error) {
2714
+ const endTime = /* @__PURE__ */ new Date();
2715
+ const durationMs = endTime.getTime() - startTime.getTime();
2716
+ this.queueSpanUpdate(context, {
2717
+ spanId: toolSpan.id,
2718
+ error: error instanceof Error ? error.message : String(error),
2719
+ startTime,
2720
+ endTime,
2721
+ meta: { durationMs }
2722
+ });
2723
+ const summary = {
2724
+ toolName: toolCall.toolName,
2725
+ success: false,
2726
+ error: error instanceof Error ? error.message : String(error)
2727
+ };
2728
+ this.logger.warn(`Tool ${toolCall.toolName} threw error`, {
2729
+ error: error instanceof Error ? error.message : String(error),
2730
+ durationMs
2731
+ });
2732
+ return ToolExecutionSummarySchema.parse(summary);
2711
2733
  }
2712
- return results;
2713
2734
  }
2714
2735
  /**
2715
2736
  * Handle memory operations from a decision