@agentica/benchmark 0.43.3 → 0.44.0-dev.20260313

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.
@@ -1,192 +1,192 @@
1
- /**
2
- * @module
3
- * This file contains functions to work with AgenticaCallBenchmarkReporter.
4
- *
5
- * @author Wrtn Technologies
6
- */
7
- import type { AgenticaTokenUsage } from "@agentica/core";
8
-
9
- import type { IAgenticaCallBenchmarkEvent } from "../structures/IAgenticaCallBenchmarkEvent";
10
- import type { IAgenticaCallBenchmarkResult } from "../structures/IAgenticaCallBenchmarkResult";
11
-
12
- import { MathUtil } from "../utils/MathUtil";
13
-
14
- import { AgenticaBenchmarkUtil } from "./AgenticaBenchmarkUtil";
15
- import { AgenticaPromptReporter } from "./AgenticaPromptReporter";
16
-
17
- export const AgenticaCallBenchmarkReporter = {
18
- markdown,
19
- };
20
-
21
- export function markdown(result: IAgenticaCallBenchmarkResult): Record<string, string> {
22
- return Object.fromEntries([
23
- ["./README.md", writeIndex(result)],
24
- ...result.experiments
25
- .map<[string, string][]>(exp => [
26
- [`./${exp.scenario.name}/README.md`, writeExperimentIndex(exp)],
27
- ...exp.events.map<[string, string]>((event, i) => [
28
- `./${exp.scenario.name}/${i + 1}.${event.type}.md`,
29
- writeExperimentEvent(event, i),
30
- ]),
31
- ])
32
- .flat(),
33
- ]);
34
- }
35
-
36
- function writeIndex(result: IAgenticaCallBenchmarkResult): string {
37
- const events: IAgenticaCallBenchmarkEvent[] = result.experiments
38
- .map(r => r.events)
39
- .flat();
40
- const average: number
41
- = events
42
- .map(e => e.completed_at.getTime() - e.started_at.getTime())
43
- .reduce((a, b) => a + b, 0) / events.length;
44
- const aggregate: AgenticaTokenUsage.IComponent = result.usage.aggregate;
45
- return [
46
- "# LLM Function Call Benchmark",
47
- "## Summary",
48
- ` - Aggregation:`,
49
- ` - Scenarios: #${result.experiments.length.toLocaleString()}`,
50
- ` - Trial: ${events.length}`,
51
- ` - Success: ${events.filter(e => e.type === "success").length}`,
52
- ` - Failure: ${events.filter(e => e.type === "failure").length}`,
53
- ` - Average Time: ${MathUtil.round(average).toLocaleString()} ms`,
54
- ` - Token Usage`,
55
- ` - Total: ${aggregate.total.toLocaleString()}`,
56
- ` - Input`,
57
- ` - Total: ${aggregate.input.total.toLocaleString()}`,
58
- ` - Cached: ${aggregate.input.cached.toLocaleString()}`,
59
- ` - Output:`,
60
- ` - Total: ${aggregate.output.total.toLocaleString()}`,
61
- ` - Reasoning: ${aggregate.output.reasoning.toLocaleString()}`,
62
- ` - Accepted Prediction: ${aggregate.output.accepted_prediction.toLocaleString()}`,
63
- ` - Rejected Prediction: ${aggregate.output.rejected_prediction.toLocaleString()}`,
64
- "",
65
- "## Experiments",
66
- " Name | Select | Call | Time/Avg ",
67
- ":-----|:-------|:-----|----------:",
68
- ...result.experiments.map(exp =>
69
- [
70
- `[${exp.scenario.name}](./${exp.scenario.name}/README.md)`,
71
- drawStatus(
72
- exp.events,
73
- e => e.type !== "error" && e.select === true,
74
- ),
75
- drawStatus(exp.events, e => e.type !== "error" && e.call === true),
76
- `${MathUtil.round(
77
- exp.events
78
- .map(e => e.completed_at.getTime() - e.started_at.getTime())
79
- .reduce((a, b) => a + b, 0) / exp.events.length,
80
- ).toLocaleString()} ms`,
81
- ].join(" | "),
82
- ),
83
- ].join("\n");
84
- }
85
-
86
- function writeExperimentIndex(exp: IAgenticaCallBenchmarkResult.IExperiment): string {
87
- return [
88
- `# ${exp.scenario.name}`,
89
- "## Summary",
90
- ` - Scenarios: #${exp.events.length.toLocaleString()}`,
91
- ` - Success: ${exp.events.filter(e => e.type === "success").length}`,
92
- ` - Failure: ${exp.events.filter(e => e.type === "failure").length}`,
93
- ` - Average Time: ${MathUtil.round(
94
- exp.events
95
- .map(e => e.completed_at.getTime() - e.started_at.getTime())
96
- .reduce((a, b) => a + b, 0) / exp.events.length,
97
- ).toLocaleString()} ms`,
98
- "",
99
- "## Events",
100
- " Name | Type | Time",
101
- ":-----|:-----|----:",
102
- ...exp.events.map((e, i) =>
103
- [
104
- `[${i + 1}.](./${i + 1}.${e.type}.md)`,
105
- e.type,
106
- `${MathUtil.round(e.completed_at.getTime() - e.started_at.getTime())} ms`,
107
- ].join(" | "),
108
- ),
109
- "",
110
- "## Scenario",
111
- "### User Prompt",
112
- exp.scenario.text,
113
- "",
114
- "### Expected",
115
- "```json",
116
- JSON.stringify(
117
- AgenticaBenchmarkUtil.expectedToJson(exp.scenario.expected),
118
- null,
119
- 2,
120
- ),
121
- "```",
122
- ].join("\n");
123
- }
124
-
125
- function writeExperimentEvent(event: IAgenticaCallBenchmarkEvent, index: number): string {
126
- return [
127
- `# ${index + 1}. ${event.type}`,
128
- "## Summary",
129
- ` - Name: ${event.scenario.name}`,
130
- ` - Type: ${event.type}`,
131
- ` - Time: ${MathUtil.round(
132
- event.completed_at.getTime() - event.started_at.getTime(),
133
- ).toLocaleString()} ms`,
134
- ...(event.type !== "error"
135
- ? [
136
- ` - Select: ${event.select ? "✅" : "❌"}`,
137
- ` - Call: ${event.call ? "✅" : "❌"}`,
138
- ]
139
- : []),
140
- ` - Token Usage:`,
141
- ` - Total: ${JSON.stringify(event.usage.aggregate.total)}`,
142
- ` - Input`,
143
- ` - Total: ${event.usage.aggregate.input.total}`,
144
- ` - Cached: ${event.usage.aggregate.input.cached}`,
145
- ` - Output:`,
146
- ` - Total: ${event.usage.aggregate.output.total}`,
147
- ` - Accepted Prediction: ${event.usage.aggregate.output.accepted_prediction}`,
148
- ` - Reasoning: ${event.usage.aggregate.output.reasoning}`,
149
- ` - Rejected Prediction: ${event.usage.aggregate.output.rejected_prediction}`,
150
-
151
- "",
152
- "## Scenario",
153
- "### User Prompt",
154
- event.scenario.text,
155
- "",
156
- "### Expected",
157
- "```json",
158
- JSON.stringify(
159
- AgenticaBenchmarkUtil.expectedToJson(event.scenario.expected),
160
- null,
161
- 2,
162
- ),
163
- "```",
164
- "",
165
- "## Prompt Histories",
166
- ...event.prompts.map(AgenticaPromptReporter.markdown),
167
- "",
168
- ...(event.type === "error"
169
- ? [
170
- "## Error",
171
- "```json",
172
- JSON.stringify(
173
- AgenticaBenchmarkUtil.errorToJson(event.error),
174
- null,
175
- 2,
176
- ),
177
- "```",
178
- ]
179
- : []),
180
- ].join("\n");
181
- }
182
-
183
- function drawStatus(events: IAgenticaCallBenchmarkEvent[], success: (e: IAgenticaCallBenchmarkEvent) => boolean): string {
184
- const count: number = Math.floor(
185
- (events.filter(success).length / events.length) * 10,
186
- );
187
- // @TODO use String.prototype.padStart, padEnd or String.prototype.repeat
188
- return (
189
- Array.from({ length: count }).fill("■").join("")
190
- + Array.from({ length: 10 - count }).fill("□").join("")
191
- );
192
- }
1
+ /**
2
+ * @module
3
+ * This file contains functions to work with AgenticaCallBenchmarkReporter.
4
+ *
5
+ * @author Wrtn Technologies
6
+ */
7
+ import type { AgenticaTokenUsage } from "@agentica/core";
8
+
9
+ import type { IAgenticaCallBenchmarkEvent } from "../structures/IAgenticaCallBenchmarkEvent";
10
+ import type { IAgenticaCallBenchmarkResult } from "../structures/IAgenticaCallBenchmarkResult";
11
+
12
+ import { MathUtil } from "../utils/MathUtil";
13
+
14
+ import { AgenticaBenchmarkUtil } from "./AgenticaBenchmarkUtil";
15
+ import { AgenticaPromptReporter } from "./AgenticaPromptReporter";
16
+
17
+ export const AgenticaCallBenchmarkReporter = {
18
+ markdown,
19
+ };
20
+
21
+ export function markdown(result: IAgenticaCallBenchmarkResult): Record<string, string> {
22
+ return Object.fromEntries([
23
+ ["./README.md", writeIndex(result)],
24
+ ...result.experiments
25
+ .map<[string, string][]>(exp => [
26
+ [`./${exp.scenario.name}/README.md`, writeExperimentIndex(exp)],
27
+ ...exp.events.map<[string, string]>((event, i) => [
28
+ `./${exp.scenario.name}/${i + 1}.${event.type}.md`,
29
+ writeExperimentEvent(event, i),
30
+ ]),
31
+ ])
32
+ .flat(),
33
+ ]);
34
+ }
35
+
36
+ function writeIndex(result: IAgenticaCallBenchmarkResult): string {
37
+ const events: IAgenticaCallBenchmarkEvent[] = result.experiments
38
+ .map(r => r.events)
39
+ .flat();
40
+ const average: number
41
+ = events
42
+ .map(e => e.completed_at.getTime() - e.started_at.getTime())
43
+ .reduce((a, b) => a + b, 0) / events.length;
44
+ const aggregate: AgenticaTokenUsage.IComponent = result.usage.aggregate;
45
+ return [
46
+ "# LLM Function Call Benchmark",
47
+ "## Summary",
48
+ ` - Aggregation:`,
49
+ ` - Scenarios: #${result.experiments.length.toLocaleString()}`,
50
+ ` - Trial: ${events.length}`,
51
+ ` - Success: ${events.filter(e => e.type === "success").length}`,
52
+ ` - Failure: ${events.filter(e => e.type === "failure").length}`,
53
+ ` - Average Time: ${MathUtil.round(average).toLocaleString()} ms`,
54
+ ` - Token Usage`,
55
+ ` - Total: ${aggregate.total.toLocaleString()}`,
56
+ ` - Input`,
57
+ ` - Total: ${aggregate.input.total.toLocaleString()}`,
58
+ ` - Cached: ${aggregate.input.cached.toLocaleString()}`,
59
+ ` - Output:`,
60
+ ` - Total: ${aggregate.output.total.toLocaleString()}`,
61
+ ` - Reasoning: ${aggregate.output.reasoning.toLocaleString()}`,
62
+ ` - Accepted Prediction: ${aggregate.output.accepted_prediction.toLocaleString()}`,
63
+ ` - Rejected Prediction: ${aggregate.output.rejected_prediction.toLocaleString()}`,
64
+ "",
65
+ "## Experiments",
66
+ " Name | Select | Call | Time/Avg ",
67
+ ":-----|:-------|:-----|----------:",
68
+ ...result.experiments.map(exp =>
69
+ [
70
+ `[${exp.scenario.name}](./${exp.scenario.name}/README.md)`,
71
+ drawStatus(
72
+ exp.events,
73
+ e => e.type !== "error" && e.select === true,
74
+ ),
75
+ drawStatus(exp.events, e => e.type !== "error" && e.call === true),
76
+ `${MathUtil.round(
77
+ exp.events
78
+ .map(e => e.completed_at.getTime() - e.started_at.getTime())
79
+ .reduce((a, b) => a + b, 0) / exp.events.length,
80
+ ).toLocaleString()} ms`,
81
+ ].join(" | "),
82
+ ),
83
+ ].join("\n");
84
+ }
85
+
86
+ function writeExperimentIndex(exp: IAgenticaCallBenchmarkResult.IExperiment): string {
87
+ return [
88
+ `# ${exp.scenario.name}`,
89
+ "## Summary",
90
+ ` - Scenarios: #${exp.events.length.toLocaleString()}`,
91
+ ` - Success: ${exp.events.filter(e => e.type === "success").length}`,
92
+ ` - Failure: ${exp.events.filter(e => e.type === "failure").length}`,
93
+ ` - Average Time: ${MathUtil.round(
94
+ exp.events
95
+ .map(e => e.completed_at.getTime() - e.started_at.getTime())
96
+ .reduce((a, b) => a + b, 0) / exp.events.length,
97
+ ).toLocaleString()} ms`,
98
+ "",
99
+ "## Events",
100
+ " Name | Type | Time",
101
+ ":-----|:-----|----:",
102
+ ...exp.events.map((e, i) =>
103
+ [
104
+ `[${i + 1}.](./${i + 1}.${e.type}.md)`,
105
+ e.type,
106
+ `${MathUtil.round(e.completed_at.getTime() - e.started_at.getTime())} ms`,
107
+ ].join(" | "),
108
+ ),
109
+ "",
110
+ "## Scenario",
111
+ "### User Prompt",
112
+ exp.scenario.text,
113
+ "",
114
+ "### Expected",
115
+ "```json",
116
+ JSON.stringify(
117
+ AgenticaBenchmarkUtil.expectedToJson(exp.scenario.expected),
118
+ null,
119
+ 2,
120
+ ),
121
+ "```",
122
+ ].join("\n");
123
+ }
124
+
125
+ function writeExperimentEvent(event: IAgenticaCallBenchmarkEvent, index: number): string {
126
+ return [
127
+ `# ${index + 1}. ${event.type}`,
128
+ "## Summary",
129
+ ` - Name: ${event.scenario.name}`,
130
+ ` - Type: ${event.type}`,
131
+ ` - Time: ${MathUtil.round(
132
+ event.completed_at.getTime() - event.started_at.getTime(),
133
+ ).toLocaleString()} ms`,
134
+ ...(event.type !== "error"
135
+ ? [
136
+ ` - Select: ${event.select ? "✅" : "❌"}`,
137
+ ` - Call: ${event.call ? "✅" : "❌"}`,
138
+ ]
139
+ : []),
140
+ ` - Token Usage:`,
141
+ ` - Total: ${JSON.stringify(event.usage.aggregate.total)}`,
142
+ ` - Input`,
143
+ ` - Total: ${event.usage.aggregate.input.total}`,
144
+ ` - Cached: ${event.usage.aggregate.input.cached}`,
145
+ ` - Output:`,
146
+ ` - Total: ${event.usage.aggregate.output.total}`,
147
+ ` - Accepted Prediction: ${event.usage.aggregate.output.accepted_prediction}`,
148
+ ` - Reasoning: ${event.usage.aggregate.output.reasoning}`,
149
+ ` - Rejected Prediction: ${event.usage.aggregate.output.rejected_prediction}`,
150
+
151
+ "",
152
+ "## Scenario",
153
+ "### User Prompt",
154
+ event.scenario.text,
155
+ "",
156
+ "### Expected",
157
+ "```json",
158
+ JSON.stringify(
159
+ AgenticaBenchmarkUtil.expectedToJson(event.scenario.expected),
160
+ null,
161
+ 2,
162
+ ),
163
+ "```",
164
+ "",
165
+ "## Prompt Histories",
166
+ ...event.prompts.map(AgenticaPromptReporter.markdown),
167
+ "",
168
+ ...(event.type === "error"
169
+ ? [
170
+ "## Error",
171
+ "```json",
172
+ JSON.stringify(
173
+ AgenticaBenchmarkUtil.errorToJson(event.error),
174
+ null,
175
+ 2,
176
+ ),
177
+ "```",
178
+ ]
179
+ : []),
180
+ ].join("\n");
181
+ }
182
+
183
+ function drawStatus(events: IAgenticaCallBenchmarkEvent[], success: (e: IAgenticaCallBenchmarkEvent) => boolean): string {
184
+ const count: number = Math.floor(
185
+ (events.filter(success).length / events.length) * 10,
186
+ );
187
+ // @TODO use String.prototype.padStart, padEnd or String.prototype.repeat
188
+ return (
189
+ Array.from({ length: count }).fill("■").join("")
190
+ + Array.from({ length: 10 - count }).fill("□").join("")
191
+ );
192
+ }
@@ -1,63 +1,63 @@
1
- /**
2
- * @module
3
- * This file contains functions to work with AgenticaPromptReporter.
4
- *
5
- * @author Wrtn Technologies
6
- */
7
- import type { AgenticaHistory } from "@agentica/core";
8
-
9
- export const AgenticaPromptReporter = {
10
- markdown,
11
- };
12
-
13
- function markdown(p: AgenticaHistory): string {
14
- if (p.type === "userMessage") {
15
- return [`### User Input`, p.contents, ""].join("\n");
16
- }
17
- if (p.type === "assistantMessage") {
18
- return [`### Assistant`, p.text, ""].join("\n");
19
- }
20
- if (p.type === "systemMessage") {
21
- return [`### System`, p.text, ""].join("\n");
22
- }
23
-
24
- if (p.type === "select" || p.type === "cancel") {
25
- return [
26
- `### ${p.type === "select" ? "Select" : "Cancel"}`,
27
- ` - controller: ${p.selection.operation.controller.name}`,
28
- ` - function: ${p.selection.operation.function.name}`,
29
- ` - reason: ${p.selection.reason}`,
30
- "",
31
- ...((p.selection.operation.function.description?.length ?? 0) !== 0
32
- ? [p.selection.operation.function.description, ""]
33
- : []),
34
- ].join("\n");
35
- }
36
-
37
- if (p.type === "describe") {
38
- return [
39
- "### Describe",
40
- ...p.executes.map(e => ` - ${e.operation.name}`),
41
- "",
42
- ...p.text.split("\n").map(s => `> ${s}`),
43
- "",
44
- ].join("\n");
45
- }
46
-
47
- if (p.type === "execute") {
48
- return [
49
- "### Execute",
50
- ` - name: ${p.operation.name}`,
51
- ` - controller: ${p.operation.controller.name}`,
52
- ` - function: ${p.operation.function.name}`,
53
- "",
54
- "```json",
55
- JSON.stringify(p.arguments, null, 2),
56
- "```",
57
- "",
58
- ].join("\n");
59
- }
60
-
61
- p satisfies never;
62
- throw new Error("Invalid history type");
63
- }
1
+ /**
2
+ * @module
3
+ * This file contains functions to work with AgenticaPromptReporter.
4
+ *
5
+ * @author Wrtn Technologies
6
+ */
7
+ import type { AgenticaHistory } from "@agentica/core";
8
+
9
+ export const AgenticaPromptReporter = {
10
+ markdown,
11
+ };
12
+
13
+ function markdown(p: AgenticaHistory): string {
14
+ if (p.type === "userMessage") {
15
+ return [`### User Input`, p.contents, ""].join("\n");
16
+ }
17
+ if (p.type === "assistantMessage") {
18
+ return [`### Assistant`, p.text, ""].join("\n");
19
+ }
20
+ if (p.type === "systemMessage") {
21
+ return [`### System`, p.text, ""].join("\n");
22
+ }
23
+
24
+ if (p.type === "select" || p.type === "cancel") {
25
+ return [
26
+ `### ${p.type === "select" ? "Select" : "Cancel"}`,
27
+ ` - controller: ${p.selection.operation.controller.name}`,
28
+ ` - function: ${p.selection.operation.function.name}`,
29
+ ` - reason: ${p.selection.reason}`,
30
+ "",
31
+ ...((p.selection.operation.function.description?.length ?? 0) !== 0
32
+ ? [p.selection.operation.function.description, ""]
33
+ : []),
34
+ ].join("\n");
35
+ }
36
+
37
+ if (p.type === "describe") {
38
+ return [
39
+ "### Describe",
40
+ ...p.executes.map(e => ` - ${e.operation.name}`),
41
+ "",
42
+ ...p.text.split("\n").map(s => `> ${s}`),
43
+ "",
44
+ ].join("\n");
45
+ }
46
+
47
+ if (p.type === "execute") {
48
+ return [
49
+ "### Execute",
50
+ ` - name: ${p.operation.name}`,
51
+ ` - controller: ${p.operation.controller.name}`,
52
+ ` - function: ${p.operation.function.name}`,
53
+ "",
54
+ "```json",
55
+ JSON.stringify(p.arguments, null, 2),
56
+ "```",
57
+ "",
58
+ ].join("\n");
59
+ }
60
+
61
+ p satisfies never;
62
+ throw new Error("Invalid history type");
63
+ }