@opperai/agents 0.7.0 → 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 +98 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -702
- package/dist/index.d.ts +67 -702
- package/dist/index.js +98 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
1643
|
+
version: "0.8.0"};
|
|
1639
1644
|
|
|
1640
1645
|
// src/utils/version.ts
|
|
1641
1646
|
var SDK_NAME = "@opperai/agents";
|
|
@@ -1671,7 +1676,8 @@ var extractCost = (response) => {
|
|
|
1671
1676
|
};
|
|
1672
1677
|
};
|
|
1673
1678
|
var DEFAULT_RETRY_CONFIG = {
|
|
1674
|
-
maxRetries:
|
|
1679
|
+
maxRetries: 0,
|
|
1680
|
+
// Retries are handled in the opper-node sdk
|
|
1675
1681
|
initialDelayMs: 1e3,
|
|
1676
1682
|
backoffMultiplier: 2,
|
|
1677
1683
|
maxDelayMs: 1e4
|
|
@@ -1684,7 +1690,8 @@ var OpperClient = class {
|
|
|
1684
1690
|
this.client = new Opper({
|
|
1685
1691
|
httpBearer: apiKey ?? process.env["OPPER_HTTP_BEARER"] ?? "",
|
|
1686
1692
|
userAgent: getUserAgent(),
|
|
1687
|
-
...options.baseUrl && { serverURL: options.baseUrl }
|
|
1693
|
+
...options.baseUrl && { serverURL: options.baseUrl },
|
|
1694
|
+
retryConfig: { strategy: "backoff" }
|
|
1688
1695
|
});
|
|
1689
1696
|
this.logger = options.logger ?? getDefaultLogger();
|
|
1690
1697
|
this.retryConfig = {
|
|
@@ -2625,89 +2632,105 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2625
2632
|
return [];
|
|
2626
2633
|
}
|
|
2627
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
|
+
}
|
|
2628
2643
|
const results = [];
|
|
2629
2644
|
for (const toolCall of decision.toolCalls) {
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
error: result.error instanceof Error ? result.error.message : String(result.error),
|
|
2667
|
-
startTime,
|
|
2668
|
-
endTime,
|
|
2669
|
-
meta: { durationMs }
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
const summary = {
|
|
2673
|
-
toolName: toolCall.toolName,
|
|
2674
|
-
success: result.success,
|
|
2675
|
-
...result.success && { output: result.output },
|
|
2676
|
-
...!result.success && {
|
|
2677
|
-
error: result.error instanceof Error ? result.error.message : String(result.error)
|
|
2678
|
-
}
|
|
2679
|
-
};
|
|
2680
|
-
results.push(ToolExecutionSummarySchema.parse(summary));
|
|
2681
|
-
this.log(
|
|
2682
|
-
`Tool ${toolCall.toolName} ${result.success ? "succeeded" : "failed"}`,
|
|
2683
|
-
{
|
|
2684
|
-
success: result.success,
|
|
2685
|
-
durationMs
|
|
2686
|
-
}
|
|
2687
|
-
);
|
|
2688
|
-
} catch (error) {
|
|
2689
|
-
const endTime = /* @__PURE__ */ new Date();
|
|
2690
|
-
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) {
|
|
2691
2681
|
this.queueSpanUpdate(context, {
|
|
2692
2682
|
spanId: toolSpan.id,
|
|
2693
|
-
|
|
2683
|
+
output: result.output,
|
|
2694
2684
|
startTime,
|
|
2695
2685
|
endTime,
|
|
2696
2686
|
meta: { durationMs }
|
|
2697
2687
|
});
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
error: error instanceof Error ? error.message : String(error)
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
error: error instanceof Error ? error.message : String(error),
|
|
2706
|
-
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 }
|
|
2707
2695
|
});
|
|
2708
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);
|
|
2709
2733
|
}
|
|
2710
|
-
return results;
|
|
2711
2734
|
}
|
|
2712
2735
|
/**
|
|
2713
2736
|
* Handle memory operations from a decision
|