File size: 99,459 Bytes
f6686e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>tinytroupe.experimentation.proposition API documentation</title>
<meta name="description" content="" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>tinytroupe.experimentation.proposition</code></h1>
</header>
<section id="section-intro">
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">import json
from chevron import render

from tinytroupe.agent import TinyPerson
from tinytroupe.environment import TinyWorld
from tinytroupe.utils import LLMChat, indent_at_current_level
from tinytroupe.experimentation import logger


from tinytroupe import default

class Proposition:

    MIN_SCORE = 0
    MAX_SCORE = 9

    def __init__(self, claim:str, target=None, include_personas:bool=False, first_n:int=None, last_n:int=None,
                 double_check:bool=False, use_reasoning_model:bool=False, precondition_function=None):
        &#34;&#34;&#34; 
        Define a proposition as a (textual) claim about a target, which can be a TinyWorld, a TinyPerson or several of any.
        The proposition&#39;s truth value can then either be checked as a boolean or computed as an integer score denoting the degree of truth.

        Sometimes a proposition is better used in an implicative way, i.e., as a claim that is true or false depending on the context. For example, when
        considering the latest agent action, the proposition might be applicable only to certain agent action types. To allow this,
        this class allows to define a precondition function, which effectivelly turns a proposition `P` into `Precondition --&gt; P`. This is logically equivalent to
        `not P or Precondition`. In other words:
          - if the precondition is true, then the proposition is evaluated normally (as a boolean or a score).
          - if the precondition is false, then the proposition is always true (or with highest score).
          - if the precondition is None, then the proposition is evaluated normally (as a boolean or a score).
        

        Args:
            
            claim (str): the claim of the proposition
            target (TinyWorld, TinyPerson, list): the target or targets of the proposition. If not given, it will have to be specified later.
            include_personas (bool): whether to include the persona specifications of the agents in the context
            first_n (int): the number of first interactions to consider in the context
            last_n (int): the number of last interactions (most recent) to consider in the context
            double_check (bool): whether to ask the LLM to double check its answer. This tends to give more strict answers, but is slower and more expensive.
            use_reasoning_model (bool): whether to use a reasoning model to evaluate the proposition
            precondition_function (function): a Boolean function that indicates whether the proposition can be evaluated or not. This is useful to avoid evaluating propositions that are not relevant for the current context. If the precondition fails, the proposition is always interpreted as true (or with highest score). MUST have named arguments `target`, `additional_context`, and `claim_variables` (note: you can use a lambda for this too, e.g., `lambda target, additional_context, claim_variables: ...`).

        &#34;&#34;&#34;
        
        self.claim = claim
        self.targets = self._target_as_list(target)
        self.include_personas = include_personas
        
        self.first_n = first_n
        self.last_n = last_n

        self.double_check = double_check

        self.use_reasoning_model = use_reasoning_model

        self.precondition_function = precondition_function

        # the chat with the LLM is preserved until the proposition is re-evaluated. While it is available,
        # the chat can be used to follow up on the proposition, e.g., to ask for more details about the evaluation.
        self.llm_chat = None
        
        self.value = None
        self.justification = None
        self.confidence = None
        self.recommendations = None

    def __copy__(self):
        &#34;&#34;&#34;
        Create a shallow copy of the proposition without any evaluation state.
        
        Returns:
            Proposition: A new proposition with the same configuration parameters.
        &#34;&#34;&#34;
        new_prop = Proposition(
            claim=self.claim,
            target=self.targets,
            include_personas=self.include_personas,
            first_n=self.first_n,
            last_n=self.last_n,
            double_check=self.double_check,
            use_reasoning_model=self.use_reasoning_model,
            precondition_function=self.precondition_function
        )
        return new_prop

    def copy(self):
        &#34;&#34;&#34;
        Create a shallow copy of the proposition without any evaluation state.
        
        Returns:
            Proposition: A new proposition with the same configuration parameters.
        &#34;&#34;&#34;
        return self.__copy__()
    

    def __call__(self, target=None, additional_context=None, claim_variables:dict={}, return_full_response:bool=False) -&gt; bool:
        return self.check(target=target, additional_context=additional_context, claim_variables=claim_variables, return_full_response=return_full_response)
    

    def _check_precondition(self, target, additional_context:str, claim_variables:dict) -&gt; bool:
        &#34;&#34;&#34;
        Check whether the proposition can be evaluated or not.
        &#34;&#34;&#34;

        if self.precondition_function is None:
            return True
        else:
            return self.precondition_function(target=target, additional_context=additional_context, claim_variables=claim_variables)

    def check(self, target=None, additional_context=&#34;No additional context available.&#34;, claim_variables:dict={}, return_full_response:bool=False) -&gt; bool:
        &#34;&#34;&#34;
        Check whether the proposition holds for the given target(s).
        &#34;&#34;&#34;

        current_targets = self._determine_target(target)

        if self._check_precondition(target=current_targets, additional_context=additional_context, claim_variables=claim_variables) == False:
            self.value = True
            self.justification = &#34;The proposition is trivially true due to the precondition being false.&#34;
            self.confidence = 1.0
            self.full_evaluation_response = {&#34;value&#34;: True, &#34;justification&#34;: self.justification, &#34;confidence&#34;: self.confidence}
        
        else: # precondition is true or None

            context = self._build_context(current_targets)

            # might use a reasoning model, which could allow careful evaluation of the proposition.
            model = self._model(self.use_reasoning_model)

            #render self.claim using the claim_variables via chevron
            rendered_claim = render(self.claim, claim_variables)      

            self.llm_chat = LLMChat(system_prompt=&#34;&#34;&#34;
                                        You are a system that evaluates whether a proposition is true or false with respect to a given context. This context
                                        always refers to a multi-agent simulation. The proposition is a claim about the behavior of the agents or the state of their environment
                                        in the simulation.
                                    
                                        The context you receive can contain one or more of the following:
                                        - the trajectory of a simulation of one or more agents. This means what agents said, did, thought, or perceived at different times.
                                        - the state of the environment at a given time.
                                    
                                        Your output **must**:
                                        - necessarily start with the word &#34;True&#34; or &#34;False&#34;;
                                        - optionally be followed by a justification. Please provide a very detailed justifications, including very concrete and specific mentions to elements that contributed to reducing or increasing the score. Examples:
                                              * WRONG JUSTIFICATION (too abstract) example: &#34; ... the agent behavior did not comply with key parts of its specification, thus a reduced score ... &#34;
                                              * CORRECT JUSTIFICATION (very precise) example: &#34; ... the agent behavior deviated from key parts of its specification, specifically: S_1 was not met because &lt;reason&gt;, ..., S_n was not met becasue &lt;reason&gt;. Thus, a reduced score ...&#34;
                                        
                                        For example, the output could be of the form: &#34;True, because &lt;HIGHLY DETAILED, CONCRETE AND SPECIFIC REASONS HERE&gt;.&#34; or merely &#34;True&#34; if no justification is needed.
                                        &#34;&#34;&#34;, 

                                        user_prompt=f&#34;&#34;&#34;
                                        Evaluate the following proposition with respect to the context provided. Is it True or False?

                                        # Proposition

                                        This is the proposition you must evaluate:

                                            ```
                                            {indent_at_current_level(rendered_claim)}
                                            ```

                                        # Context

                                        The context you must consider is the following.

                                        {indent_at_current_level(context)}

                                        # Additional Context (if any)

                                        {indent_at_current_level(additional_context)}

                                        &#34;&#34;&#34;,

                                        output_type=bool,
                                        enable_reasoning_step=True,

                                        temperature=0.5,
                                        frequency_penalty=0.0, 
                                        presence_penalty=0.0,
                                        model=model)
            
            self.value = self.llm_chat()

            if self.double_check:
                self.llm_chat.add_user_message(&#34;Are you sure? Please revise your evaluation to make is correct as possible.&#34;)
                revised_value = self.llm_chat()
                if revised_value != self.value:
                    logger.warning(f&#34;The LLM revised its evaluation: from {self.value} to {revised_value}.&#34;)
                    self.value = revised_value

            self.reasoning = self.llm_chat.response_reasoning
            self.justification = self.llm_chat.response_justification      
            self.confidence = self.llm_chat.response_confidence

            self.full_evaluation_response = self.llm_chat.response_json

        # return the final result, either only the value or the full response
        if not return_full_response:
            return self.value
        else:
            return self.full_evaluation_response
        
    def score(self, target=None, additional_context=&#34;No additional context available.&#34;, claim_variables:dict={}, return_full_response:bool=False) -&gt; int:
        &#34;&#34;&#34;
        Compute the score for the proposition with respect to the given context.
        &#34;&#34;&#34;

        current_targets = self._determine_target(target)

        if self._check_precondition(target=current_targets, additional_context=additional_context, claim_variables=claim_variables) == False:
            self.value = self.MAX_SCORE
            self.justification = &#34;The proposition is trivially true due to the precondition being false.&#34;
            self.confidence = 1.0
            self.full_evaluation_response = {&#34;value&#34;: self.value, &#34;justification&#34;: self.justification, &#34;confidence&#34;: self.confidence}
        
        else: # precondition is true or None

            # build the context with the appropriate targets
        
            context = self._build_context(current_targets)

            # might use a reasoning model, which could allow careful evaluation of the proposition.
            model = self._model(self.use_reasoning_model)

            #render self.claim using the claim_variables via chevron
            rendered_claim = render(self.claim, claim_variables)      

            self.llm_chat = LLMChat(system_prompt=f&#34;&#34;&#34;
                                        You are a system that computes an integer score (between {Proposition.MIN_SCORE} and {Proposition.MAX_SCORE}, inclusive) about how much a proposition is true or false with respect to a given context. 
                                        This context always refers to a multi-agent simulation. The proposition is a claim about the behavior of the agents or the state of their environment in the simulation.

                                        The minimum score of {Proposition.MIN_SCORE} means that the proposition is completely false in all of the simulation trajectories, while the maximum score of {Proposition.MAX_SCORE} means that the proposition is completely true in all of the simulation trajectories. Intermediate scores are used to express varying degrees of partially met expectations. When assigning a score, follow these guidelines:
                                        - If the data required to judge the proposition is not present, assign a score of {Proposition.MAX_SCORE}. That is to say, unless there is evidence to the contrary, the proposition is assumed to be true.
                                        - The maximum score of {Proposition.MAX_SCORE} should be assigned when the evidence is as good as it can be. That is to say, all parts of the observed simulation trajectory support the proposition, no exceptions.
                                        - The minimum score of {Proposition.MIN_SCORE} should be assigned when the evidence is as bad as it can be. That is to say, all parts of the observed simulation trajectory contradict the proposition, no exceptions.
                                        - Intermediate scores should be assigned when the evidence is mixed. The intermediary score should be proportional to the balance of evidence, according to these bands:
                                                  0 = The proposition is without any doubt completely false;
                                            1, 2, 3 = The proposition has little support and is mostly false;
                                               4, 5 = The evidence is mixed, and the proposition is as much true as it is false;
                                            6, 7, 8 = The proposition is well-supported and is mostly true;
                                                  9 = The proposition is without any doubt completely true.
                                        - You should be very rigorous in your evaluation and, when in doubt, assign a lower score.
                                        - If there are critical flaws in the evidence, you should move your score to a lower band entirely.
                                        - If the provided context has inconsistent information, you **must** consider **only** the information that gives the lowest score, since we want to be rigorous and if necessary err to the lower end.
                                          * If you are considering the relationship between an agent specification and a simulation trajectory, you should consider the worst possible interpretation of: the agent specification; the simulation trajectory; or the relationship between the two.
                                          * These contradictions can appear anywhere in the context. When they do, you **always** adopt the worst possible inteprpretation, because we want to be rigorous and if necessary err to the lower end. It does not matter if the contradiction shows only very rarely, or if it is very small. It is still a contradiction and should be considered as such.
                                          * DO NOT dismiss contradictions as specification errors. They are part of the evidence and should be considered as such. They **must** be **always** taken into account when computing the score. **Never** ignore them.
                                        
                                        Additionally, whenever you are considering the relationship between an agent specification and a simulation trajectory, the following additional scoring guidelines apply:
                                          - All observed behavior **must** be easily mapped back to clear elements of the agent specification. If you cannot do this, you should assign a lower score.
                                          - Evaluate **each** relevant elements in the simulation trajectory (e.g., actions, stimuli) one by one, and assign a score to each of them. The final score is the average of all the scores assigned to each element.
                                                                            
                                        The proposition you receive can contain one or more of the following:
                                          - A statement of fact, which you will score.
                                          - Additional context, which you will use to evaluate the proposition. In particular, it might refer or specify potentail parts
                                            of similation trajectories for consideration. These might be formatted differently than what is given in the main context, so
                                            make sure you read them carefully.
                                          - Additional instructions on how to evaluate the proposition.

                                        The context you receive can contain one or more of the following:
                                          - the persona specifications of the agents in the simulation. That is to say, what the agents **are**, not what they are **doing**.
                                          - the simulation trajectories of one or more agents. This means what agents said, did, thought, or perceived at different times.
                                            These trajectories **are not** part of the persona specification.
                                          - the state of the environment at a given time.
                                          - additional context that can vary from simulation to simulation.
                                        
                                        To interpret the simulation trajectories, use the following guidelines:
                                          - Agents can receive stimuli and produce actions. You might be concerned with both or only one of them, depending on the specific proposition.
                                          - Actions are clearly marked with the text &#34;acts&#34;, e.g., &#34;Agent A acts: [ACTION]&#34;. If it is not thus marked, it is not an action.
                                          - Stimuli are denoted by &#34;--&gt; Agent name: [STIMULUS]&#34;.
                                    
                                        Your output **must**:
                                          - necessarily start with an integer between {Proposition.MIN_SCORE} and {Proposition.MAX_SCORE}, inclusive;
                                          - be followed by a justification. Please provide a very detailed justifications, including very concrete and specific mentions to elements that contributed to reducing or increasing the score. Examples:
                                              * WRONG JUSTIFICATION (too abstract) example: &#34; ... the agent behavior did not comply with key parts of its specification, thus a reduced score ... &#34;
                                              * CORRECT JUSTIFICATION (very precise) example: &#34; ... the agent behavior deviated from key parts of its specification, specifically: S_1 was not met because &lt;reason&gt;, ..., S_n was not met becasue &lt;reason&gt;. Thus, a reduced score ...&#34;
                                        
                                        For example, the output could be of the form: &#34;1, because &lt;HIGHLY DETAILED, CONCRETE AND SPECIFIC REASONS HERE&gt;.&#34;
                                        &#34;&#34;&#34;, 

                                        user_prompt=f&#34;&#34;&#34;
                                        Compute the score for the following proposition with respect to the context provided. Think step-by-step to assign the most accurate score and provide a justification.

                                        # Proposition

                                        This is the proposition you must evaluate:
                                        
                                            ```
                                            {indent_at_current_level(rendered_claim)}
                                            ```

                                        # Context

                                        The context you must consider is the following.

                                        {indent_at_current_level(context)}

                                        # Additional Context (if any)

                                        {indent_at_current_level(additional_context)}   
                                        &#34;&#34;&#34;,

                                        output_type=int,
                                        enable_reasoning_step=True,

                                        temperature=1.0,
                                        frequency_penalty=0.0, 
                                        presence_penalty=0.0,

                                        # Use a reasoning model, which allows careful evaluation of the proposition.
                                        model=model)
            

            self.value = self.llm_chat()

            if self.double_check:
                self.llm_chat.add_user_message(&#34;Are you sure? Please revise your evaluation to make is correct as possible.&#34;)
                revised_value = self.llm_chat()
                if revised_value != self.value:
                    logger.warning(f&#34;The LLM revised its evaluation: from {self.value} to {revised_value}.&#34;)
                    self.value = revised_value

            self.reasoning = self.llm_chat.response_reasoning
            self.justification = self.llm_chat.response_justification      
            self.confidence = self.llm_chat.response_confidence

            self.full_evaluation_response = self.llm_chat.response_json
        
        # return the final result, either only the value or the full response
        if not return_full_response:
            return self.value
        else:
            return self.full_evaluation_response
    
    def recommendations_for_improvement(self):
        &#34;&#34;&#34;
        Get recommendations for improving the proposition.
        &#34;&#34;&#34;

        # TODO this is not working, let&#39;s try something else
        #
        #if self.llm_chat is None:
        #    raise ValueError(&#34;No evaluation has been performed yet. Please evaluate the proposition before getting recommendations.&#34;)
#
        #self.llm_chat.add_system_message(\
        #    &#34;&#34;&#34;
        #    You will now act as a system that provides recommendations for the improvement of the scores previously assigned to propositions.
        #    You will now output text that contains analysises, recommendations and other information as requested by the user.
        #    &#34;&#34;&#34;)
#
        #self.llm_chat.add_user_message(\
        #    &#34;&#34;&#34;    
        #    To help improve the score next time, please list the following in as much detail as possible:
        #      - all recommendations for improvements based on the current score.
        #      - all criteria you are using to assign scores, and how to best satisfy them
#
        #    For both cases:
        #      - besides guidelines, make sure to provide plenty of concrete examples of what to be done in order to maximize each criterion.
        #      - avoid being generic or abstract. Instead, all of your criteria and recommendations should be given in very concrete terms that would work specifically for the case just considered.            
        #    
        #    Note that your output is a TEXT with the various recommendations, information and tips, not a JSON object.
#
        #    Recommendations:
        #    &#34;&#34;&#34;)
        #
        #recommendation = self.llm_chat(output_type=str, enable_json_output_format=False)
        recommendation = &#34;No additional recommendations at this time.&#34;
        return recommendation

    def _model(self, use_reasoning_model):
        if use_reasoning_model:
            return default[&#34;reasoning_model&#34;]
        else:
            return default[&#34;model&#34;]
    
    def _determine_target(self, target):
        &#34;&#34;&#34;
        Determine the target for the proposition. If a target was provided during initialization, it must not be provided now (i.e., the proposition is immutable).
        If no target was provided during initialization, it must be provided now.
        &#34;&#34;&#34;
       # If no target was provided during initialization, it must be provided now.
        if self.targets is None :
            if target is None:
                raise ValueError(&#34;No target specified. Please provide a target.&#34;)
            else:
                return self._target_as_list(target)

        # If it was provided during initialization, it must not be provided now (i.e., the proposition is immutable).
        else:
            if target is not None:
                raise ValueError(&#34;Target already specified. Please do not provide a target.&#34;)
            else:
                return self.targets
        
    def _build_context(self, current_targets):

        #
        # build the context with the appropriate targets
        #
        context = &#34;&#34;

        for target in current_targets:
            target_trajectory = target.pretty_current_interactions(max_content_length=None, first_n=self.first_n, last_n=self.last_n)

            if isinstance(target, TinyPerson):
                if self.include_personas:
                    context += f&#34;## Agent &#39;{target.name}&#39; Persona Specification\n\n&#34;
                    context += &#34;Before presenting the actual simulation trajectory, here is the persona specification of the agent that was used to produce the simulation.\n\n&#34;
                    context += &#34;This IS NOT the actual simulation, but only the static persona specification of the agent.\n\n&#34;
                    context += f&#34;persona={json.dumps(target._persona, indent=4)}\n\n&#34;
                
                context += f&#34;## Agent &#39;{target.name}&#39; Simulation Trajectory (if any)\n\n&#34;
            elif isinstance(target, TinyWorld):
                if self.include_personas:
                    context += f&#34;## Environment &#39;{target.name}&#39; Personas Specifications\n\n&#34;
                    context += &#34;Before presenting the actual simulation trajectory, here are the persona specifications of the agents used to produce the simulation.\n\n&#34;
                    context += &#34;This IS NOT the actual simulation, but only the static persona specification of the agent.\n\n&#34;
                    for agent in target.agents:
                        context += f&#34;### Agent &#39;{agent.name}&#39; Persona Specification\n\n&#34;
                        context += f&#34;persona={json.dumps(agent._persona, indent=4)}\n\n&#34;
                    
                context += f&#34;## Environment &#39;{target.name}&#39; Simulation Trajectory (if any)\n\n&#34;

            context += target_trajectory + &#34;\n\n&#34;

        return context

    def _target_as_list(self, target):
        if target is None:
            return None 
        elif isinstance(target, TinyWorld) or isinstance(target, TinyPerson):
            return [target]
        elif isinstance(target, list) and all(isinstance(t, TinyWorld) or isinstance(t, TinyPerson) for t in target):
            return target
        else:
            raise ValueError(&#34;Target must be a TinyWorld, a TinyPerson or a list of them.&#34;)


def check_proposition(target, claim:str, additional_context=&#34;No additional context available.&#34;,
                      first_n:int=None, last_n:int=None, 
                      return_full_response:bool=False):
    &#34;&#34;&#34;
    Check whether a propositional claim holds for the given target(s). This is meant as a
    convenience method to avoid creating a Proposition object (which you might not need
    if you are not interested in the justification or confidence of the claim, or will
    not use it again).

    Args:
        target (TinyWorld, TinyPerson, list): the target or targets of the proposition
        claim (str): the claim of the proposition
        additional_context (str): additional context to provide to the LLM
        first_n (int): the number of first interactions to consider in the context
        last_n (int): the number of last interactions (most recent) to consider in the context
        return_full_response (bool): whether to return the full response from the LLM, including justification and confidence

    Returns:
        bool: whether the proposition holds for the given target(s)
    &#34;&#34;&#34;

    proposition = Proposition(claim, target, first_n=first_n, last_n=last_n)
    return proposition.check(additional_context=additional_context, return_full_response=return_full_response)


def compute_score(target, claim:str,
                      additional_context=&#34;No additional context available.&#34;,
                      first_n:int=None, last_n:int=None,
                      return_full_response:bool=False):
    &#34;&#34;&#34;
    Compute a score about whether a claim holds for the given target(s). This is meant as a
    convenience method to avoid creating a Score object (which you might not need
    if you are not interested in the justification or confidence of the claim, or will
    not use it again).

    Args:
        target (TinyWorld, TinyPerson, list): the target or targets of the proposition
        claim (str): the claim of the proposition
        additional_context (str): additional context to provide to the LLM
        first_n (int): the number of first interactions to consider in the context
        last_n (int): the number of last interactions (most recent) to consider in the context
        return_full_response (bool): whether to return the full response from the LLM, including justification and confidence

    Returns:
        bool: whether the proposition holds for the given target(s)
    &#34;&#34;&#34;

    score = Proposition(claim, target,
                  first_n=first_n, last_n=last_n)
    return score.compute(additional_context=additional_context, return_full_response=return_full_response)</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="tinytroupe.experimentation.proposition.check_proposition"><code class="name flex">
<span>def <span class="ident">check_proposition</span></span>(<span>target, claim: str, additional_context='No additional context available.', first_n: int = None, last_n: int = None, return_full_response: bool = False)</span>
</code></dt>
<dd>
<div class="desc"><p>Check whether a propositional claim holds for the given target(s). This is meant as a
convenience method to avoid creating a Proposition object (which you might not need
if you are not interested in the justification or confidence of the claim, or will
not use it again).</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>target</code></strong> :&ensp;<code>TinyWorld, TinyPerson, list</code></dt>
<dd>the target or targets of the proposition</dd>
<dt><strong><code>claim</code></strong> :&ensp;<code>str</code></dt>
<dd>the claim of the proposition</dd>
<dt><strong><code>additional_context</code></strong> :&ensp;<code>str</code></dt>
<dd>additional context to provide to the LLM</dd>
<dt><strong><code>first_n</code></strong> :&ensp;<code>int</code></dt>
<dd>the number of first interactions to consider in the context</dd>
<dt><strong><code>last_n</code></strong> :&ensp;<code>int</code></dt>
<dd>the number of last interactions (most recent) to consider in the context</dd>
<dt><strong><code>return_full_response</code></strong> :&ensp;<code>bool</code></dt>
<dd>whether to return the full response from the LLM, including justification and confidence</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>bool</code></dt>
<dd>whether the proposition holds for the given target(s)</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def check_proposition(target, claim:str, additional_context=&#34;No additional context available.&#34;,
                      first_n:int=None, last_n:int=None, 
                      return_full_response:bool=False):
    &#34;&#34;&#34;
    Check whether a propositional claim holds for the given target(s). This is meant as a
    convenience method to avoid creating a Proposition object (which you might not need
    if you are not interested in the justification or confidence of the claim, or will
    not use it again).

    Args:
        target (TinyWorld, TinyPerson, list): the target or targets of the proposition
        claim (str): the claim of the proposition
        additional_context (str): additional context to provide to the LLM
        first_n (int): the number of first interactions to consider in the context
        last_n (int): the number of last interactions (most recent) to consider in the context
        return_full_response (bool): whether to return the full response from the LLM, including justification and confidence

    Returns:
        bool: whether the proposition holds for the given target(s)
    &#34;&#34;&#34;

    proposition = Proposition(claim, target, first_n=first_n, last_n=last_n)
    return proposition.check(additional_context=additional_context, return_full_response=return_full_response)</code></pre>
</details>
</dd>
<dt id="tinytroupe.experimentation.proposition.compute_score"><code class="name flex">
<span>def <span class="ident">compute_score</span></span>(<span>target, claim: str, additional_context='No additional context available.', first_n: int = None, last_n: int = None, return_full_response: bool = False)</span>
</code></dt>
<dd>
<div class="desc"><p>Compute a score about whether a claim holds for the given target(s). This is meant as a
convenience method to avoid creating a Score object (which you might not need
if you are not interested in the justification or confidence of the claim, or will
not use it again).</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>target</code></strong> :&ensp;<code>TinyWorld, TinyPerson, list</code></dt>
<dd>the target or targets of the proposition</dd>
<dt><strong><code>claim</code></strong> :&ensp;<code>str</code></dt>
<dd>the claim of the proposition</dd>
<dt><strong><code>additional_context</code></strong> :&ensp;<code>str</code></dt>
<dd>additional context to provide to the LLM</dd>
<dt><strong><code>first_n</code></strong> :&ensp;<code>int</code></dt>
<dd>the number of first interactions to consider in the context</dd>
<dt><strong><code>last_n</code></strong> :&ensp;<code>int</code></dt>
<dd>the number of last interactions (most recent) to consider in the context</dd>
<dt><strong><code>return_full_response</code></strong> :&ensp;<code>bool</code></dt>
<dd>whether to return the full response from the LLM, including justification and confidence</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>bool</code></dt>
<dd>whether the proposition holds for the given target(s)</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def compute_score(target, claim:str,
                      additional_context=&#34;No additional context available.&#34;,
                      first_n:int=None, last_n:int=None,
                      return_full_response:bool=False):
    &#34;&#34;&#34;
    Compute a score about whether a claim holds for the given target(s). This is meant as a
    convenience method to avoid creating a Score object (which you might not need
    if you are not interested in the justification or confidence of the claim, or will
    not use it again).

    Args:
        target (TinyWorld, TinyPerson, list): the target or targets of the proposition
        claim (str): the claim of the proposition
        additional_context (str): additional context to provide to the LLM
        first_n (int): the number of first interactions to consider in the context
        last_n (int): the number of last interactions (most recent) to consider in the context
        return_full_response (bool): whether to return the full response from the LLM, including justification and confidence

    Returns:
        bool: whether the proposition holds for the given target(s)
    &#34;&#34;&#34;

    score = Proposition(claim, target,
                  first_n=first_n, last_n=last_n)
    return score.compute(additional_context=additional_context, return_full_response=return_full_response)</code></pre>
</details>
</dd>
</dl>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="tinytroupe.experimentation.proposition.Proposition"><code class="flex name class">
<span>class <span class="ident">Proposition</span></span>
<span>(</span><span>claim: str, target=None, include_personas: bool = False, first_n: int = None, last_n: int = None, double_check: bool = False, use_reasoning_model: bool = False, precondition_function=None)</span>
</code></dt>
<dd>
<div class="desc"><p>Define a proposition as a (textual) claim about a target, which can be a TinyWorld, a TinyPerson or several of any.
The proposition's truth value can then either be checked as a boolean or computed as an integer score denoting the degree of truth.</p>
<p>Sometimes a proposition is better used in an implicative way, i.e., as a claim that is true or false depending on the context. For example, when
considering the latest agent action, the proposition might be applicable only to certain agent action types. To allow this,
this class allows to define a precondition function, which effectivelly turns a proposition <code>P</code> into <code>Precondition --&gt; P</code>. This is logically equivalent to
<code>not P or Precondition</code>. In other words:
- if the precondition is true, then the proposition is evaluated normally (as a boolean or a score).
- if the precondition is false, then the proposition is always true (or with highest score).
- if the precondition is None, then the proposition is evaluated normally (as a boolean or a score).</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>claim</code></strong> :&ensp;<code>str</code></dt>
<dd>the claim of the proposition</dd>
<dt><strong><code>target</code></strong> :&ensp;<code>TinyWorld, TinyPerson, list</code></dt>
<dd>the target or targets of the proposition. If not given, it will have to be specified later.</dd>
<dt><strong><code>include_personas</code></strong> :&ensp;<code>bool</code></dt>
<dd>whether to include the persona specifications of the agents in the context</dd>
<dt><strong><code>first_n</code></strong> :&ensp;<code>int</code></dt>
<dd>the number of first interactions to consider in the context</dd>
<dt><strong><code>last_n</code></strong> :&ensp;<code>int</code></dt>
<dd>the number of last interactions (most recent) to consider in the context</dd>
<dt><strong><code>double_check</code></strong> :&ensp;<code>bool</code></dt>
<dd>whether to ask the LLM to double check its answer. This tends to give more strict answers, but is slower and more expensive.</dd>
<dt><strong><code>use_reasoning_model</code></strong> :&ensp;<code>bool</code></dt>
<dd>whether to use a reasoning model to evaluate the proposition</dd>
<dt><strong><code>precondition_function</code></strong> :&ensp;<code>function</code></dt>
<dd>a Boolean function that indicates whether the proposition can be evaluated or not. This is useful to avoid evaluating propositions that are not relevant for the current context. If the precondition fails, the proposition is always interpreted as true (or with highest score). MUST have named arguments <code>target</code>, <code>additional_context</code>, and <code>claim_variables</code> (note: you can use a lambda for this too, e.g., <code>lambda target, additional_context, claim_variables: ...</code>).</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class Proposition:

    MIN_SCORE = 0
    MAX_SCORE = 9

    def __init__(self, claim:str, target=None, include_personas:bool=False, first_n:int=None, last_n:int=None,
                 double_check:bool=False, use_reasoning_model:bool=False, precondition_function=None):
        &#34;&#34;&#34; 
        Define a proposition as a (textual) claim about a target, which can be a TinyWorld, a TinyPerson or several of any.
        The proposition&#39;s truth value can then either be checked as a boolean or computed as an integer score denoting the degree of truth.

        Sometimes a proposition is better used in an implicative way, i.e., as a claim that is true or false depending on the context. For example, when
        considering the latest agent action, the proposition might be applicable only to certain agent action types. To allow this,
        this class allows to define a precondition function, which effectivelly turns a proposition `P` into `Precondition --&gt; P`. This is logically equivalent to
        `not P or Precondition`. In other words:
          - if the precondition is true, then the proposition is evaluated normally (as a boolean or a score).
          - if the precondition is false, then the proposition is always true (or with highest score).
          - if the precondition is None, then the proposition is evaluated normally (as a boolean or a score).
        

        Args:
            
            claim (str): the claim of the proposition
            target (TinyWorld, TinyPerson, list): the target or targets of the proposition. If not given, it will have to be specified later.
            include_personas (bool): whether to include the persona specifications of the agents in the context
            first_n (int): the number of first interactions to consider in the context
            last_n (int): the number of last interactions (most recent) to consider in the context
            double_check (bool): whether to ask the LLM to double check its answer. This tends to give more strict answers, but is slower and more expensive.
            use_reasoning_model (bool): whether to use a reasoning model to evaluate the proposition
            precondition_function (function): a Boolean function that indicates whether the proposition can be evaluated or not. This is useful to avoid evaluating propositions that are not relevant for the current context. If the precondition fails, the proposition is always interpreted as true (or with highest score). MUST have named arguments `target`, `additional_context`, and `claim_variables` (note: you can use a lambda for this too, e.g., `lambda target, additional_context, claim_variables: ...`).

        &#34;&#34;&#34;
        
        self.claim = claim
        self.targets = self._target_as_list(target)
        self.include_personas = include_personas
        
        self.first_n = first_n
        self.last_n = last_n

        self.double_check = double_check

        self.use_reasoning_model = use_reasoning_model

        self.precondition_function = precondition_function

        # the chat with the LLM is preserved until the proposition is re-evaluated. While it is available,
        # the chat can be used to follow up on the proposition, e.g., to ask for more details about the evaluation.
        self.llm_chat = None
        
        self.value = None
        self.justification = None
        self.confidence = None
        self.recommendations = None

    def __copy__(self):
        &#34;&#34;&#34;
        Create a shallow copy of the proposition without any evaluation state.
        
        Returns:
            Proposition: A new proposition with the same configuration parameters.
        &#34;&#34;&#34;
        new_prop = Proposition(
            claim=self.claim,
            target=self.targets,
            include_personas=self.include_personas,
            first_n=self.first_n,
            last_n=self.last_n,
            double_check=self.double_check,
            use_reasoning_model=self.use_reasoning_model,
            precondition_function=self.precondition_function
        )
        return new_prop

    def copy(self):
        &#34;&#34;&#34;
        Create a shallow copy of the proposition without any evaluation state.
        
        Returns:
            Proposition: A new proposition with the same configuration parameters.
        &#34;&#34;&#34;
        return self.__copy__()
    

    def __call__(self, target=None, additional_context=None, claim_variables:dict={}, return_full_response:bool=False) -&gt; bool:
        return self.check(target=target, additional_context=additional_context, claim_variables=claim_variables, return_full_response=return_full_response)
    

    def _check_precondition(self, target, additional_context:str, claim_variables:dict) -&gt; bool:
        &#34;&#34;&#34;
        Check whether the proposition can be evaluated or not.
        &#34;&#34;&#34;

        if self.precondition_function is None:
            return True
        else:
            return self.precondition_function(target=target, additional_context=additional_context, claim_variables=claim_variables)

    def check(self, target=None, additional_context=&#34;No additional context available.&#34;, claim_variables:dict={}, return_full_response:bool=False) -&gt; bool:
        &#34;&#34;&#34;
        Check whether the proposition holds for the given target(s).
        &#34;&#34;&#34;

        current_targets = self._determine_target(target)

        if self._check_precondition(target=current_targets, additional_context=additional_context, claim_variables=claim_variables) == False:
            self.value = True
            self.justification = &#34;The proposition is trivially true due to the precondition being false.&#34;
            self.confidence = 1.0
            self.full_evaluation_response = {&#34;value&#34;: True, &#34;justification&#34;: self.justification, &#34;confidence&#34;: self.confidence}
        
        else: # precondition is true or None

            context = self._build_context(current_targets)

            # might use a reasoning model, which could allow careful evaluation of the proposition.
            model = self._model(self.use_reasoning_model)

            #render self.claim using the claim_variables via chevron
            rendered_claim = render(self.claim, claim_variables)      

            self.llm_chat = LLMChat(system_prompt=&#34;&#34;&#34;
                                        You are a system that evaluates whether a proposition is true or false with respect to a given context. This context
                                        always refers to a multi-agent simulation. The proposition is a claim about the behavior of the agents or the state of their environment
                                        in the simulation.
                                    
                                        The context you receive can contain one or more of the following:
                                        - the trajectory of a simulation of one or more agents. This means what agents said, did, thought, or perceived at different times.
                                        - the state of the environment at a given time.
                                    
                                        Your output **must**:
                                        - necessarily start with the word &#34;True&#34; or &#34;False&#34;;
                                        - optionally be followed by a justification. Please provide a very detailed justifications, including very concrete and specific mentions to elements that contributed to reducing or increasing the score. Examples:
                                              * WRONG JUSTIFICATION (too abstract) example: &#34; ... the agent behavior did not comply with key parts of its specification, thus a reduced score ... &#34;
                                              * CORRECT JUSTIFICATION (very precise) example: &#34; ... the agent behavior deviated from key parts of its specification, specifically: S_1 was not met because &lt;reason&gt;, ..., S_n was not met becasue &lt;reason&gt;. Thus, a reduced score ...&#34;
                                        
                                        For example, the output could be of the form: &#34;True, because &lt;HIGHLY DETAILED, CONCRETE AND SPECIFIC REASONS HERE&gt;.&#34; or merely &#34;True&#34; if no justification is needed.
                                        &#34;&#34;&#34;, 

                                        user_prompt=f&#34;&#34;&#34;
                                        Evaluate the following proposition with respect to the context provided. Is it True or False?

                                        # Proposition

                                        This is the proposition you must evaluate:

                                            ```
                                            {indent_at_current_level(rendered_claim)}
                                            ```

                                        # Context

                                        The context you must consider is the following.

                                        {indent_at_current_level(context)}

                                        # Additional Context (if any)

                                        {indent_at_current_level(additional_context)}

                                        &#34;&#34;&#34;,

                                        output_type=bool,
                                        enable_reasoning_step=True,

                                        temperature=0.5,
                                        frequency_penalty=0.0, 
                                        presence_penalty=0.0,
                                        model=model)
            
            self.value = self.llm_chat()

            if self.double_check:
                self.llm_chat.add_user_message(&#34;Are you sure? Please revise your evaluation to make is correct as possible.&#34;)
                revised_value = self.llm_chat()
                if revised_value != self.value:
                    logger.warning(f&#34;The LLM revised its evaluation: from {self.value} to {revised_value}.&#34;)
                    self.value = revised_value

            self.reasoning = self.llm_chat.response_reasoning
            self.justification = self.llm_chat.response_justification      
            self.confidence = self.llm_chat.response_confidence

            self.full_evaluation_response = self.llm_chat.response_json

        # return the final result, either only the value or the full response
        if not return_full_response:
            return self.value
        else:
            return self.full_evaluation_response
        
    def score(self, target=None, additional_context=&#34;No additional context available.&#34;, claim_variables:dict={}, return_full_response:bool=False) -&gt; int:
        &#34;&#34;&#34;
        Compute the score for the proposition with respect to the given context.
        &#34;&#34;&#34;

        current_targets = self._determine_target(target)

        if self._check_precondition(target=current_targets, additional_context=additional_context, claim_variables=claim_variables) == False:
            self.value = self.MAX_SCORE
            self.justification = &#34;The proposition is trivially true due to the precondition being false.&#34;
            self.confidence = 1.0
            self.full_evaluation_response = {&#34;value&#34;: self.value, &#34;justification&#34;: self.justification, &#34;confidence&#34;: self.confidence}
        
        else: # precondition is true or None

            # build the context with the appropriate targets
        
            context = self._build_context(current_targets)

            # might use a reasoning model, which could allow careful evaluation of the proposition.
            model = self._model(self.use_reasoning_model)

            #render self.claim using the claim_variables via chevron
            rendered_claim = render(self.claim, claim_variables)      

            self.llm_chat = LLMChat(system_prompt=f&#34;&#34;&#34;
                                        You are a system that computes an integer score (between {Proposition.MIN_SCORE} and {Proposition.MAX_SCORE}, inclusive) about how much a proposition is true or false with respect to a given context. 
                                        This context always refers to a multi-agent simulation. The proposition is a claim about the behavior of the agents or the state of their environment in the simulation.

                                        The minimum score of {Proposition.MIN_SCORE} means that the proposition is completely false in all of the simulation trajectories, while the maximum score of {Proposition.MAX_SCORE} means that the proposition is completely true in all of the simulation trajectories. Intermediate scores are used to express varying degrees of partially met expectations. When assigning a score, follow these guidelines:
                                        - If the data required to judge the proposition is not present, assign a score of {Proposition.MAX_SCORE}. That is to say, unless there is evidence to the contrary, the proposition is assumed to be true.
                                        - The maximum score of {Proposition.MAX_SCORE} should be assigned when the evidence is as good as it can be. That is to say, all parts of the observed simulation trajectory support the proposition, no exceptions.
                                        - The minimum score of {Proposition.MIN_SCORE} should be assigned when the evidence is as bad as it can be. That is to say, all parts of the observed simulation trajectory contradict the proposition, no exceptions.
                                        - Intermediate scores should be assigned when the evidence is mixed. The intermediary score should be proportional to the balance of evidence, according to these bands:
                                                  0 = The proposition is without any doubt completely false;
                                            1, 2, 3 = The proposition has little support and is mostly false;
                                               4, 5 = The evidence is mixed, and the proposition is as much true as it is false;
                                            6, 7, 8 = The proposition is well-supported and is mostly true;
                                                  9 = The proposition is without any doubt completely true.
                                        - You should be very rigorous in your evaluation and, when in doubt, assign a lower score.
                                        - If there are critical flaws in the evidence, you should move your score to a lower band entirely.
                                        - If the provided context has inconsistent information, you **must** consider **only** the information that gives the lowest score, since we want to be rigorous and if necessary err to the lower end.
                                          * If you are considering the relationship between an agent specification and a simulation trajectory, you should consider the worst possible interpretation of: the agent specification; the simulation trajectory; or the relationship between the two.
                                          * These contradictions can appear anywhere in the context. When they do, you **always** adopt the worst possible inteprpretation, because we want to be rigorous and if necessary err to the lower end. It does not matter if the contradiction shows only very rarely, or if it is very small. It is still a contradiction and should be considered as such.
                                          * DO NOT dismiss contradictions as specification errors. They are part of the evidence and should be considered as such. They **must** be **always** taken into account when computing the score. **Never** ignore them.
                                        
                                        Additionally, whenever you are considering the relationship between an agent specification and a simulation trajectory, the following additional scoring guidelines apply:
                                          - All observed behavior **must** be easily mapped back to clear elements of the agent specification. If you cannot do this, you should assign a lower score.
                                          - Evaluate **each** relevant elements in the simulation trajectory (e.g., actions, stimuli) one by one, and assign a score to each of them. The final score is the average of all the scores assigned to each element.
                                                                            
                                        The proposition you receive can contain one or more of the following:
                                          - A statement of fact, which you will score.
                                          - Additional context, which you will use to evaluate the proposition. In particular, it might refer or specify potentail parts
                                            of similation trajectories for consideration. These might be formatted differently than what is given in the main context, so
                                            make sure you read them carefully.
                                          - Additional instructions on how to evaluate the proposition.

                                        The context you receive can contain one or more of the following:
                                          - the persona specifications of the agents in the simulation. That is to say, what the agents **are**, not what they are **doing**.
                                          - the simulation trajectories of one or more agents. This means what agents said, did, thought, or perceived at different times.
                                            These trajectories **are not** part of the persona specification.
                                          - the state of the environment at a given time.
                                          - additional context that can vary from simulation to simulation.
                                        
                                        To interpret the simulation trajectories, use the following guidelines:
                                          - Agents can receive stimuli and produce actions. You might be concerned with both or only one of them, depending on the specific proposition.
                                          - Actions are clearly marked with the text &#34;acts&#34;, e.g., &#34;Agent A acts: [ACTION]&#34;. If it is not thus marked, it is not an action.
                                          - Stimuli are denoted by &#34;--&gt; Agent name: [STIMULUS]&#34;.
                                    
                                        Your output **must**:
                                          - necessarily start with an integer between {Proposition.MIN_SCORE} and {Proposition.MAX_SCORE}, inclusive;
                                          - be followed by a justification. Please provide a very detailed justifications, including very concrete and specific mentions to elements that contributed to reducing or increasing the score. Examples:
                                              * WRONG JUSTIFICATION (too abstract) example: &#34; ... the agent behavior did not comply with key parts of its specification, thus a reduced score ... &#34;
                                              * CORRECT JUSTIFICATION (very precise) example: &#34; ... the agent behavior deviated from key parts of its specification, specifically: S_1 was not met because &lt;reason&gt;, ..., S_n was not met becasue &lt;reason&gt;. Thus, a reduced score ...&#34;
                                        
                                        For example, the output could be of the form: &#34;1, because &lt;HIGHLY DETAILED, CONCRETE AND SPECIFIC REASONS HERE&gt;.&#34;
                                        &#34;&#34;&#34;, 

                                        user_prompt=f&#34;&#34;&#34;
                                        Compute the score for the following proposition with respect to the context provided. Think step-by-step to assign the most accurate score and provide a justification.

                                        # Proposition

                                        This is the proposition you must evaluate:
                                        
                                            ```
                                            {indent_at_current_level(rendered_claim)}
                                            ```

                                        # Context

                                        The context you must consider is the following.

                                        {indent_at_current_level(context)}

                                        # Additional Context (if any)

                                        {indent_at_current_level(additional_context)}   
                                        &#34;&#34;&#34;,

                                        output_type=int,
                                        enable_reasoning_step=True,

                                        temperature=1.0,
                                        frequency_penalty=0.0, 
                                        presence_penalty=0.0,

                                        # Use a reasoning model, which allows careful evaluation of the proposition.
                                        model=model)
            

            self.value = self.llm_chat()

            if self.double_check:
                self.llm_chat.add_user_message(&#34;Are you sure? Please revise your evaluation to make is correct as possible.&#34;)
                revised_value = self.llm_chat()
                if revised_value != self.value:
                    logger.warning(f&#34;The LLM revised its evaluation: from {self.value} to {revised_value}.&#34;)
                    self.value = revised_value

            self.reasoning = self.llm_chat.response_reasoning
            self.justification = self.llm_chat.response_justification      
            self.confidence = self.llm_chat.response_confidence

            self.full_evaluation_response = self.llm_chat.response_json
        
        # return the final result, either only the value or the full response
        if not return_full_response:
            return self.value
        else:
            return self.full_evaluation_response
    
    def recommendations_for_improvement(self):
        &#34;&#34;&#34;
        Get recommendations for improving the proposition.
        &#34;&#34;&#34;

        # TODO this is not working, let&#39;s try something else
        #
        #if self.llm_chat is None:
        #    raise ValueError(&#34;No evaluation has been performed yet. Please evaluate the proposition before getting recommendations.&#34;)
#
        #self.llm_chat.add_system_message(\
        #    &#34;&#34;&#34;
        #    You will now act as a system that provides recommendations for the improvement of the scores previously assigned to propositions.
        #    You will now output text that contains analysises, recommendations and other information as requested by the user.
        #    &#34;&#34;&#34;)
#
        #self.llm_chat.add_user_message(\
        #    &#34;&#34;&#34;    
        #    To help improve the score next time, please list the following in as much detail as possible:
        #      - all recommendations for improvements based on the current score.
        #      - all criteria you are using to assign scores, and how to best satisfy them
#
        #    For both cases:
        #      - besides guidelines, make sure to provide plenty of concrete examples of what to be done in order to maximize each criterion.
        #      - avoid being generic or abstract. Instead, all of your criteria and recommendations should be given in very concrete terms that would work specifically for the case just considered.            
        #    
        #    Note that your output is a TEXT with the various recommendations, information and tips, not a JSON object.
#
        #    Recommendations:
        #    &#34;&#34;&#34;)
        #
        #recommendation = self.llm_chat(output_type=str, enable_json_output_format=False)
        recommendation = &#34;No additional recommendations at this time.&#34;
        return recommendation

    def _model(self, use_reasoning_model):
        if use_reasoning_model:
            return default[&#34;reasoning_model&#34;]
        else:
            return default[&#34;model&#34;]
    
    def _determine_target(self, target):
        &#34;&#34;&#34;
        Determine the target for the proposition. If a target was provided during initialization, it must not be provided now (i.e., the proposition is immutable).
        If no target was provided during initialization, it must be provided now.
        &#34;&#34;&#34;
       # If no target was provided during initialization, it must be provided now.
        if self.targets is None :
            if target is None:
                raise ValueError(&#34;No target specified. Please provide a target.&#34;)
            else:
                return self._target_as_list(target)

        # If it was provided during initialization, it must not be provided now (i.e., the proposition is immutable).
        else:
            if target is not None:
                raise ValueError(&#34;Target already specified. Please do not provide a target.&#34;)
            else:
                return self.targets
        
    def _build_context(self, current_targets):

        #
        # build the context with the appropriate targets
        #
        context = &#34;&#34;

        for target in current_targets:
            target_trajectory = target.pretty_current_interactions(max_content_length=None, first_n=self.first_n, last_n=self.last_n)

            if isinstance(target, TinyPerson):
                if self.include_personas:
                    context += f&#34;## Agent &#39;{target.name}&#39; Persona Specification\n\n&#34;
                    context += &#34;Before presenting the actual simulation trajectory, here is the persona specification of the agent that was used to produce the simulation.\n\n&#34;
                    context += &#34;This IS NOT the actual simulation, but only the static persona specification of the agent.\n\n&#34;
                    context += f&#34;persona={json.dumps(target._persona, indent=4)}\n\n&#34;
                
                context += f&#34;## Agent &#39;{target.name}&#39; Simulation Trajectory (if any)\n\n&#34;
            elif isinstance(target, TinyWorld):
                if self.include_personas:
                    context += f&#34;## Environment &#39;{target.name}&#39; Personas Specifications\n\n&#34;
                    context += &#34;Before presenting the actual simulation trajectory, here are the persona specifications of the agents used to produce the simulation.\n\n&#34;
                    context += &#34;This IS NOT the actual simulation, but only the static persona specification of the agent.\n\n&#34;
                    for agent in target.agents:
                        context += f&#34;### Agent &#39;{agent.name}&#39; Persona Specification\n\n&#34;
                        context += f&#34;persona={json.dumps(agent._persona, indent=4)}\n\n&#34;
                    
                context += f&#34;## Environment &#39;{target.name}&#39; Simulation Trajectory (if any)\n\n&#34;

            context += target_trajectory + &#34;\n\n&#34;

        return context

    def _target_as_list(self, target):
        if target is None:
            return None 
        elif isinstance(target, TinyWorld) or isinstance(target, TinyPerson):
            return [target]
        elif isinstance(target, list) and all(isinstance(t, TinyWorld) or isinstance(t, TinyPerson) for t in target):
            return target
        else:
            raise ValueError(&#34;Target must be a TinyWorld, a TinyPerson or a list of them.&#34;)</code></pre>
</details>
<h3>Class variables</h3>
<dl>
<dt id="tinytroupe.experimentation.proposition.Proposition.MAX_SCORE"><code class="name">var <span class="ident">MAX_SCORE</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="tinytroupe.experimentation.proposition.Proposition.MIN_SCORE"><code class="name">var <span class="ident">MIN_SCORE</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="tinytroupe.experimentation.proposition.Proposition.check"><code class="name flex">
<span>def <span class="ident">check</span></span>(<span>self, target=None, additional_context='No additional context available.', claim_variables: dict = {}, return_full_response: bool = False) ‑> bool</span>
</code></dt>
<dd>
<div class="desc"><p>Check whether the proposition holds for the given target(s).</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def check(self, target=None, additional_context=&#34;No additional context available.&#34;, claim_variables:dict={}, return_full_response:bool=False) -&gt; bool:
    &#34;&#34;&#34;
    Check whether the proposition holds for the given target(s).
    &#34;&#34;&#34;

    current_targets = self._determine_target(target)

    if self._check_precondition(target=current_targets, additional_context=additional_context, claim_variables=claim_variables) == False:
        self.value = True
        self.justification = &#34;The proposition is trivially true due to the precondition being false.&#34;
        self.confidence = 1.0
        self.full_evaluation_response = {&#34;value&#34;: True, &#34;justification&#34;: self.justification, &#34;confidence&#34;: self.confidence}
    
    else: # precondition is true or None

        context = self._build_context(current_targets)

        # might use a reasoning model, which could allow careful evaluation of the proposition.
        model = self._model(self.use_reasoning_model)

        #render self.claim using the claim_variables via chevron
        rendered_claim = render(self.claim, claim_variables)      

        self.llm_chat = LLMChat(system_prompt=&#34;&#34;&#34;
                                    You are a system that evaluates whether a proposition is true or false with respect to a given context. This context
                                    always refers to a multi-agent simulation. The proposition is a claim about the behavior of the agents or the state of their environment
                                    in the simulation.
                                
                                    The context you receive can contain one or more of the following:
                                    - the trajectory of a simulation of one or more agents. This means what agents said, did, thought, or perceived at different times.
                                    - the state of the environment at a given time.
                                
                                    Your output **must**:
                                    - necessarily start with the word &#34;True&#34; or &#34;False&#34;;
                                    - optionally be followed by a justification. Please provide a very detailed justifications, including very concrete and specific mentions to elements that contributed to reducing or increasing the score. Examples:
                                          * WRONG JUSTIFICATION (too abstract) example: &#34; ... the agent behavior did not comply with key parts of its specification, thus a reduced score ... &#34;
                                          * CORRECT JUSTIFICATION (very precise) example: &#34; ... the agent behavior deviated from key parts of its specification, specifically: S_1 was not met because &lt;reason&gt;, ..., S_n was not met becasue &lt;reason&gt;. Thus, a reduced score ...&#34;
                                    
                                    For example, the output could be of the form: &#34;True, because &lt;HIGHLY DETAILED, CONCRETE AND SPECIFIC REASONS HERE&gt;.&#34; or merely &#34;True&#34; if no justification is needed.
                                    &#34;&#34;&#34;, 

                                    user_prompt=f&#34;&#34;&#34;
                                    Evaluate the following proposition with respect to the context provided. Is it True or False?

                                    # Proposition

                                    This is the proposition you must evaluate:

                                        ```
                                        {indent_at_current_level(rendered_claim)}
                                        ```

                                    # Context

                                    The context you must consider is the following.

                                    {indent_at_current_level(context)}

                                    # Additional Context (if any)

                                    {indent_at_current_level(additional_context)}

                                    &#34;&#34;&#34;,

                                    output_type=bool,
                                    enable_reasoning_step=True,

                                    temperature=0.5,
                                    frequency_penalty=0.0, 
                                    presence_penalty=0.0,
                                    model=model)
        
        self.value = self.llm_chat()

        if self.double_check:
            self.llm_chat.add_user_message(&#34;Are you sure? Please revise your evaluation to make is correct as possible.&#34;)
            revised_value = self.llm_chat()
            if revised_value != self.value:
                logger.warning(f&#34;The LLM revised its evaluation: from {self.value} to {revised_value}.&#34;)
                self.value = revised_value

        self.reasoning = self.llm_chat.response_reasoning
        self.justification = self.llm_chat.response_justification      
        self.confidence = self.llm_chat.response_confidence

        self.full_evaluation_response = self.llm_chat.response_json

    # return the final result, either only the value or the full response
    if not return_full_response:
        return self.value
    else:
        return self.full_evaluation_response</code></pre>
</details>
</dd>
<dt id="tinytroupe.experimentation.proposition.Proposition.copy"><code class="name flex">
<span>def <span class="ident">copy</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"><p>Create a shallow copy of the proposition without any evaluation state.</p>
<h2 id="returns">Returns</h2>
<dl>
<dt><code><a title="tinytroupe.experimentation.proposition.Proposition" href="#tinytroupe.experimentation.proposition.Proposition">Proposition</a></code></dt>
<dd>A new proposition with the same configuration parameters.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def copy(self):
    &#34;&#34;&#34;
    Create a shallow copy of the proposition without any evaluation state.
    
    Returns:
        Proposition: A new proposition with the same configuration parameters.
    &#34;&#34;&#34;
    return self.__copy__()</code></pre>
</details>
</dd>
<dt id="tinytroupe.experimentation.proposition.Proposition.recommendations_for_improvement"><code class="name flex">
<span>def <span class="ident">recommendations_for_improvement</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"><p>Get recommendations for improving the proposition.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">    def recommendations_for_improvement(self):
        &#34;&#34;&#34;
        Get recommendations for improving the proposition.
        &#34;&#34;&#34;

        # TODO this is not working, let&#39;s try something else
        #
        #if self.llm_chat is None:
        #    raise ValueError(&#34;No evaluation has been performed yet. Please evaluate the proposition before getting recommendations.&#34;)
#
        #self.llm_chat.add_system_message(\
        #    &#34;&#34;&#34;
        #    You will now act as a system that provides recommendations for the improvement of the scores previously assigned to propositions.
        #    You will now output text that contains analysises, recommendations and other information as requested by the user.
        #    &#34;&#34;&#34;)
#
        #self.llm_chat.add_user_message(\
        #    &#34;&#34;&#34;    
        #    To help improve the score next time, please list the following in as much detail as possible:
        #      - all recommendations for improvements based on the current score.
        #      - all criteria you are using to assign scores, and how to best satisfy them
#
        #    For both cases:
        #      - besides guidelines, make sure to provide plenty of concrete examples of what to be done in order to maximize each criterion.
        #      - avoid being generic or abstract. Instead, all of your criteria and recommendations should be given in very concrete terms that would work specifically for the case just considered.            
        #    
        #    Note that your output is a TEXT with the various recommendations, information and tips, not a JSON object.
#
        #    Recommendations:
        #    &#34;&#34;&#34;)
        #
        #recommendation = self.llm_chat(output_type=str, enable_json_output_format=False)
        recommendation = &#34;No additional recommendations at this time.&#34;
        return recommendation</code></pre>
</details>
</dd>
<dt id="tinytroupe.experimentation.proposition.Proposition.score"><code class="name flex">
<span>def <span class="ident">score</span></span>(<span>self, target=None, additional_context='No additional context available.', claim_variables: dict = {}, return_full_response: bool = False) ‑> int</span>
</code></dt>
<dd>
<div class="desc"><p>Compute the score for the proposition with respect to the given context.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def score(self, target=None, additional_context=&#34;No additional context available.&#34;, claim_variables:dict={}, return_full_response:bool=False) -&gt; int:
    &#34;&#34;&#34;
    Compute the score for the proposition with respect to the given context.
    &#34;&#34;&#34;

    current_targets = self._determine_target(target)

    if self._check_precondition(target=current_targets, additional_context=additional_context, claim_variables=claim_variables) == False:
        self.value = self.MAX_SCORE
        self.justification = &#34;The proposition is trivially true due to the precondition being false.&#34;
        self.confidence = 1.0
        self.full_evaluation_response = {&#34;value&#34;: self.value, &#34;justification&#34;: self.justification, &#34;confidence&#34;: self.confidence}
    
    else: # precondition is true or None

        # build the context with the appropriate targets
    
        context = self._build_context(current_targets)

        # might use a reasoning model, which could allow careful evaluation of the proposition.
        model = self._model(self.use_reasoning_model)

        #render self.claim using the claim_variables via chevron
        rendered_claim = render(self.claim, claim_variables)      

        self.llm_chat = LLMChat(system_prompt=f&#34;&#34;&#34;
                                    You are a system that computes an integer score (between {Proposition.MIN_SCORE} and {Proposition.MAX_SCORE}, inclusive) about how much a proposition is true or false with respect to a given context. 
                                    This context always refers to a multi-agent simulation. The proposition is a claim about the behavior of the agents or the state of their environment in the simulation.

                                    The minimum score of {Proposition.MIN_SCORE} means that the proposition is completely false in all of the simulation trajectories, while the maximum score of {Proposition.MAX_SCORE} means that the proposition is completely true in all of the simulation trajectories. Intermediate scores are used to express varying degrees of partially met expectations. When assigning a score, follow these guidelines:
                                    - If the data required to judge the proposition is not present, assign a score of {Proposition.MAX_SCORE}. That is to say, unless there is evidence to the contrary, the proposition is assumed to be true.
                                    - The maximum score of {Proposition.MAX_SCORE} should be assigned when the evidence is as good as it can be. That is to say, all parts of the observed simulation trajectory support the proposition, no exceptions.
                                    - The minimum score of {Proposition.MIN_SCORE} should be assigned when the evidence is as bad as it can be. That is to say, all parts of the observed simulation trajectory contradict the proposition, no exceptions.
                                    - Intermediate scores should be assigned when the evidence is mixed. The intermediary score should be proportional to the balance of evidence, according to these bands:
                                              0 = The proposition is without any doubt completely false;
                                        1, 2, 3 = The proposition has little support and is mostly false;
                                           4, 5 = The evidence is mixed, and the proposition is as much true as it is false;
                                        6, 7, 8 = The proposition is well-supported and is mostly true;
                                              9 = The proposition is without any doubt completely true.
                                    - You should be very rigorous in your evaluation and, when in doubt, assign a lower score.
                                    - If there are critical flaws in the evidence, you should move your score to a lower band entirely.
                                    - If the provided context has inconsistent information, you **must** consider **only** the information that gives the lowest score, since we want to be rigorous and if necessary err to the lower end.
                                      * If you are considering the relationship between an agent specification and a simulation trajectory, you should consider the worst possible interpretation of: the agent specification; the simulation trajectory; or the relationship between the two.
                                      * These contradictions can appear anywhere in the context. When they do, you **always** adopt the worst possible inteprpretation, because we want to be rigorous and if necessary err to the lower end. It does not matter if the contradiction shows only very rarely, or if it is very small. It is still a contradiction and should be considered as such.
                                      * DO NOT dismiss contradictions as specification errors. They are part of the evidence and should be considered as such. They **must** be **always** taken into account when computing the score. **Never** ignore them.
                                    
                                    Additionally, whenever you are considering the relationship between an agent specification and a simulation trajectory, the following additional scoring guidelines apply:
                                      - All observed behavior **must** be easily mapped back to clear elements of the agent specification. If you cannot do this, you should assign a lower score.
                                      - Evaluate **each** relevant elements in the simulation trajectory (e.g., actions, stimuli) one by one, and assign a score to each of them. The final score is the average of all the scores assigned to each element.
                                                                        
                                    The proposition you receive can contain one or more of the following:
                                      - A statement of fact, which you will score.
                                      - Additional context, which you will use to evaluate the proposition. In particular, it might refer or specify potentail parts
                                        of similation trajectories for consideration. These might be formatted differently than what is given in the main context, so
                                        make sure you read them carefully.
                                      - Additional instructions on how to evaluate the proposition.

                                    The context you receive can contain one or more of the following:
                                      - the persona specifications of the agents in the simulation. That is to say, what the agents **are**, not what they are **doing**.
                                      - the simulation trajectories of one or more agents. This means what agents said, did, thought, or perceived at different times.
                                        These trajectories **are not** part of the persona specification.
                                      - the state of the environment at a given time.
                                      - additional context that can vary from simulation to simulation.
                                    
                                    To interpret the simulation trajectories, use the following guidelines:
                                      - Agents can receive stimuli and produce actions. You might be concerned with both or only one of them, depending on the specific proposition.
                                      - Actions are clearly marked with the text &#34;acts&#34;, e.g., &#34;Agent A acts: [ACTION]&#34;. If it is not thus marked, it is not an action.
                                      - Stimuli are denoted by &#34;--&gt; Agent name: [STIMULUS]&#34;.
                                
                                    Your output **must**:
                                      - necessarily start with an integer between {Proposition.MIN_SCORE} and {Proposition.MAX_SCORE}, inclusive;
                                      - be followed by a justification. Please provide a very detailed justifications, including very concrete and specific mentions to elements that contributed to reducing or increasing the score. Examples:
                                          * WRONG JUSTIFICATION (too abstract) example: &#34; ... the agent behavior did not comply with key parts of its specification, thus a reduced score ... &#34;
                                          * CORRECT JUSTIFICATION (very precise) example: &#34; ... the agent behavior deviated from key parts of its specification, specifically: S_1 was not met because &lt;reason&gt;, ..., S_n was not met becasue &lt;reason&gt;. Thus, a reduced score ...&#34;
                                    
                                    For example, the output could be of the form: &#34;1, because &lt;HIGHLY DETAILED, CONCRETE AND SPECIFIC REASONS HERE&gt;.&#34;
                                    &#34;&#34;&#34;, 

                                    user_prompt=f&#34;&#34;&#34;
                                    Compute the score for the following proposition with respect to the context provided. Think step-by-step to assign the most accurate score and provide a justification.

                                    # Proposition

                                    This is the proposition you must evaluate:
                                    
                                        ```
                                        {indent_at_current_level(rendered_claim)}
                                        ```

                                    # Context

                                    The context you must consider is the following.

                                    {indent_at_current_level(context)}

                                    # Additional Context (if any)

                                    {indent_at_current_level(additional_context)}   
                                    &#34;&#34;&#34;,

                                    output_type=int,
                                    enable_reasoning_step=True,

                                    temperature=1.0,
                                    frequency_penalty=0.0, 
                                    presence_penalty=0.0,

                                    # Use a reasoning model, which allows careful evaluation of the proposition.
                                    model=model)
        

        self.value = self.llm_chat()

        if self.double_check:
            self.llm_chat.add_user_message(&#34;Are you sure? Please revise your evaluation to make is correct as possible.&#34;)
            revised_value = self.llm_chat()
            if revised_value != self.value:
                logger.warning(f&#34;The LLM revised its evaluation: from {self.value} to {revised_value}.&#34;)
                self.value = revised_value

        self.reasoning = self.llm_chat.response_reasoning
        self.justification = self.llm_chat.response_justification      
        self.confidence = self.llm_chat.response_confidence

        self.full_evaluation_response = self.llm_chat.response_json
    
    # return the final result, either only the value or the full response
    if not return_full_response:
        return self.value
    else:
        return self.full_evaluation_response</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="tinytroupe.experimentation" href="index.html">tinytroupe.experimentation</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="tinytroupe.experimentation.proposition.check_proposition" href="#tinytroupe.experimentation.proposition.check_proposition">check_proposition</a></code></li>
<li><code><a title="tinytroupe.experimentation.proposition.compute_score" href="#tinytroupe.experimentation.proposition.compute_score">compute_score</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="tinytroupe.experimentation.proposition.Proposition" href="#tinytroupe.experimentation.proposition.Proposition">Proposition</a></code></h4>
<ul class="">
<li><code><a title="tinytroupe.experimentation.proposition.Proposition.MAX_SCORE" href="#tinytroupe.experimentation.proposition.Proposition.MAX_SCORE">MAX_SCORE</a></code></li>
<li><code><a title="tinytroupe.experimentation.proposition.Proposition.MIN_SCORE" href="#tinytroupe.experimentation.proposition.Proposition.MIN_SCORE">MIN_SCORE</a></code></li>
<li><code><a title="tinytroupe.experimentation.proposition.Proposition.check" href="#tinytroupe.experimentation.proposition.Proposition.check">check</a></code></li>
<li><code><a title="tinytroupe.experimentation.proposition.Proposition.copy" href="#tinytroupe.experimentation.proposition.Proposition.copy">copy</a></code></li>
<li><code><a title="tinytroupe.experimentation.proposition.Proposition.recommendations_for_improvement" href="#tinytroupe.experimentation.proposition.Proposition.recommendations_for_improvement">recommendations_for_improvement</a></code></li>
<li><code><a title="tinytroupe.experimentation.proposition.Proposition.score" href="#tinytroupe.experimentation.proposition.Proposition.score">score</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>