-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheval_context_tools.py
More file actions
1295 lines (1184 loc) · 44.9 KB
/
eval_context_tools.py
File metadata and controls
1295 lines (1184 loc) · 44.9 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
"""
Evaluation suite for Librarian MCP tools.
This module defines comprehensive test cases to evaluate how well LLMs
use the agent library tools correctly.
Run with:
arcade evals . -p openai
arcade evals . -p anthropic
arcade evals . --details # For detailed critic feedback
"""
from datetime import datetime, timedelta
from arcade_evals import (
BinaryCritic,
DatetimeCritic,
EvalRubric,
EvalSuite,
ExpectedMCPToolCall,
NumericCritic,
SimilarityCritic,
tool_eval,
)
@tool_eval()
async def search_tools_eval() -> EvalSuite:
"""Evaluate search tool usage and query understanding."""
suite = EvalSuite(
name="Library Search Tools",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"Use the library tools to store, search, and retrieve information. "
"The library persists across sessions and contains notes, documents, and knowledge."
),
rubric=EvalRubric(fail_threshold=0.75, warn_threshold=0.85),
)
# Load tools from the MCP server
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "false"},
)
# ==========================================================================
# Basic Search Queries (all use unified SearchLibrary)
# ==========================================================================
suite.add_case(
name="Simple topic search",
user_message="Find my notes about Python programming",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "Python programming", "limit": 10},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.8),
NumericCritic(critic_field="limit", value_range=(5, 15), weight=0.2),
],
)
suite.add_case(
name="Search with specific limit",
user_message="Show me the top 5 documents about machine learning from my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "machine learning", "limit": 5},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.6),
BinaryCritic(critic_field="limit", weight=0.4),
],
)
suite.add_case(
name="Search for meeting notes",
user_message="Find all my meeting notes from the project kickoff in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "meeting notes project kickoff"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=1.0),
],
)
# ==========================================================================
# Timeframe-based Search (uses timeframe enum parameter)
# ==========================================================================
suite.add_case(
name="Search with today timeframe",
user_message="What did I add to my library today?",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "notes", "timeframe": "today"},
)
],
critics=[
BinaryCritic(critic_field="timeframe", weight=0.8),
SimilarityCritic(critic_field="query", weight=0.2),
],
)
suite.add_case(
name="Search this week",
user_message="Show me everything I stored this week about the API design",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "API design", "timeframe": "this_week"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.5),
BinaryCritic(critic_field="timeframe", weight=0.5),
],
)
suite.add_case(
name="Search last 7 days",
user_message="Find recent notes from the past week about database migrations",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "database migrations", "timeframe": "last_7_days"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.5),
BinaryCritic(critic_field="timeframe", weight=0.5),
],
)
suite.add_case(
name="Search last month",
user_message="What were my notes from last month about the product roadmap?",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "product roadmap", "timeframe": "last_month"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.5),
BinaryCritic(critic_field="timeframe", weight=0.5),
],
)
# ==========================================================================
# Specific Date Range Search (uses start_date/end_date parameters)
# ==========================================================================
# Calculate realistic dates for test cases
today = datetime.now()
last_week_start = (today - timedelta(days=7)).strftime("%Y-%m-%d")
last_week_end = today.strftime("%Y-%m-%d")
suite.add_case(
name="Search with specific date range",
user_message=(
f"Find notes about the sprint review between {last_week_start} and {last_week_end}"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{
"query": "sprint review",
"start_date": last_week_start,
"end_date": last_week_end,
},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.4),
DatetimeCritic(critic_field="start_date", tolerance=timedelta(days=1), weight=0.3),
DatetimeCritic(critic_field="end_date", tolerance=timedelta(days=1), weight=0.3),
],
)
suite.add_case(
name="Search Q4 2025",
user_message="Find all documentation I stored in Q4 2025 about authentication",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{
"query": "authentication",
"start_date": "2025-10-01",
"end_date": "2025-12-31",
},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.4),
DatetimeCritic(critic_field="start_date", tolerance=timedelta(days=3), weight=0.3),
DatetimeCritic(critic_field="end_date", tolerance=timedelta(days=3), weight=0.3),
],
)
# ==========================================================================
# Search Mode Selection (semantic vs keyword via mode parameter)
# ==========================================================================
suite.add_case(
name="Semantic search request",
user_message=(
"Find information in my library that is conceptually related to "
"containerization and Docker"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "containerization Docker", "mode": "semantic"},
)
],
critics=[
# The mode choice is the actual subject of this case; the query
# text is incidental, so mode gets the heavier weight.
SimilarityCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
suite.add_case(
name="Exact keyword search",
user_message="Search for the exact term 'JIRA-1234' in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "JIRA-1234", "mode": "keyword"},
)
],
critics=[
BinaryCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
return suite
@tool_eval()
async def document_management_eval() -> EvalSuite:
"""Evaluate document creation, reading, and management tools."""
suite = EvalSuite(
name="Library Management",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"You can add, read, update, and remove information from the library. "
"Use the library to store and retrieve notes, documents, and any useful information."
),
rubric=EvalRubric(fail_threshold=0.75, warn_threshold=0.85),
)
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "false"},
)
# ==========================================================================
# Adding to Library
# ==========================================================================
suite.add_case(
name="Store simple note",
user_message=(
"Save a note called 'meeting-notes' with the content: "
"'# Team Standup\n\nDiscussed sprint goals.'"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_AddToLibrary",
{
"title": "meeting-notes",
"content": "# Team Standup\n\nDiscussed sprint goals.",
},
)
],
critics=[
BinaryCritic(critic_field="title", weight=0.5),
SimilarityCritic(critic_field="content", weight=0.5),
],
)
suite.add_case(
name="Store note with tags",
user_message=(
"Add to my library a document called 'project-plan' with tags 'planning' and 'q1' "
"about the project timeline"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_AddToLibrary",
{
"title": "project-plan",
"content": "project timeline",
"tags": ["planning", "q1"],
},
)
],
critics=[
BinaryCritic(critic_field="title", weight=0.4),
SimilarityCritic(critic_field="content", weight=0.3),
SimilarityCritic(critic_field="tags", weight=0.3),
],
)
# ==========================================================================
# Reading from Library
# ==========================================================================
suite.add_case(
name="Read specific document",
user_message="Show me the full contents of /documents/readme.md from my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_ReadFromLibrary",
{"path": "/documents/readme.md"},
)
],
critics=[
BinaryCritic(critic_field="path", weight=1.0),
],
)
suite.add_case(
name="List library contents",
user_message="Show me everything in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_ListLibraryContents",
{},
)
],
critics=[], # No parameters to validate
)
# ==========================================================================
# Updating Library Content
# ==========================================================================
suite.add_case(
name="Update document content",
user_message=(
"Update the content at /notes/todo.md with: '# Updated Todo\n\n- [ ] New task'"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_UpdateLibraryDoc",
{
"path": "/notes/todo.md",
"content": "# Updated Todo\n\n- [ ] New task",
},
)
],
critics=[
BinaryCritic(critic_field="path", weight=0.5),
SimilarityCritic(critic_field="content", weight=0.5),
],
)
# ==========================================================================
# Removing from Library
# ==========================================================================
suite.add_case(
name="Remove from index only",
user_message=("Remove /old/archive.md from my library search but keep the file on disk"),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_RemoveFromLibrary",
{"path": "/old/archive.md", "delete_file": False},
)
],
critics=[
BinaryCritic(critic_field="path", weight=0.6),
BinaryCritic(critic_field="delete_file", weight=0.4),
],
)
suite.add_case(
name="Permanently delete",
user_message="Permanently delete /temp/scratch.md from my library and disk",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_RemoveFromLibrary",
{"path": "/temp/scratch.md", "delete_file": True},
)
],
critics=[
BinaryCritic(critic_field="path", weight=0.6),
BinaryCritic(critic_field="delete_file", weight=0.4),
],
)
# Store to an explicit directory — covers a path the model must lift from
# the user message rather than defaulting.
suite.add_case(
name="Store note to explicit directory",
user_message=(
"Save a note called 'deploy-plan' into /Users/me/work-notes/deploys "
"with the content: '# Deploy Plan\n\nStage 1: canary'"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_AddToLibrary",
{
"title": "deploy-plan",
"content": "# Deploy Plan\n\nStage 1: canary",
"directory": "/Users/me/work-notes/deploys",
},
)
],
critics=[
BinaryCritic(critic_field="title", weight=0.3),
SimilarityCritic(critic_field="content", weight=0.2),
BinaryCritic(critic_field="directory", weight=0.5),
],
)
# Remove without mentioning file deletion — model should leave delete_file
# at the default (False), so we assert the tool + path and do NOT assert
# delete_file (the auto-NoneCritic will cover the unchecked field).
suite.add_case(
name="Remove without mentioning file deletion",
user_message="Take /archive/old-spec.md out of my library index",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_RemoveFromLibrary",
{"path": "/archive/old-spec.md"},
)
],
critics=[
BinaryCritic(critic_field="path", weight=1.0),
],
)
return suite
@tool_eval()
async def ingestion_eval() -> EvalSuite:
"""Evaluate document ingestion tools."""
suite = EvalSuite(
name="Library Ingestion",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"You can add entire directories of files to the library for indexing and search."
),
rubric=EvalRubric(fail_threshold=0.7, warn_threshold=0.85),
)
# This suite tests the optional GetLibraryOverview tool alongside the core
# IndexDirectoryToLibrary tool, so optional tools must be enabled here
# (the other suites disable them to keep tool-selection unambiguous
# between direct actions and workflow helpers).
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "true"},
)
# ==========================================================================
# Directory Ingestion
# ==========================================================================
suite.add_case(
name="Index specific directory",
user_message="Add all files from /projects/documentation to my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_IndexDirectoryToLibrary",
{"directory": "/projects/documentation"},
)
],
critics=[
BinaryCritic(critic_field="directory", weight=1.0),
],
)
suite.add_case(
name="Index notes directory",
user_message="Index everything in /notes into my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_IndexDirectoryToLibrary",
{"directory": "/notes"},
)
],
critics=[
BinaryCritic(critic_field="directory", weight=1.0),
],
)
# ==========================================================================
# Library overview (consolidated stats / sections / tree)
# ==========================================================================
suite.add_case(
name="Get library statistics (view=stats)",
user_message="How many documents do I have in my library?",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_GetLibraryOverview",
{"view": "stats"},
)
],
critics=[
BinaryCritic(critic_field="view", weight=1.0),
],
)
suite.add_case(
name="Show library tree (view=tree)",
user_message="Show me the folder layout of my library so I can see how it's organized",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_GetLibraryOverview",
{"view": "tree"},
)
],
critics=[
BinaryCritic(critic_field="view", weight=1.0),
],
)
return suite
@tool_eval()
async def location_workflow_eval() -> EvalSuite:
"""Evaluate the 'where should I put this?' workflow helpers.
GetLibraryOverview (default view='sections') is the canonical pre-flight
call before AddToLibrary, and SuggestLibraryLocation is the smart-default
for content the user hasn't filed by hand. These cases verify the model
picks each one in the right context.
"""
suite = EvalSuite(
name="Library Location Workflow",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"Before storing new content, figure out where it belongs. "
"Use GetLibraryOverview to enumerate writable locations, "
"or SuggestLibraryLocation to get ranked recommendations based on "
"title and content."
),
rubric=EvalRubric(fail_threshold=0.7, warn_threshold=0.85),
)
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "true"},
)
suite.add_case(
name="Enumerate available sections",
user_message="Where can I save things in my library? Show me the sections.",
expected_tool_calls=[
# Default view is 'sections', so passing nothing — or view='sections' —
# are both correct.
ExpectedMCPToolCall("Librarian_GetLibraryOverview", {}),
],
critics=[], # Tool selection alone carries the signal.
)
suite.add_case(
name="Ask for placement recommendation",
user_message=(
"I've got some notes on rate limiting strategies — "
"where should I file this in my library?"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SuggestLibraryLocation",
{"title": "rate limiting strategies"},
)
],
critics=[
SimilarityCritic(critic_field="title", weight=1.0),
],
)
suite.add_case(
name="Suggestion with content summary",
user_message=(
"Help me find the best place to put a doc titled 'Q2 OKRs' "
"about engineering team objectives for next quarter"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SuggestLibraryLocation",
{
"title": "Q2 OKRs",
"content_summary": "engineering team objectives for next quarter",
},
)
],
critics=[
SimilarityCritic(critic_field="title", weight=0.5),
SimilarityCritic(
critic_field="content_summary", weight=0.5, similarity_threshold=0.5
),
],
)
return suite
@tool_eval()
async def complex_workflows_eval() -> EvalSuite:
"""Evaluate complex multi-step workflows."""
suite = EvalSuite(
name="Complex Library Workflows",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"You can store, search, and manage information in the library. "
"Perform multi-step operations when needed to help the user."
),
rubric=EvalRubric(fail_threshold=0.7, warn_threshold=0.85),
)
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "false"},
)
# ==========================================================================
# Multi-step Operations
# ==========================================================================
suite.add_case(
name="Search then read",
user_message="Find my notes about the budget and show me the most relevant one",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "budget", "limit": 1},
),
],
critics=[
SimilarityCritic(critic_field="query", weight=0.7),
NumericCritic(critic_field="limit", value_range=(1, 5), weight=0.3),
],
)
suite.add_case(
name="Search code assets",
user_message="Find authentication code in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "authentication", "asset_type": "code"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.6),
BinaryCritic(critic_field="asset_type", weight=0.4),
],
)
suite.add_case(
name="Search PDFs only",
user_message="Search my PDF documents for information about the contract terms",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "contract terms", "asset_type": "pdf"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.6),
BinaryCritic(critic_field="asset_type", weight=0.4),
],
)
return suite
@tool_eval()
async def multimodal_eval() -> EvalSuite:
"""Evaluate multi-modal asset type handling."""
suite = EvalSuite(
name="Multi-Modal Library Support",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"The library supports multiple asset types: text, code, PDFs, and images. "
"Use the SearchLibrary tool with the 'mode' parameter for semantic or keyword "
"search, and 'asset_type' to filter by content type."
),
rubric=EvalRubric(fail_threshold=0.7, warn_threshold=0.85),
)
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "false"},
)
# ==========================================================================
# Multi-Modal Search
# ==========================================================================
suite.add_case(
name="Search returns asset_type",
user_message="Search my library for calculator",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "calculator"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=1.0),
],
)
suite.add_case(
name="Semantic search via mode parameter",
user_message="Find conceptually similar content about data structures in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "data structures", "mode": "semantic"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
suite.add_case(
name="Keyword search via mode parameter",
user_message="Search for the exact keyword 'Calculator' in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "Calculator", "mode": "keyword"},
)
],
critics=[
BinaryCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
suite.add_case(
name="Index code directory",
user_message="Add all files from /projects/api-server to my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_IndexDirectoryToLibrary",
{"directory": "/projects/api-server"},
)
],
critics=[
BinaryCritic(critic_field="directory", weight=1.0),
],
)
suite.add_case(
name="Search with code asset type filter",
user_message="Find authentication functions in my code files",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "authentication functions", "asset_type": "code"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.6),
BinaryCritic(critic_field="asset_type", weight=0.4),
],
)
return suite
@tool_eval()
async def adversarial_eval() -> EvalSuite:
"""Adversarial coverage: ambiguous phrasings, boundary values, mode/asset-type
inference, date-range parsing, and tool-selection traps.
Looser rubric (fail=0.6, warn=0.75) is intentional: these cases are designed
to expose weak spots, not to enforce 100% pass rates.
"""
suite = EvalSuite(
name="Library Adversarial Coverage",
system_message=(
"You are a helpful assistant with access to a personal knowledge library. "
"Choose the right tool and arguments for each request. Prefer direct "
"action tools over discovery/workflow tools when the user's intent is "
"clear."
),
rubric=EvalRubric(fail_threshold=0.6, warn_threshold=0.75),
)
# Keep the tool surface constrained to the 7 core tools so tool selection
# isn't diluted by the optional workflow helpers.
await suite.add_mcp_stdio_server(
command=["uv", "run", "python", "-m", "librarian.server", "stdio"],
env={"LIBRARIAN_ENABLE_OPTIONAL_TOOLS": "false"},
)
# ==========================================================================
# Block A — Tool selection under ambiguity
# ==========================================================================
suite.add_case(
name="List everything I have",
user_message="List everything I have in my library",
expected_tool_calls=[
ExpectedMCPToolCall("Librarian_ListLibraryContents", {}),
],
critics=[], # Tool-selection correctness is enforced by the rubric.
)
# Realistic phrasing of "do I have notes on X?" — the answer comes from
# search, not from list/read. This replaces an earlier "Is /tmp/foo.md in
# my library?" case that didn't match how users actually ask.
suite.add_case(
name="Existential search query",
user_message="Do I have any notes on Kubernetes networking?",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "Kubernetes networking"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=1.0),
],
)
suite.add_case(
name="Search inside an indexed folder",
user_message=(
"I want to see what's in the api-server folder I indexed "
"— anything about rate limiting?"
),
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "rate limiting api-server"},
)
],
critics=[
# Threshold loosened; phrasing of the query will vary.
SimilarityCritic(
critic_field="query", weight=1.0, similarity_threshold=0.5
),
],
)
suite.add_case(
name="Unindex jargon",
user_message="Unindex /old/archive.md from my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_RemoveFromLibrary",
{"path": "/old/archive.md", "delete_file": False},
)
],
critics=[
BinaryCritic(critic_field="path", weight=0.5),
BinaryCritic(critic_field="delete_file", weight=0.5),
],
)
suite.add_case(
name="Permanent-delete slang",
user_message="Nuke /temp/scratch.md from orbit",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_RemoveFromLibrary",
{"path": "/temp/scratch.md", "delete_file": True},
)
],
critics=[
BinaryCritic(critic_field="path", weight=0.5),
BinaryCritic(critic_field="delete_file", weight=0.5),
],
)
# ==========================================================================
# Block B — Mode inference
# ==========================================================================
suite.add_case(
name="Semantic phrasing — conceptually similar",
user_message="Find notes conceptually similar to 'distributed consensus'",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "distributed consensus", "mode": "semantic"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
suite.add_case(
name="Keyword phrasing — literal string",
user_message="Find notes that literally contain the string 'TODO(spartee)'",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "TODO(spartee)", "mode": "keyword"},
)
],
critics=[
# Exact-string — BinaryCritic, not SimilarityCritic, because the
# whole point is that the model preserves the exact token.
BinaryCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
suite.add_case(
name="Hybrid default — best overall match",
user_message="Search my library for budget forecasting — best overall match",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "budget forecasting"},
)
],
critics=[
# Intentionally no mode critic: either omitting mode (defaults to
# hybrid) or passing mode="hybrid" is acceptable.
SimilarityCritic(critic_field="query", weight=1.0),
],
)
suite.add_case(
name="Keyword phrasing — exact phrase",
user_message="I know the exact phrase — find 'eventual consistency' in my library",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "eventual consistency", "mode": "keyword"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="mode", weight=0.6),
],
)
# ==========================================================================
# Block C — Asset-type inference
# ==========================================================================
suite.add_case(
name="Infer asset_type=code from language cue",
user_message="Find Python code dealing with JWT parsing",
expected_tool_calls=[
ExpectedMCPToolCall(
"Librarian_SearchLibrary",
{"query": "JWT parsing", "asset_type": "code"},
)
],
critics=[
SimilarityCritic(critic_field="query", weight=0.4),
BinaryCritic(critic_field="asset_type", weight=0.6),
],
)
# Prior context establishes the user just indexed image-format diagrams,
# so "diagrams" should now resolve to asset_type=image rather than text.
# This is a realistic agent scenario — the tool catalog plus conversation
# history together carry the signal.
suite.add_case(
name="Infer asset_type=image from 'diagrams' (with context)",
user_message="Pull up the diagrams about the auth flow",
additional_messages=[
{
"role": "user",
"content": (
"I just indexed our architecture folder — it's mostly PNG "
"diagrams alongside the docs."
),
},
{
"role": "assistant",
"content": (
"Got it — your library now includes the architecture "
"diagrams alongside the existing documentation."
),
},