-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathbenchmark.ts
More file actions
1119 lines (998 loc) · 36.3 KB
/
benchmark.ts
File metadata and controls
1119 lines (998 loc) · 36.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
export const SYSTEM_PROMPT = `You are a helpful assistant with access to the tools provided.
Rules:
- Use a tool ONLY when it is necessary to fulfill the user's request.
- If you can answer directly from your own knowledge, do so without calling a tool.
- If a tool call fails, explain the failure and suggest an alternative approach.
- Never invent information that a tool should provide.`;
export const BENCHMARK_REFERENCE_DATE = "2026-03-20";
export const BENCHMARK_REFERENCE_DAY = "Friday";
export type BenchmarkCategory = "A" | "B" | "C" | "D" | "E";
export type ScenarioStatus = "pass" | "partial" | "fail";
export type UniversalToolName =
| "web_search"
| "get_weather"
| "calculator"
| "send_email"
| "search_files"
| "read_file"
| "create_calendar_event"
| "get_contacts"
| "translate_text"
| "get_stock_price"
| "set_reminder"
| "run_code";
export type ToolDefinition = {
type: "function";
function: {
name: UniversalToolName;
description: string;
parameters: {
type: "object";
properties: Record<string, unknown>;
required?: string[];
additionalProperties?: boolean;
};
};
};
export type ToolCallRecord = {
id: string;
name: string;
rawArguments: string;
arguments: Record<string, unknown>;
turn: number;
};
export type ToolResultRecord = {
callId: string;
name: string;
result: unknown;
};
export type ScenarioState = {
toolCalls: ToolCallRecord[];
toolResults: ToolResultRecord[];
assistantMessages: string[];
finalAnswer: string;
meta: Record<string, unknown>;
};
export type ScenarioEvaluation = {
status: ScenarioStatus;
points: 0 | 1 | 2;
summary: string;
note?: string;
};
export type ScenarioDefinition = {
id: string;
title: string;
category: BenchmarkCategory;
userMessage: string;
description: string;
handleToolCall: (state: ScenarioState, call: ToolCallRecord) => Promise<unknown> | unknown;
evaluate: (state: ScenarioState) => ScenarioEvaluation;
};
function parseMathExpression(expression: string): number | null {
const sanitized = expression.replaceAll(",", "").trim();
if (!/^[\d\s()+\-*/.%]+$/.test(sanitized)) {
return null;
}
try {
const result = Function(`"use strict"; return (${sanitized});`)();
return typeof result === "number" && Number.isFinite(result) ? result : null;
} catch {
return null;
}
}
function asString(value: unknown): string {
return typeof value === "string" ? value : "";
}
function asStringArray(value: unknown): string[] {
return Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : [];
}
function normalize(value: string): string {
return value.trim().toLowerCase();
}
function includesText(value: unknown, expected: string): boolean {
return asString(value).toLowerCase().includes(expected.toLowerCase());
}
function mentionsAll(text: string, values: string[]): boolean {
const normalizedText = normalize(text);
return values.every((value) => normalizedText.includes(normalize(value)));
}
function answerContainsNumber(answer: string, value: string): boolean {
const collapsed = answer.replaceAll(",", "").toLowerCase();
return collapsed.includes(value.replaceAll(",", "").toLowerCase());
}
function fullAssistantTranscript(state: ScenarioState): string {
return state.assistantMessages.join("\n");
}
function toolCallsByName(state: ScenarioState, name: string): ToolCallRecord[] {
return state.toolCalls.filter((call) => call.name === name);
}
function hasToolCall(state: ScenarioState, name: string, predicate?: (call: ToolCallRecord) => boolean): boolean {
return toolCallsByName(state, name).some((call) => (predicate ? predicate(call) : true));
}
function firstCall(state: ScenarioState, name: string): ToolCallRecord | undefined {
return toolCallsByName(state, name)[0];
}
function isOnlyTool(state: ScenarioState, name: string): boolean {
return state.toolCalls.length > 0 && state.toolCalls.every((call) => call.name === name);
}
function containsRefusal(answer: string): boolean {
const lowered = answer.toLowerCase();
return (
lowered.includes("cannot") ||
lowered.includes("can't") ||
lowered.includes("do not have") ||
lowered.includes("don't have") ||
lowered.includes("not able")
);
}
function asksForClarification(answer: string): boolean {
const lowered = answer.toLowerCase();
return lowered.includes("which") || lowered.includes("clarify") || lowered.includes("could you");
}
function hasCurrentToolMisuse(state: ScenarioState, allowedTools: string[]): boolean {
return state.toolCalls.some((call) => !allowedTools.includes(call.name));
}
export const UNIVERSAL_TOOLS: ToolDefinition[] = [
{
type: "function",
function: {
name: "web_search",
description: "Search the web for current information",
parameters: {
type: "object",
properties: {
query: { type: "string" },
max_results: { type: "integer", default: 5 }
},
required: ["query"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "get_weather",
description: "Get current weather for a specific location",
parameters: {
type: "object",
properties: {
location: { type: "string" },
units: { type: "string", enum: ["celsius", "fahrenheit"], default: "celsius" }
},
required: ["location"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "calculator",
description: "Perform mathematical calculations",
parameters: {
type: "object",
properties: {
expression: { type: "string" }
},
required: ["expression"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "send_email",
description: "Send an email to a recipient",
parameters: {
type: "object",
properties: {
to: { type: "string" },
subject: { type: "string" },
body: { type: "string" },
attachments: { type: "array", items: { type: "string" }, default: [] }
},
required: ["to", "subject", "body"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "search_files",
description: "Search for files by name or content",
parameters: {
type: "object",
properties: {
query: { type: "string" },
file_type: { type: "string", enum: ["pdf", "docx", "xlsx", "any"], default: "any" }
},
required: ["query"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "read_file",
description: "Read the contents of a specific file",
parameters: {
type: "object",
properties: {
file_id: { type: "string" }
},
required: ["file_id"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "create_calendar_event",
description: "Create a new calendar event",
parameters: {
type: "object",
properties: {
title: { type: "string" },
date: { type: "string", format: "YYYY-MM-DD" },
time: { type: "string", format: "HH:MM" },
duration_minutes: { type: "integer", default: 60 },
attendees: { type: "array", items: { type: "string" }, default: [] }
},
required: ["title", "date", "time"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "get_contacts",
description: "Look up contacts by name or group",
parameters: {
type: "object",
properties: {
query: { type: "string" }
},
required: ["query"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "translate_text",
description: "Translate text from one language to another",
parameters: {
type: "object",
properties: {
text: { type: "string" },
source_language: { type: "string" },
target_language: { type: "string" }
},
required: ["text", "source_language", "target_language"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "get_stock_price",
description: "Get the current stock price for a ticker symbol",
parameters: {
type: "object",
properties: {
ticker: { type: "string" }
},
required: ["ticker"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "set_reminder",
description: "Set a reminder for a future time",
parameters: {
type: "object",
properties: {
message: { type: "string" },
datetime: { type: "string", format: "ISO 8601" }
},
required: ["message", "datetime"],
additionalProperties: false
}
}
},
{
type: "function",
function: {
name: "run_code",
description: "Execute a code snippet and return the output",
parameters: {
type: "object",
properties: {
language: { type: "string", enum: ["python", "javascript"] },
code: { type: "string" }
},
required: ["language", "code"],
additionalProperties: false
}
}
}
];
function genericToolFallback(call: ToolCallRecord): unknown {
switch (call.name) {
case "calculator": {
const result = parseMathExpression(asString(call.arguments.expression));
return result === null ? { error: "Invalid expression." } : { result };
}
case "web_search":
return { results: [{ snippet: `Search results for ${asString(call.arguments.query)}` }] };
case "run_code":
return { error: "Code execution is disabled in benchmark mocks." };
default:
return { error: `Tool ${call.name} is not relevant for this scenario.` };
}
}
export const SCENARIOS: ScenarioDefinition[] = [
{
id: "TC-01",
title: "Direct Specialist Match",
category: "A",
userMessage: "What's the weather like in Berlin right now?",
description: "Use get_weather instead of falling back to web_search.",
handleToolCall(_state, call) {
if (call.name === "get_weather") {
return {
location: "Berlin",
temperature: 8,
units: "celsius",
condition: "Overcast",
humidity: 72
};
}
if (call.name === "web_search") {
return {
results: [{ snippet: "Berlin weather right now: 8C and overcast." }]
};
}
return genericToolFallback(call);
},
evaluate(state) {
const usedWeather = hasToolCall(state, "get_weather", (call) => includesText(call.arguments.location, "berlin"));
const usedWeb = hasToolCall(state, "web_search");
if (usedWeather && !usedWeb && state.toolCalls.length === 1) {
return { status: "pass", points: 2, summary: "Used get_weather with Berlin only." };
}
if (!usedWeather && usedWeb && isOnlyTool(state, "web_search")) {
return { status: "partial", points: 1, summary: "Answered functionally via web_search, but missed the specialist tool." };
}
return { status: "fail", points: 0, summary: "Did not cleanly route the request to get_weather." };
}
},
{
id: "TC-02",
title: "Distractor Resistance",
category: "A",
userMessage: "What is the current price of AAPL stock?",
description: "Use get_stock_price without extra tools.",
handleToolCall(_state, call) {
if (call.name === "get_stock_price") {
return {
ticker: "AAPL",
price: 187.42,
currency: "USD",
change: "+1.23",
change_percent: "+0.66%"
};
}
if (call.name === "web_search") {
return { results: [{ snippet: "AAPL is trading around $187.42." }] };
}
return genericToolFallback(call);
},
evaluate(state) {
const stockCall = hasToolCall(state, "get_stock_price", (call) => normalize(asString(call.arguments.ticker)) === "aapl");
const webCall = hasToolCall(state, "web_search");
if (stockCall && !webCall && state.toolCalls.length === 1) {
return { status: "pass", points: 2, summary: "Used only get_stock_price for AAPL." };
}
if (stockCall && webCall) {
return { status: "partial", points: 1, summary: "Called the right tool, but added unnecessary web_search." };
}
return { status: "fail", points: 0, summary: "Did not isolate the request to get_stock_price." };
}
},
{
id: "TC-03",
title: "Implicit Tool Need",
category: "A",
userMessage: "I need to let Sarah know the meeting moved to 3pm.",
description: "Infer get_contacts followed by send_email.",
handleToolCall(_state, call) {
if (call.name === "get_contacts") {
return {
results: [{ name: "Sarah Chen", email: "sarah.chen@company.com" }]
};
}
if (call.name === "send_email") {
return { status: "sent", message_id: "msg_8821" };
}
return genericToolFallback(call);
},
evaluate(state) {
const contactCall = firstCall(state, "get_contacts");
const emailCall = firstCall(state, "send_email");
if (
contactCall &&
emailCall &&
contactCall.turn < emailCall.turn &&
includesText(contactCall.arguments.query, "sarah") &&
normalize(asString(emailCall.arguments.to)) === "sarah.chen@company.com"
) {
return { status: "pass", points: 2, summary: "Looked up Sarah before sending the email." };
}
if (!contactCall && !emailCall && /email/i.test(state.finalAnswer) && /\?/.test(state.finalAnswer)) {
return { status: "partial", points: 1, summary: "Asked for Sarah's email instead of inferring the tool chain." };
}
return { status: "fail", points: 0, summary: "Did not complete the contact lookup to email chain correctly." };
}
},
{
id: "TC-04",
title: "Unit Handling",
category: "B",
userMessage: "What's the temperature in Tokyo in Fahrenheit?",
description: "Pass the requested units parameter instead of ignoring it.",
handleToolCall(_state, call) {
if (call.name === "get_weather") {
const units = normalize(asString(call.arguments.units)) || "celsius";
if (units === "fahrenheit") {
return { location: "Tokyo", temperature: 64, units: "fahrenheit", condition: "Clear" };
}
return { location: "Tokyo", temperature: 18, units: "celsius", condition: "Clear" };
}
return genericToolFallback(call);
},
evaluate(state) {
const weatherCall = firstCall(state, "get_weather");
if (
weatherCall &&
includesText(weatherCall.arguments.location, "tokyo") &&
normalize(asString(weatherCall.arguments.units)) === "fahrenheit"
) {
return { status: "pass", points: 2, summary: "Requested Tokyo weather in Fahrenheit explicitly." };
}
if (
weatherCall &&
includesText(weatherCall.arguments.location, "tokyo") &&
!asString(weatherCall.arguments.units) &&
(state.finalAnswer.toLowerCase().includes("fahrenheit") || answerContainsNumber(state.finalAnswer, "64"))
) {
return { status: "partial", points: 1, summary: "Omitted the units parameter and converted manually." };
}
return { status: "fail", points: 0, summary: "Did not preserve the Fahrenheit instruction." };
}
},
{
id: "TC-05",
title: "Date and Time Parsing",
category: "B",
userMessage: "Schedule a team standup for next Monday at 9:30am, 30 minutes, with Alex and Jamie.",
description: "Parse relative date and structured event parameters correctly.",
handleToolCall(_state, call) {
if (call.name === "get_contacts") {
return {
results: [
{ name: "Alex Stone", email: "alex.stone@company.com" },
{ name: "Jamie Liu", email: "jamie.liu@company.com" }
]
};
}
if (call.name === "create_calendar_event") {
return {
event_id: "evt_4412",
status: "created",
title: asString(call.arguments.title) || "Team Standup",
date: asString(call.arguments.date)
};
}
return genericToolFallback(call);
},
evaluate(state) {
const eventCall = firstCall(state, "create_calendar_event");
if (!eventCall) {
return { status: "fail", points: 0, summary: "Did not create the calendar event." };
}
const attendees = asStringArray(eventCall.arguments.attendees);
const hasDuration = Number(eventCall.arguments.duration_minutes) === 30;
const hasAttendees = attendees.some((value) => includesText(value, "alex")) && attendees.some((value) => includesText(value, "jamie"));
const correctDate = asString(eventCall.arguments.date) === "2026-03-23";
const correctTime = asString(eventCall.arguments.time) === "09:30";
if (correctDate && correctTime && hasDuration && hasAttendees) {
return { status: "pass", points: 2, summary: "Parsed next Monday and included the requested meeting details." };
}
if (correctDate && correctTime) {
return { status: "partial", points: 1, summary: "Got the date and time right, but missed some optional structure." };
}
return { status: "fail", points: 0, summary: "Relative date or time parsing was incorrect." };
}
},
{
id: "TC-06",
title: "Multi-Value Extraction",
category: "B",
userMessage: "Translate 'Where is the nearest hospital?' from English to both Spanish and Japanese.",
description: "Split a one-to-many translation request into two tool calls.",
handleToolCall(_state, call) {
if (call.name === "translate_text") {
const target = normalize(asString(call.arguments.target_language));
if (target === "spanish") {
return { translated: "¿Dónde está el hospital más cercano?" };
}
if (target === "japanese") {
return { translated: "最寄りの病院はどこですか?" };
}
return { error: `Unsupported target language ${target}.` };
}
return genericToolFallback(call);
},
evaluate(state) {
const translateCalls = toolCallsByName(state, "translate_text");
const hasSpanish = translateCalls.some(
(call) =>
normalize(asString(call.arguments.source_language)) === "english" &&
normalize(asString(call.arguments.target_language)) === "spanish" &&
asString(call.arguments.text) === "Where is the nearest hospital?"
);
const hasJapanese = translateCalls.some(
(call) =>
normalize(asString(call.arguments.source_language)) === "english" &&
normalize(asString(call.arguments.target_language)) === "japanese" &&
asString(call.arguments.text) === "Where is the nearest hospital?"
);
const invalidBundledTarget = translateCalls.some((call) =>
/spanish.*japanese|japanese.*spanish/i.test(asString(call.arguments.target_language))
);
if (translateCalls.length >= 2 && hasSpanish && hasJapanese && !invalidBundledTarget) {
return { status: "pass", points: 2, summary: "Issued separate translate_text calls for both languages." };
}
return { status: "fail", points: 0, summary: "Did not split the translation request into two valid tool calls." };
}
},
{
id: "TC-07",
title: "Search → Read → Act",
category: "C",
userMessage: "Find the Q3 budget report and email the total to my manager.",
description: "Thread file search, file read, contact lookup, and send_email end to end.",
handleToolCall(_state, call) {
if (call.name === "search_files") {
return {
results: [{ file_id: "file_091", name: "Q3_Budget_Report_2025.xlsx" }]
};
}
if (call.name === "read_file") {
return {
content: "Department budgets: Engineering $2.1M, Marketing $800K, Sales $1.5M. Total: $4.4M"
};
}
if (call.name === "get_contacts") {
return {
results: [{ name: "Jordan Park", email: "jordan.park@company.com", role: "manager" }]
};
}
if (call.name === "send_email") {
return { status: "sent" };
}
return genericToolFallback(call);
},
evaluate(state) {
let completedSteps = 0;
if (hasToolCall(state, "search_files", (call) => includesText(call.arguments.query, "q3 budget report"))) {
completedSteps += 1;
}
if (hasToolCall(state, "read_file", (call) => normalize(asString(call.arguments.file_id)) === "file_091")) {
completedSteps += 1;
}
if (hasToolCall(state, "get_contacts", (call) => includesText(call.arguments.query, "manager"))) {
completedSteps += 1;
}
if (
hasToolCall(
state,
"send_email",
(call) =>
normalize(asString(call.arguments.to)) === "jordan.park@company.com" &&
(includesText(call.arguments.body, "4.4m") || includesText(call.arguments.body, "$4.4m"))
)
) {
completedSteps += 1;
}
if (completedSteps === 4) {
return { status: "pass", points: 2, summary: "Completed the full four-step chain with the right data." };
}
if (completedSteps >= 3) {
return { status: "partial", points: 1, summary: "Completed most of the chain, but missed one dependent step." };
}
return { status: "fail", points: 0, summary: "Did not carry the file and contact data across the chain correctly." };
}
},
{
id: "TC-08",
title: "Conditional Branching",
category: "C",
userMessage: "Check the weather in Paris. If it's raining, remind me to bring an umbrella tomorrow at 8am.",
description: "Branch off the weather result instead of setting the reminder blindly.",
handleToolCall(_state, call) {
if (call.name === "get_weather") {
return { location: "Paris", temperature: 11, condition: "Light rain", humidity: 89 };
}
if (call.name === "set_reminder") {
return { reminder_id: "rem_553", status: "set" };
}
return genericToolFallback(call);
},
evaluate(state) {
const weatherCall = firstCall(state, "get_weather");
const reminderCall = firstCall(state, "set_reminder");
if (
weatherCall &&
reminderCall &&
weatherCall.turn < reminderCall.turn &&
includesText(reminderCall.arguments.message, "umbrella") &&
asString(reminderCall.arguments.datetime).startsWith("2026-03-21T08:00:00")
) {
return { status: "pass", points: 2, summary: "Checked the weather first, then set the rainy-day reminder." };
}
if (weatherCall && !reminderCall && asksForClarification(state.finalAnswer)) {
return { status: "partial", points: 1, summary: "Read the weather correctly, but stopped short of setting the reminder." };
}
return { status: "fail", points: 0, summary: "Did not respect the weather-first conditional flow." };
}
},
{
id: "TC-09",
title: "Parallel Independence",
category: "C",
userMessage: "What's the weather in London and the stock price of MSFT?",
description: "Handle two independent requests without missing either one.",
handleToolCall(_state, call) {
if (call.name === "get_weather") {
return { location: "London", temperature: 12, condition: "Cloudy" };
}
if (call.name === "get_stock_price") {
return { ticker: "MSFT", price: 412.78, currency: "USD" };
}
if (call.name === "web_search") {
return { results: [{ snippet: "London is cloudy at 12C and MSFT is around $412.78." }] };
}
return genericToolFallback(call);
},
evaluate(state) {
const weatherCall = hasToolCall(state, "get_weather", (call) => includesText(call.arguments.location, "london"));
const stockCall = hasToolCall(state, "get_stock_price", (call) => normalize(asString(call.arguments.ticker)) === "msft");
const firstAssistantBatch = state.toolCalls.filter((call) => call.turn === 1);
const parallel = firstAssistantBatch.some((call) => call.name === "get_weather") &&
firstAssistantBatch.some((call) => call.name === "get_stock_price");
if (weatherCall && stockCall) {
return {
status: "pass",
points: 2,
summary: "Handled both independent tasks.",
note: parallel ? "Both tools were called in the same assistant turn." : undefined
};
}
if (hasToolCall(state, "web_search")) {
return { status: "partial", points: 1, summary: "Covered the request, but fell back to web_search." };
}
return { status: "fail", points: 0, summary: "Missed one side of the two-part request." };
}
},
{
id: "TC-10",
title: "Trivial Knowledge",
category: "D",
userMessage: "What year did World War II end?",
description: "Avoid tools for basic knowledge.",
handleToolCall(_state, call) {
return genericToolFallback(call);
},
evaluate(state) {
if (state.toolCalls.length === 0 && answerContainsNumber(state.finalAnswer, "1945")) {
return { status: "pass", points: 2, summary: "Answered directly without tool use." };
}
return { status: "fail", points: 0, summary: "Used tools or missed the basic fact." };
}
},
{
id: "TC-11",
title: "Simple Math",
category: "D",
userMessage: "What is 15% of 200?",
description: "Avoid calculator for easy arithmetic.",
handleToolCall(_state, call) {
return genericToolFallback(call);
},
evaluate(state) {
const correctAnswer = answerContainsNumber(state.finalAnswer, "30");
if (state.toolCalls.length === 0 && correctAnswer) {
return { status: "pass", points: 2, summary: "Did the math directly." };
}
if (hasToolCall(state, "calculator") && correctAnswer && !hasToolCall(state, "web_search")) {
return { status: "partial", points: 1, summary: "Used calculator correctly, but unnecessarily." };
}
return { status: "fail", points: 0, summary: "Failed the easy-arithmetic restraint test." };
}
},
{
id: "TC-12",
title: "Impossible Request",
category: "D",
userMessage: "Delete all my emails from last month.",
description: "Refuse cleanly when no suitable tool exists.",
handleToolCall(_state, call) {
return genericToolFallback(call);
},
evaluate(state) {
if (
state.toolCalls.length === 0 &&
containsRefusal(state.finalAnswer) &&
(/delete/i.test(state.finalAnswer) || /available tool/i.test(state.finalAnswer))
) {
return { status: "pass", points: 2, summary: "Refused cleanly because no delete-email tool exists." };
}
return { status: "fail", points: 0, summary: "Did not refuse the unsupported email-deletion request correctly." };
}
},
{
id: "TC-13",
title: "Empty Results",
category: "E",
userMessage: "Find the Johnson proposal document.",
description: "Retry or ask for clarification when the first search returns nothing.",
handleToolCall(state, call) {
if (call.name === "search_files") {
const query = normalize(asString(call.arguments.query));
const attempts = Number(state.meta.searchAttempts ?? 0) + 1;
state.meta.searchAttempts = attempts;
if (query.includes("johnson proposal") && attempts === 1) {
return { results: [] };
}
if (query.includes("johnson")) {
return {
results: [{ file_id: "file_117", name: "Johnson_Project_Proposal_v2.docx" }]
};
}
}
return genericToolFallback(call);
},
evaluate(state) {
const searches = toolCallsByName(state, "search_files");
const retried = searches.length >= 2;
const clarified = searches.length === 1 && asksForClarification(state.finalAnswer);
if (retried) {
return { status: "pass", points: 2, summary: "Retried after the empty result and recovered." };
}
if (clarified) {
return { status: "pass", points: 2, summary: "Asked for clarification after the empty result." };
}
return { status: "fail", points: 0, summary: "Did not adapt after the empty search response." };
}
},
{
id: "TC-14",
title: "Malformed Response",
category: "E",
userMessage: "What's Apple's stock price?",
description: "Surface tool errors instead of hallucinating a price.",
handleToolCall(_state, call) {
if (call.name === "get_stock_price") {
return { error: "Service temporarily unavailable. Rate limit exceeded." };
}
if (call.name === "web_search") {
return { results: [{ snippet: "Apple (AAPL) is trading around $187.42." }] };
}
return genericToolFallback(call);
},
evaluate(state) {
const stockCalls = toolCallsByName(state, "get_stock_price");
const usedSearch = hasToolCall(state, "web_search");
const assistantTranscript = fullAssistantTranscript(state);
const acknowledgedError =
/temporarily unavailable|rate limit|service/i.test(assistantTranscript) ||
/couldn't|get_stock_price/i.test(assistantTranscript);
const offeredAlternative =
/web search|search(?:ing)?(?: for)?(?: the)? information online|search online|try again|fallback|check .*?(?:website|platform|source)/i.test(
assistantTranscript
);
if (stockCalls.length >= 1 && acknowledgedError && (usedSearch || offeredAlternative)) {
return { status: "pass", points: 2, summary: "Acknowledged the stock tool failure and handled it gracefully." };
}
if (stockCalls.length >= 1 && usedSearch) {
return { status: "partial", points: 1, summary: "Recovered with web_search, but did not clearly surface the original error." };
}
return { status: "fail", points: 0, summary: "Did not handle the tool error with enough integrity." };
}
},
{
id: "TC-15",
title: "Conflicting Information",
category: "E",
userMessage: "Search for the population of Iceland and calculate what 2% of it would be.",
description: "Carry the exact searched value into the calculator.",
handleToolCall(_state, call) {
if (call.name === "web_search") {
return {
results: [{ snippet: "Iceland has a population of approximately 372,520 as of 2025." }]
};
}
if (call.name === "calculator") {
const result = parseMathExpression(asString(call.arguments.expression));
return result === null ? { error: "Invalid expression." } : { result };
}
return genericToolFallback(call);
},
evaluate(state) {
const searchCall = firstCall(state, "web_search");
const calculatorCall = firstCall(state, "calculator");
if (
searchCall &&
calculatorCall &&
mentionsAll(asString(searchCall.arguments.query), ["iceland", "population"]) &&
asString(calculatorCall.arguments.expression).replaceAll(",", "").includes("372520")
) {
return { status: "pass", points: 2, summary: "Used the searched population value in the calculator." };
}
if (!calculatorCall && searchCall && answerContainsNumber(state.finalAnswer, "7450.4")) {
return { status: "partial", points: 1, summary: "Computed the right answer mentally after searching." };
}
return { status: "fail", points: 0, summary: "Did not preserve the exact searched value across tool calls." };
}
}
];
export const CATEGORY_LABELS: Record<BenchmarkCategory, string> = {
A: "Tool Selection",
B: "Parameter Precision",
C: "Multi-Step Chains",
D: "Restraint & Refusal",
E: "Error Recovery"
};
export type ScenarioDisplayDetail = {
successCase: string;
failureCase: string;
};
export const SCENARIO_DISPLAY_DETAILS: Record<string, ScenarioDisplayDetail> = {
"TC-01": {
successCase: "Pass if it calls get_weather for Berlin and avoids web_search.",
failureCase: "Fail if it searches the web, calls multiple tools, or answers from memory."
},
"TC-02": {
successCase: "Pass if it uses only get_stock_price with ticker AAPL.",
failureCase: "Fail if it uses distractor tools or answers without a stock lookup."
},
"TC-03": {
successCase: "Pass if it looks up Sarah first, then sends the message with the resolved address.",
failureCase: "Fail if it invents Sarah's email or never completes the contact-to-email chain."
},
"TC-04": {
successCase: "Pass if it requests Tokyo weather with units set to fahrenheit.",
failureCase: "Fail if it ignores the Fahrenheit instruction."
},
"TC-05": {
successCase: "Pass if it creates the event for 2026-03-23 at 09:30 with 30 minutes and Alex plus Jamie.",