@agentica/benchmark 0.7.0-dev.20250224-2
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/LICENSE +21 -0
- package/lib/AgenticaCallBenchmark.d.ts +137 -0
- package/lib/AgenticaCallBenchmark.js +187 -0
- package/lib/AgenticaCallBenchmark.js.map +1 -0
- package/lib/AgenticaSelectBenchmark.d.ts +123 -0
- package/lib/AgenticaSelectBenchmark.js +185 -0
- package/lib/AgenticaSelectBenchmark.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +449 -0
- package/lib/index.mjs.map +1 -0
- package/lib/internal/AgenticaBenchmarkPredicator.d.ts +32 -0
- package/lib/internal/AgenticaBenchmarkPredicator.js +179 -0
- package/lib/internal/AgenticaBenchmarkPredicator.js.map +1 -0
- package/lib/internal/AgenticaBenchmarkUtil.d.ts +5 -0
- package/lib/internal/AgenticaBenchmarkUtil.js +37 -0
- package/lib/internal/AgenticaBenchmarkUtil.js.map +1 -0
- package/lib/internal/AgenticaCallBenchmarkReporter.d.ts +4 -0
- package/lib/internal/AgenticaCallBenchmarkReporter.js +136 -0
- package/lib/internal/AgenticaCallBenchmarkReporter.js.map +1 -0
- package/lib/internal/AgenticaPromptReporter.d.ts +4 -0
- package/lib/internal/AgenticaPromptReporter.js +49 -0
- package/lib/internal/AgenticaPromptReporter.js.map +1 -0
- package/lib/internal/AgenticaSelectBenchmarkReporter.d.ts +1 -0
- package/lib/internal/AgenticaSelectBenchmarkReporter.js +172 -0
- package/lib/internal/AgenticaSelectBenchmarkReporter.js.map +1 -0
- package/lib/structures/IAgenticaBenchmarkExpected.d.ts +44 -0
- package/lib/structures/IAgenticaBenchmarkExpected.js +3 -0
- package/lib/structures/IAgenticaBenchmarkExpected.js.map +1 -0
- package/lib/structures/IAgenticaCallBenchmarkEvent.d.ts +95 -0
- package/lib/structures/IAgenticaCallBenchmarkEvent.js +3 -0
- package/lib/structures/IAgenticaCallBenchmarkEvent.js.map +1 -0
- package/lib/structures/IAgenticaCallBenchmarkResult.d.ts +62 -0
- package/lib/structures/IAgenticaCallBenchmarkResult.js +3 -0
- package/lib/structures/IAgenticaCallBenchmarkResult.js.map +1 -0
- package/lib/structures/IAgenticaCallBenchmarkScenario.d.ts +36 -0
- package/lib/structures/IAgenticaCallBenchmarkScenario.js +3 -0
- package/lib/structures/IAgenticaCallBenchmarkScenario.js.map +1 -0
- package/lib/structures/IAgenticaSelectBenchmarkEvent.d.ts +92 -0
- package/lib/structures/IAgenticaSelectBenchmarkEvent.js +3 -0
- package/lib/structures/IAgenticaSelectBenchmarkEvent.js.map +1 -0
- package/lib/structures/IAgenticaSelectBenchmarkResult.d.ts +62 -0
- package/lib/structures/IAgenticaSelectBenchmarkResult.js +3 -0
- package/lib/structures/IAgenticaSelectBenchmarkResult.js.map +1 -0
- package/lib/structures/IAgenticaSelectBenchmarkScenario.d.ts +36 -0
- package/lib/structures/IAgenticaSelectBenchmarkScenario.js +3 -0
- package/lib/structures/IAgenticaSelectBenchmarkScenario.js.map +1 -0
- package/lib/utils/MathUtil.d.ts +3 -0
- package/lib/utils/MathUtil.js +8 -0
- package/lib/utils/MathUtil.js.map +1 -0
- package/lib/utils/TokenUsageComputer.d.ts +5 -0
- package/lib/utils/TokenUsageComputer.js +37 -0
- package/lib/utils/TokenUsageComputer.js.map +1 -0
- package/package.json +57 -0
- package/src/AgenticaCallBenchmark.ts +259 -0
- package/src/AgenticaSelectBenchmark.ts +262 -0
- package/src/index.ts +3 -0
- package/src/internal/AgenticaBenchmarkPredicator.ts +216 -0
- package/src/internal/AgenticaBenchmarkUtil.ts +40 -0
- package/src/internal/AgenticaCallBenchmarkReporter.ts +177 -0
- package/src/internal/AgenticaPromptReporter.ts +43 -0
- package/src/internal/AgenticaSelectBenchmarkReporter.ts +212 -0
- package/src/structures/IAgenticaBenchmarkExpected.ts +58 -0
- package/src/structures/IAgenticaCallBenchmarkEvent.ts +109 -0
- package/src/structures/IAgenticaCallBenchmarkResult.ts +69 -0
- package/src/structures/IAgenticaCallBenchmarkScenario.ts +39 -0
- package/src/structures/IAgenticaSelectBenchmarkEvent.ts +110 -0
- package/src/structures/IAgenticaSelectBenchmarkResult.ts +69 -0
- package/src/structures/IAgenticaSelectBenchmarkScenario.ts +39 -0
- package/src/utils/MathUtil.ts +3 -0
- package/src/utils/TokenUsageComputer.ts +40 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { IAgenticaOperation } from "@agentica/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Expected operation determinant.
|
|
5
|
+
*
|
|
6
|
+
* `IAgenticaBenchmarkExpected` is a type for determining what
|
|
7
|
+
* operation is expected in the benchmarking.
|
|
8
|
+
*
|
|
9
|
+
* And `IAgenticaBenchmarkExpected` is an union type of 4 types,
|
|
10
|
+
* especially designed for the detailed determination of the expected
|
|
11
|
+
* operations.
|
|
12
|
+
*
|
|
13
|
+
* @author Samchon
|
|
14
|
+
*/
|
|
15
|
+
export type IAgenticaBenchmarkExpected =
|
|
16
|
+
| IAgenticaBenchmarkExpected.IAllOf
|
|
17
|
+
| IAgenticaBenchmarkExpected.IAnyOf
|
|
18
|
+
| IAgenticaBenchmarkExpected.IArray
|
|
19
|
+
| IAgenticaBenchmarkExpected.IStandalone;
|
|
20
|
+
export namespace IAgenticaBenchmarkExpected {
|
|
21
|
+
/**
|
|
22
|
+
* All of them must meet the condition, but sequence is not important.
|
|
23
|
+
*/
|
|
24
|
+
export interface IAllOf {
|
|
25
|
+
type: "allOf";
|
|
26
|
+
allOf: Array<
|
|
27
|
+
Exclude<IAgenticaBenchmarkExpected, IAgenticaBenchmarkExpected.IAllOf>
|
|
28
|
+
>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* At least one of them must meet the condition.
|
|
33
|
+
*/
|
|
34
|
+
export interface IAnyOf {
|
|
35
|
+
type: "anyOf";
|
|
36
|
+
anyOf: Array<
|
|
37
|
+
Exclude<IAgenticaBenchmarkExpected, IAgenticaBenchmarkExpected.IAnyOf>
|
|
38
|
+
>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* All of them must meet the condition, and sequence is important.
|
|
43
|
+
*/
|
|
44
|
+
export interface IArray {
|
|
45
|
+
type: "array";
|
|
46
|
+
items: Array<
|
|
47
|
+
Exclude<IAgenticaBenchmarkExpected, IAgenticaBenchmarkExpected.IArray>
|
|
48
|
+
>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Standalone operation.
|
|
53
|
+
*/
|
|
54
|
+
export interface IStandalone {
|
|
55
|
+
type: "standalone";
|
|
56
|
+
operation: IAgenticaOperation;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { IAgenticaPrompt, IAgenticaTokenUsage } from "@agentica/core";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaCallBenchmarkScenario } from "./IAgenticaCallBenchmarkScenario";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Event of LLM function selection benchmark.
|
|
7
|
+
*
|
|
8
|
+
* `IAgenticaCallBenchmarkEvent` is an union type of the events occurred
|
|
9
|
+
* during the LLM function calling benchmark, representing one phase of
|
|
10
|
+
* the benchmark testing about a scenario.
|
|
11
|
+
*
|
|
12
|
+
* In other words, when {@link AgenticaCallBenchmark} executes the
|
|
13
|
+
* benchmark, it will run the benchmark will test a scenario repeately with
|
|
14
|
+
* the given configuration {@link AgenticaCallBenchmark.IConfig.repeat}.
|
|
15
|
+
* And in the repeated benchmark about a scenario,
|
|
16
|
+
* `IAgenticaCallBenchmarkEvent` is one of the repeated testing.
|
|
17
|
+
*
|
|
18
|
+
* For reference, `IAgenticaCallBenchmarkEvent` is categorized into three
|
|
19
|
+
* types: `success`, `failure`, and `error`. The `success` means the
|
|
20
|
+
* benchmark testing is fully meet the expected scenario, and `failure`
|
|
21
|
+
* means that the `selector` or `caller` agents had not selected or
|
|
22
|
+
* called the expected operations. The last type, `error`, means that
|
|
23
|
+
* an error had been occurred during the benchmark testing.
|
|
24
|
+
*
|
|
25
|
+
* @author Samchon
|
|
26
|
+
*/
|
|
27
|
+
export type IAgenticaCallBenchmarkEvent =
|
|
28
|
+
| IAgenticaCallBenchmarkEvent.ISuccess
|
|
29
|
+
| IAgenticaCallBenchmarkEvent.IFailure
|
|
30
|
+
| IAgenticaCallBenchmarkEvent.IError;
|
|
31
|
+
export namespace IAgenticaCallBenchmarkEvent {
|
|
32
|
+
/**
|
|
33
|
+
* Success event type.
|
|
34
|
+
*
|
|
35
|
+
* The `success` event type represents that the benchmark
|
|
36
|
+
* testing is fully meet the expected scenario.
|
|
37
|
+
*/
|
|
38
|
+
export interface ISuccess extends IEventBase<"success"> {
|
|
39
|
+
/**
|
|
40
|
+
* Whether succeeded to function selection.
|
|
41
|
+
*/
|
|
42
|
+
select: true;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether succeeded to function call.
|
|
46
|
+
*/
|
|
47
|
+
call: true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Failure event type.
|
|
52
|
+
*
|
|
53
|
+
* The `failure` event type represents that the `selector`
|
|
54
|
+
* or `caller` agents have not selected or called following the
|
|
55
|
+
* expected scenario in the benchmark testing.
|
|
56
|
+
*/
|
|
57
|
+
export interface IFailure extends IEventBase<"failure"> {
|
|
58
|
+
/**
|
|
59
|
+
* Whether succeeded to function selection.
|
|
60
|
+
*/
|
|
61
|
+
select: boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Whether succeeded to function call.
|
|
65
|
+
*/
|
|
66
|
+
call: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface IError extends IEventBase<"error"> {
|
|
70
|
+
/**
|
|
71
|
+
* Error occurred during the benchmark.
|
|
72
|
+
*/
|
|
73
|
+
error: unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface IEventBase<Type extends string> {
|
|
77
|
+
/**
|
|
78
|
+
* Discriminant type.
|
|
79
|
+
*/
|
|
80
|
+
type: Type;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Expected scenario.
|
|
84
|
+
*/
|
|
85
|
+
scenario: IAgenticaCallBenchmarkScenario;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Prompt histories.
|
|
89
|
+
*
|
|
90
|
+
* List of prompts occurred during the benchmark testing.
|
|
91
|
+
*/
|
|
92
|
+
prompts: IAgenticaPrompt[];
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Usage of the token during the benchmark.
|
|
96
|
+
*/
|
|
97
|
+
usage: IAgenticaTokenUsage;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* When the benchmark testing started.
|
|
101
|
+
*/
|
|
102
|
+
started_at: Date;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* When the benchmark testing completed.
|
|
106
|
+
*/
|
|
107
|
+
completed_at: Date;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { IAgenticaTokenUsage } from "@agentica/core";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaCallBenchmarkEvent } from "./IAgenticaCallBenchmarkEvent";
|
|
4
|
+
import { IAgenticaCallBenchmarkScenario } from "./IAgenticaCallBenchmarkScenario";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Result of the LLM function calling benchmark.
|
|
8
|
+
*
|
|
9
|
+
* `IAgenticaCallBenchmarkResult` is a structure representing the result
|
|
10
|
+
* of the LLM function calling benchmark executed by the
|
|
11
|
+
* {@link AgenticaCallBenchmark.execute execute} function.
|
|
12
|
+
*
|
|
13
|
+
* It contains every experiment results for each scenario, and aggregated
|
|
14
|
+
* LLM token cost in the benchmark process.
|
|
15
|
+
*
|
|
16
|
+
* In each scenario, as the benchmark program experiments multiple times
|
|
17
|
+
* about a scenario, it will contain multiple events. Also, because of the
|
|
18
|
+
* characteristics of the LLM which is not predictable, the result can be
|
|
19
|
+
* different in each event.
|
|
20
|
+
*
|
|
21
|
+
* @author Samchon
|
|
22
|
+
*/
|
|
23
|
+
export interface IAgenticaCallBenchmarkResult {
|
|
24
|
+
/**
|
|
25
|
+
* Experiments for each scenario.
|
|
26
|
+
*/
|
|
27
|
+
experiments: IAgenticaCallBenchmarkResult.IExperiment[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Aggregated token usage information.
|
|
31
|
+
*/
|
|
32
|
+
usage: IAgenticaTokenUsage;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Start time of the benchmark.
|
|
36
|
+
*/
|
|
37
|
+
started_at: Date;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* End time of the benchmark.
|
|
41
|
+
*/
|
|
42
|
+
completed_at: Date;
|
|
43
|
+
}
|
|
44
|
+
export namespace IAgenticaCallBenchmarkResult {
|
|
45
|
+
/**
|
|
46
|
+
* Experiment result about a scenario.
|
|
47
|
+
*/
|
|
48
|
+
export interface IExperiment {
|
|
49
|
+
/**
|
|
50
|
+
* Scenario of the experiment.
|
|
51
|
+
*/
|
|
52
|
+
scenario: IAgenticaCallBenchmarkScenario;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Events occurred during the benchmark in the scenario.
|
|
56
|
+
*
|
|
57
|
+
* When benchmarking a scenario, {@link AgenticaCallBenchmark} will
|
|
58
|
+
* test a scenario multiple times with the given
|
|
59
|
+
* {@link AgenticaCallBenchmark.IConfig.repeat repeat} count.
|
|
60
|
+
* And the event is one of the repeated benchmark results.
|
|
61
|
+
*/
|
|
62
|
+
events: IAgenticaCallBenchmarkEvent[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* LLM token usage information.
|
|
66
|
+
*/
|
|
67
|
+
usage: IAgenticaTokenUsage;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IAgenticaBenchmarkExpected } from "./IAgenticaBenchmarkExpected";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scenario of function calling.
|
|
5
|
+
*
|
|
6
|
+
* `IAgenticaCallBenchmarkScenario` is a data structure which
|
|
7
|
+
* represents a function calling benchmark scenario. It contains two
|
|
8
|
+
* properties; {@linkk text} and {@link operations}.
|
|
9
|
+
*
|
|
10
|
+
* The {@link text} means the conversation text from the user, and
|
|
11
|
+
* the other {@link operations} are the expected operations that
|
|
12
|
+
* should be selected by the `caller` agent through the {@link text}
|
|
13
|
+
* conversation.
|
|
14
|
+
*
|
|
15
|
+
* @author Samchon
|
|
16
|
+
*/
|
|
17
|
+
export interface IAgenticaCallBenchmarkScenario {
|
|
18
|
+
/**
|
|
19
|
+
* Name of the scenario.
|
|
20
|
+
*
|
|
21
|
+
* It must be unique within the benchmark scenarios.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The prompt text from user.
|
|
27
|
+
*/
|
|
28
|
+
text: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Expected function calling sequence.
|
|
32
|
+
*
|
|
33
|
+
* Sequence of operations (API operation or class function) that
|
|
34
|
+
* should be called by both `selector` and `caller` agents from
|
|
35
|
+
* the user's {@link text} conversation for the LLM
|
|
36
|
+
* (Large Language Model) function calling.
|
|
37
|
+
*/
|
|
38
|
+
expected: IAgenticaBenchmarkExpected;
|
|
39
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAgenticaOperationSelection,
|
|
3
|
+
IAgenticaPrompt,
|
|
4
|
+
IAgenticaTokenUsage,
|
|
5
|
+
} from "@agentica/core";
|
|
6
|
+
|
|
7
|
+
import { IAgenticaSelectBenchmarkScenario } from "./IAgenticaSelectBenchmarkScenario";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Event of LLM function selection benchmark.
|
|
11
|
+
*
|
|
12
|
+
* `IAgenticaSelectBenchmarkEvent` is an union type of the events occurred
|
|
13
|
+
* during the LLM function selection benchmark, representing one phase of
|
|
14
|
+
* the benchmark testing about a scenario.
|
|
15
|
+
*
|
|
16
|
+
* In other words, when {@link AgenticaSelectBenchmark} executes the
|
|
17
|
+
* benchmark, it will run the benchmark will test a scenario repeately with
|
|
18
|
+
* the given configuration {@link AgenticaSelectBenchmark.IConfig.repeat}.
|
|
19
|
+
* And in the repeated benchmark about a scenario,
|
|
20
|
+
* `IAgenticaSelectBenchmarkEvent` is one of the repeated testing.
|
|
21
|
+
*
|
|
22
|
+
* For reference, `IAgenticaSelectBenchmarkEvent` is categorized into three
|
|
23
|
+
* types: `success`, `failure`, and `error`. The `success` means the
|
|
24
|
+
* benchmark testing is fully meet the expected scenario, and `failure`
|
|
25
|
+
* means that the `selector` had not selected the expected operations. The
|
|
26
|
+
* last type, `error`, means that an error had been occurred during the
|
|
27
|
+
* benchmark testing.
|
|
28
|
+
*
|
|
29
|
+
* @author Samchon
|
|
30
|
+
*/
|
|
31
|
+
export type IAgenticaSelectBenchmarkEvent =
|
|
32
|
+
| IAgenticaSelectBenchmarkEvent.ISuccess
|
|
33
|
+
| IAgenticaSelectBenchmarkEvent.IFailure
|
|
34
|
+
| IAgenticaSelectBenchmarkEvent.IError;
|
|
35
|
+
export namespace IAgenticaSelectBenchmarkEvent {
|
|
36
|
+
/**
|
|
37
|
+
* Success event type.
|
|
38
|
+
*
|
|
39
|
+
* The `success` event type represents that the benchmark testing is
|
|
40
|
+
* fully meet the expected scenario.
|
|
41
|
+
*/
|
|
42
|
+
export interface ISuccess extends IEventBase<"success"> {
|
|
43
|
+
/**
|
|
44
|
+
* Usage of the token during the benchmark.
|
|
45
|
+
*/
|
|
46
|
+
usage: IAgenticaTokenUsage;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Selected operations in the benchmark.
|
|
50
|
+
*/
|
|
51
|
+
selected: IAgenticaOperationSelection[];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Prompt messages from the assistant.
|
|
55
|
+
*/
|
|
56
|
+
assistantPrompts: IAgenticaPrompt.IText<"assistant">[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Failure event type.
|
|
61
|
+
*
|
|
62
|
+
* The `failure` event type represents that the `selector` had not
|
|
63
|
+
* selected the expected scenario in the benchmark testing.
|
|
64
|
+
*/
|
|
65
|
+
export interface IFailure extends IEventBase<"failure"> {
|
|
66
|
+
/**
|
|
67
|
+
* Usage of the token during the benchmark.
|
|
68
|
+
*/
|
|
69
|
+
usage: IAgenticaTokenUsage;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Selected operations in the benchmark.
|
|
73
|
+
*/
|
|
74
|
+
selected: IAgenticaOperationSelection[];
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Prompt messages from the assistant.
|
|
78
|
+
*/
|
|
79
|
+
assistantPrompts: IAgenticaPrompt.IText<"assistant">[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface IError extends IEventBase<"error"> {
|
|
83
|
+
/**
|
|
84
|
+
* Error occurred during the benchmark.
|
|
85
|
+
*/
|
|
86
|
+
error: unknown;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface IEventBase<Type extends string> {
|
|
90
|
+
/**
|
|
91
|
+
* Discriminant type.
|
|
92
|
+
*/
|
|
93
|
+
type: Type;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Expected scenario.
|
|
97
|
+
*/
|
|
98
|
+
scenario: IAgenticaSelectBenchmarkScenario;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* When the benchmark testing started.
|
|
102
|
+
*/
|
|
103
|
+
started_at: Date;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* When the benchmark testing completed.
|
|
107
|
+
*/
|
|
108
|
+
completed_at: Date;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { IAgenticaTokenUsage } from "@agentica/core";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaSelectBenchmarkEvent } from "./IAgenticaSelectBenchmarkEvent";
|
|
4
|
+
import { IAgenticaSelectBenchmarkScenario } from "./IAgenticaSelectBenchmarkScenario";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Result of the LLM function selection benchmark.
|
|
8
|
+
*
|
|
9
|
+
* `IAgenticaSelectBenchmarkResult` is a structure representing the result
|
|
10
|
+
* of the LLM function selection benchmark executed by the
|
|
11
|
+
* {@link AgenticaSelectBenchmark.execute execute} function.
|
|
12
|
+
*
|
|
13
|
+
* It contains every experiment results for each scenario, and aggregated
|
|
14
|
+
* LLM token cost in the benchmark process.
|
|
15
|
+
*
|
|
16
|
+
* In each scenario, as the benchmark program experiments multiple times
|
|
17
|
+
* about a scenario, it will contain multiple events. Also, because of the
|
|
18
|
+
* characteristics of the LLM which is not predictable, the result can be
|
|
19
|
+
* different in each event.
|
|
20
|
+
*
|
|
21
|
+
* @author Samchon
|
|
22
|
+
*/
|
|
23
|
+
export interface IAgenticaSelectBenchmarkResult {
|
|
24
|
+
/**
|
|
25
|
+
* Experiments for each scenario.
|
|
26
|
+
*/
|
|
27
|
+
experiments: IAgenticaSelectBenchmarkResult.IExperiment[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Aggregated token usage information.
|
|
31
|
+
*/
|
|
32
|
+
usage: IAgenticaTokenUsage;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Start time of the benchmark.
|
|
36
|
+
*/
|
|
37
|
+
started_at: Date;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* End time of the benchmark.
|
|
41
|
+
*/
|
|
42
|
+
completed_at: Date;
|
|
43
|
+
}
|
|
44
|
+
export namespace IAgenticaSelectBenchmarkResult {
|
|
45
|
+
/**
|
|
46
|
+
* Experiment result about a scenario.
|
|
47
|
+
*/
|
|
48
|
+
export interface IExperiment {
|
|
49
|
+
/**
|
|
50
|
+
* Expected scenario.
|
|
51
|
+
*/
|
|
52
|
+
scenario: IAgenticaSelectBenchmarkScenario;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Events occurred during the benchmark in the scenario.
|
|
56
|
+
*
|
|
57
|
+
* When benchmarking a scenario, {@link AgenticaSelectBenchmark} will
|
|
58
|
+
* test a scenario multiple times with the given
|
|
59
|
+
* {@link AgenticaSelectBenchmark.IConfig.repeat repeat} count.
|
|
60
|
+
* And the event is one of the repeated benchmark results.
|
|
61
|
+
*/
|
|
62
|
+
events: IAgenticaSelectBenchmarkEvent[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* LLM token usage information.
|
|
66
|
+
*/
|
|
67
|
+
usage: IAgenticaTokenUsage;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IAgenticaBenchmarkExpected } from "./IAgenticaBenchmarkExpected";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scenario of function selection.
|
|
5
|
+
*
|
|
6
|
+
* `IAgenticaSelectBenchmarkScenario` is a data structure which
|
|
7
|
+
* represents a function selection benchmark scenario. It contains two
|
|
8
|
+
* properties; {@linkk text} and {@link operations}.
|
|
9
|
+
*
|
|
10
|
+
* The {@link text} means the conversation text from the user, and
|
|
11
|
+
* the other {@link operations} are the expected operations that
|
|
12
|
+
* should be selected by the `selector` agent through the {@link text}
|
|
13
|
+
* conversation.
|
|
14
|
+
*
|
|
15
|
+
* @author Samchon
|
|
16
|
+
*/
|
|
17
|
+
export interface IAgenticaSelectBenchmarkScenario {
|
|
18
|
+
/**
|
|
19
|
+
* Name of the scenario.
|
|
20
|
+
*
|
|
21
|
+
* It must be unique within the benchmark scenarios.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The prompt text from user.
|
|
27
|
+
*/
|
|
28
|
+
text: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Expected function selection sequence.
|
|
32
|
+
*
|
|
33
|
+
* Sequence of operations (API operation or class function) that
|
|
34
|
+
* should be selected by the `selector` agent from the user's
|
|
35
|
+
* {@link text} conversation for the LLM (Large Language Model)
|
|
36
|
+
* function selection.
|
|
37
|
+
*/
|
|
38
|
+
expected: IAgenticaBenchmarkExpected;
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IAgenticaTokenUsage } from "@agentica/core/src/structures/IAgenticaTokenUsage";
|
|
2
|
+
|
|
3
|
+
export namespace TokenUsageComputer {
|
|
4
|
+
export const zero = (): IAgenticaTokenUsage => ({
|
|
5
|
+
total: 0,
|
|
6
|
+
prompt: {
|
|
7
|
+
total: 0,
|
|
8
|
+
audio: 0,
|
|
9
|
+
cached: 0,
|
|
10
|
+
},
|
|
11
|
+
completion: {
|
|
12
|
+
total: 0,
|
|
13
|
+
accepted_prediction: 0,
|
|
14
|
+
audio: 0,
|
|
15
|
+
reasoning: 0,
|
|
16
|
+
rejected_prediction: 0,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const plus = (
|
|
21
|
+
a: IAgenticaTokenUsage,
|
|
22
|
+
b: IAgenticaTokenUsage,
|
|
23
|
+
): IAgenticaTokenUsage => ({
|
|
24
|
+
total: a.total + b.total,
|
|
25
|
+
prompt: {
|
|
26
|
+
total: a.prompt.total + b.prompt.total,
|
|
27
|
+
audio: a.prompt.audio + b.prompt.audio,
|
|
28
|
+
cached: a.prompt.cached + b.prompt.cached,
|
|
29
|
+
},
|
|
30
|
+
completion: {
|
|
31
|
+
total: a.completion.total + b.completion.total,
|
|
32
|
+
accepted_prediction:
|
|
33
|
+
a.completion.accepted_prediction + b.completion.accepted_prediction,
|
|
34
|
+
audio: a.completion.audio + b.completion.audio,
|
|
35
|
+
reasoning: a.completion.reasoning + b.completion.reasoning,
|
|
36
|
+
rejected_prediction:
|
|
37
|
+
a.completion.rejected_prediction + b.completion.rejected_prediction,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|