@botbotgo/better-call 0.1.27 → 0.1.29
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/package.json +1 -1
- package/scripts/demo.mjs +72 -31
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -3,6 +3,23 @@ import { betterTools, repairToolCall, reliableToolCalls } from "../dist/index.js
|
|
|
3
3
|
|
|
4
4
|
const json = process.argv.includes("--json");
|
|
5
5
|
|
|
6
|
+
function errorMessage(error) {
|
|
7
|
+
return error instanceof Error ? error.message : String(error);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function exitWithError(step, error) {
|
|
11
|
+
const message = errorMessage(error);
|
|
12
|
+
|
|
13
|
+
if (json) {
|
|
14
|
+
console.error(JSON.stringify({ error: step, message }, null, 2));
|
|
15
|
+
} else {
|
|
16
|
+
console.error(`BetterCall demo failed during ${step}.`);
|
|
17
|
+
console.error(message);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
const stockQuote = {
|
|
7
24
|
name: "stock_quote",
|
|
8
25
|
description: "Get a stock quote.",
|
|
@@ -29,39 +46,63 @@ const [wrappedStockQuote] = betterTools([stockQuote], {
|
|
|
29
46
|
},
|
|
30
47
|
});
|
|
31
48
|
|
|
32
|
-
|
|
49
|
+
let wrappedOutput;
|
|
50
|
+
try {
|
|
51
|
+
wrappedOutput = await wrappedStockQuote.invoke(badArgs);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
exitWithError("wrapped stock_quote invocation", error);
|
|
54
|
+
}
|
|
33
55
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
56
|
+
let reliableResult;
|
|
57
|
+
try {
|
|
58
|
+
reliableResult = await reliableToolCalls({
|
|
59
|
+
userInput: "Get Apple stock in the US market.",
|
|
60
|
+
tools: [stockQuote],
|
|
61
|
+
// The tool name is intentionally wrong to demonstrate repair to stock_quote.
|
|
62
|
+
calls: [{ tool: "stock_price", args: badArgs }],
|
|
63
|
+
repair() {
|
|
64
|
+
return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
exitWithError("tool-call repair", error);
|
|
69
|
+
}
|
|
43
70
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
71
|
+
let gatewayResult;
|
|
72
|
+
try {
|
|
73
|
+
gatewayResult = await repairToolCall({
|
|
74
|
+
userInput: "Research the current market.",
|
|
75
|
+
visibleTools: [{
|
|
76
|
+
name: "task",
|
|
77
|
+
description: "Delegate a task to a visible specialist.",
|
|
78
|
+
schema: {
|
|
79
|
+
type: "object",
|
|
80
|
+
properties: {
|
|
81
|
+
subagent_type: { type: "string", enum: ["research", "ops"] },
|
|
82
|
+
description: { type: "string" },
|
|
83
|
+
},
|
|
84
|
+
required: ["subagent_type", "description"],
|
|
85
|
+
additionalProperties: false,
|
|
54
86
|
},
|
|
55
|
-
|
|
56
|
-
|
|
87
|
+
}],
|
|
88
|
+
invalidToolName: "research",
|
|
89
|
+
args: {
|
|
90
|
+
subagent_type: "research",
|
|
91
|
+
description: "Research the current market.",
|
|
57
92
|
},
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
gatewayResult = {
|
|
96
|
+
status: "error",
|
|
97
|
+
originalToolName: "research",
|
|
98
|
+
toolName: null,
|
|
99
|
+
reason: `repairToolCall failed: ${errorMessage(error)}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const repairedCall = Array.isArray(reliableResult.calls) && reliableResult.calls.length > 0
|
|
104
|
+
? reliableResult.calls[0]
|
|
105
|
+
: null;
|
|
65
106
|
|
|
66
107
|
const report = {
|
|
67
108
|
wrappedTool: {
|
|
@@ -70,8 +111,8 @@ const report = {
|
|
|
70
111
|
},
|
|
71
112
|
reliableToolCalls: {
|
|
72
113
|
before: { tool: "stock_price", args: badArgs },
|
|
73
|
-
repaired:
|
|
74
|
-
diagnostics: reliableResult.diagnostics,
|
|
114
|
+
repaired: repairedCall,
|
|
115
|
+
diagnostics: reliableResult.diagnostics ?? null,
|
|
75
116
|
},
|
|
76
117
|
gatewayRepair: gatewayResult,
|
|
77
118
|
};
|