agi4-core 0.1.0

Pure verdict logic for AGI/4 attestation
Documentation
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
//! Per-conjunct evaluation functions.
//!
//! Each function takes evidence for a conjunct and returns a ConjunctStatus
//! based on the thresholds defined in SPEC.md ยง3.

use crate::conjunct::ConjunctStatus;
use crate::evidence::{Evidence, SourceValue};
use crate::threshold;

/// Evaluate the Generality conjunct.
///
/// Requires: at least 3 of 4 sources (ARC-AGI-2, ARC-AGI-3, HLE, GPQA-Diamond)
/// with ARC-AGI-3 mandatory.
///
/// Pass: all four sources meet thresholds
/// Partial: at least one meets, at least one doesn't
/// Fail: no source meets OR ARC-AGI-3 < 5%
/// InsufficientData: minimum evidence requirement unmet
pub fn evaluate_generality(evidence: &[Evidence]) -> ConjunctStatus {
    let mut arc_agi_2 = None;
    let mut arc_agi_3 = None;
    let mut hle = None;
    let mut gpqa_diamond = None;

    for e in evidence {
        match e.source.as_str() {
            "arc-agi-2" => {
                if let SourceValue::Fraction(f) = e.value {
                    arc_agi_2 = Some(f);
                }
            }
            "arc-agi-3" => {
                if let SourceValue::Fraction(f) = e.value {
                    arc_agi_3 = Some(f);
                }
            }
            "hle" => {
                if let SourceValue::Fraction(f) = e.value {
                    hle = Some(f);
                }
            }
            "gpqa-diamond" => {
                if let SourceValue::Fraction(f) = e.value {
                    gpqa_diamond = Some(f);
                }
            }
            _ => {}
        }
    }

    // ARC-AGI-3 is mandatory
    let arc_agi_3 = match arc_agi_3 {
        Some(f) => f,
        None => return ConjunctStatus::InsufficientData,
    };

    // Check ARC-AGI-3 floor
    if arc_agi_3.value() < threshold::generality::ARC_AGI_3_FLOOR {
        return ConjunctStatus::Fail;
    }

    // Count how many sources are available
    let available_sources = [arc_agi_2.is_some(), hle.is_some(), gpqa_diamond.is_some()]
        .iter()
        .filter(|&&x| x)
        .count()
        + 1; // +1 for ARC-AGI-3

    // Minimum evidence: at least 3 of 4 sources
    if available_sources < 3 {
        return ConjunctStatus::InsufficientData;
    }

    // Check thresholds
    let arc_agi_2_pass = arc_agi_2
        .map(|f| f.value() >= threshold::generality::ARC_AGI_2_PASS)
        .unwrap_or(false);
    let arc_agi_3_pass = arc_agi_3.value() >= threshold::generality::ARC_AGI_3_PASS;
    let hle_pass = hle
        .map(|f| f.value() >= threshold::generality::HLE_PASS)
        .unwrap_or(false);
    let gpqa_pass = gpqa_diamond
        .map(|f| f.value() >= threshold::generality::GPQA_DIAMOND_PASS)
        .unwrap_or(false);

    let sources = [
        (arc_agi_2_pass, arc_agi_2.is_some()),
        (arc_agi_3_pass, true),
        (hle_pass, hle.is_some()),
        (gpqa_pass, gpqa_diamond.is_some()),
    ];

    let passing = sources
        .iter()
        .filter(|(pass, present)| *present && *pass)
        .count();
    let present = sources.iter().filter(|(_, present)| *present).count();

    if passing == present && present >= 3 {
        ConjunctStatus::Pass
    } else if passing > 0 && passing < present {
        ConjunctStatus::Partial
    } else {
        ConjunctStatus::Fail
    }
}

/// Evaluate the Economic Substitutability conjunct.
///
/// Requires: both GDPval and RLI (APEX-Agents is supplementary)
///
/// Pass: GDPval โ‰ฅ85% AND RLI โ‰ฅ60%
/// Partial: one meets, one doesn't
/// Fail: neither meets threshold
/// InsufficientData: missing required sources
pub fn evaluate_economic_substitutability(evidence: &[Evidence]) -> ConjunctStatus {
    let mut gdpval = None;
    let mut rli = None;

    for e in evidence {
        match e.source.as_str() {
            "gdpval" => {
                if let SourceValue::Fraction(f) = e.value {
                    gdpval = Some(f);
                }
            }
            "rli" => {
                if let SourceValue::Fraction(f) = e.value {
                    rli = Some(f);
                }
            }
            "apex-agents" => {
                // APEX-Agents is supplementary, not used in logic yet
            }
            _ => {}
        }
    }

    // Both GDPval and RLI are required
    let gdpval = match gdpval {
        Some(f) => f,
        None => return ConjunctStatus::InsufficientData,
    };
    let rli = match rli {
        Some(f) => f,
        None => return ConjunctStatus::InsufficientData,
    };

    // Check for floor on RLI
    if rli.value() < threshold::economic_substitutability::RLI_FLOOR {
        return ConjunctStatus::Fail;
    }

    let gdpval_pass = gdpval.value() >= threshold::economic_substitutability::GDPVAL_PASS;
    let rli_pass = rli.value() >= threshold::economic_substitutability::RLI_PASS;

    if gdpval_pass && rli_pass {
        ConjunctStatus::Pass
    } else if gdpval_pass || rli_pass {
        ConjunctStatus::Partial
    } else {
        ConjunctStatus::Fail
    }
}

/// Evaluate the Environmental Transfer conjunct.
///
/// Requires: ARC-AGI-3 (mandatory) + at least one of OSWorld or NES
///
/// Pass: ARC-AGI-3 โ‰ฅ50% AND (OSWorld โ‰ฅ85% OR NES โ‰ฅthreshold)
/// Partial: ARC-AGI-3 above floor but below threshold OR ARC-AGI-3 passes but no secondary source
/// Fail: ARC-AGI-3 < 5%
/// InsufficientData: ARC-AGI-3 missing or no secondary source
pub fn evaluate_environmental_transfer(evidence: &[Evidence]) -> ConjunctStatus {
    let mut arc_agi_3 = None;
    let mut osworld = None;
    let mut nes = None;

    for e in evidence {
        match e.source.as_str() {
            "arc-agi-3" => {
                if let SourceValue::Fraction(f) = e.value {
                    arc_agi_3 = Some(f);
                }
            }
            "osworld" => {
                if let SourceValue::Fraction(f) = e.value {
                    osworld = Some(f);
                }
            }
            "nes" => {
                if let SourceValue::Fraction(f) = e.value {
                    nes = Some(f);
                }
            }
            _ => {}
        }
    }

    // ARC-AGI-3 is required
    let arc_agi_3 = match arc_agi_3 {
        Some(f) => f,
        None => return ConjunctStatus::InsufficientData,
    };

    // Check ARC-AGI-3 floor
    if arc_agi_3.value() < threshold::environmental_transfer::ARC_AGI_3_FLOOR {
        return ConjunctStatus::Fail;
    }

    // Need at least one secondary source
    if osworld.is_none() && nes.is_none() {
        return ConjunctStatus::InsufficientData;
    }

    let arc_agi_3_pass = arc_agi_3.value() >= threshold::environmental_transfer::ARC_AGI_3_PASS;
    let osworld_pass = osworld
        .map(|f| f.value() >= threshold::environmental_transfer::OSWORLD_PASS)
        .unwrap_or(false);

    if arc_agi_3_pass && (osworld_pass || nes.is_some()) {
        // NES is TBD, so we treat it as passing if present
        ConjunctStatus::Pass
    } else if arc_agi_3_pass
        || osworld_pass
        || arc_agi_3.value() >= threshold::environmental_transfer::ARC_AGI_3_FLOOR
    {
        ConjunctStatus::Partial
    } else {
        ConjunctStatus::Fail
    }
}

/// Evaluate the Autonomous Agency conjunct.
///
/// Requires: METR 80%-time horizon (mandatory) + at least one of RE-Bench or SWE-bench Verified
///
/// Pass: METR โ‰ฅ168h AND (RE-Bench โ‰ฅ60% OR SWE-bench โ‰ฅ85%)
/// Partial: METR โ‰ฅ168h but no supporting source OR supporting source passes but METR < 168h >= 8h
/// Fail: METR < 8h
/// InsufficientData: METR missing or no supporting source
pub fn evaluate_autonomous_agency(evidence: &[Evidence]) -> ConjunctStatus {
    let mut metr = None;
    let mut rebench = None;
    let mut swebench = None;

    for e in evidence {
        match e.source.as_str() {
            "metr-80pct-time-horizon" => {
                if let SourceValue::Hours(h) = e.value {
                    metr = Some(h);
                }
            }
            "rebench" => {
                if let SourceValue::Fraction(f) = e.value {
                    rebench = Some(f);
                }
            }
            "swebench-verified-pass-at-5" => {
                if let SourceValue::Fraction(f) = e.value {
                    swebench = Some(f);
                }
            }
            _ => {}
        }
    }

    // METR is required
    let metr = match metr {
        Some(h) => h,
        None => return ConjunctStatus::InsufficientData,
    };

    // Check METR floor
    if metr.value() < threshold::autonomous_agency::METR_80PCT_FLOOR_HOURS {
        return ConjunctStatus::Fail;
    }

    // Need at least one supporting source
    if rebench.is_none() && swebench.is_none() {
        return ConjunctStatus::InsufficientData;
    }

    let metr_pass = metr.value() >= threshold::autonomous_agency::METR_80PCT_PASS_HOURS;
    let rebench_pass = rebench
        .map(|f| f.value() >= threshold::autonomous_agency::REBENCH_PASS)
        .unwrap_or(false);
    let swebench_pass = swebench
        .map(|f| f.value() >= threshold::autonomous_agency::SWEBENCH_VERIFIED_PASS_AT_5)
        .unwrap_or(false);

    if metr_pass && (rebench_pass || swebench_pass) {
        ConjunctStatus::Pass
    } else if metr_pass || rebench_pass || swebench_pass {
        ConjunctStatus::Partial
    } else {
        ConjunctStatus::Fail
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::evidence::{BoundedFraction, MeasurementId, NonNegativeHours, Provenance, SourceId};
    use chrono::Utc;
    use url::Url;

    fn make_evidence(source: &str, measurement: &str, value: SourceValue) -> Evidence {
        Evidence {
            source: SourceId::new(source),
            measurement: MeasurementId::new(measurement),
            value,
            reliability_percentile: 95,
            provenance: Provenance {
                source_url: Url::parse("https://example.com").unwrap(),
                fetch_timestamp: Utc::now(),
                source_version: Some("1.0".to_string()),
                raw_value: "test".to_string(),
            },
        }
    }

    #[test]
    fn generality_pass_all_sources() {
        let evidence = vec![
            make_evidence(
                "arc-agi-2",
                "pass-rate",
                SourceValue::Fraction(BoundedFraction::new(0.85).unwrap()),
            ),
            make_evidence(
                "arc-agi-3",
                "pass-rate",
                SourceValue::Fraction(BoundedFraction::new(0.50).unwrap()),
            ),
            make_evidence(
                "hle",
                "accuracy",
                SourceValue::Fraction(BoundedFraction::new(0.80).unwrap()),
            ),
            make_evidence(
                "gpqa-diamond",
                "accuracy",
                SourceValue::Fraction(BoundedFraction::new(0.90).unwrap()),
            ),
        ];

        assert_eq!(evaluate_generality(&evidence), ConjunctStatus::Pass);
    }

    #[test]
    fn generality_insufficient_data() {
        let evidence = vec![make_evidence(
            "arc-agi-3",
            "pass-rate",
            SourceValue::Fraction(BoundedFraction::new(0.50).unwrap()),
        )];

        assert_eq!(
            evaluate_generality(&evidence),
            ConjunctStatus::InsufficientData
        );
    }

    #[test]
    fn generality_fail_below_floor() {
        let evidence = vec![
            make_evidence(
                "arc-agi-3",
                "pass-rate",
                SourceValue::Fraction(BoundedFraction::new(0.03).unwrap()),
            ),
            make_evidence(
                "hle",
                "accuracy",
                SourceValue::Fraction(BoundedFraction::new(0.80).unwrap()),
            ),
            make_evidence(
                "gpqa-diamond",
                "accuracy",
                SourceValue::Fraction(BoundedFraction::new(0.90).unwrap()),
            ),
        ];

        assert_eq!(evaluate_generality(&evidence), ConjunctStatus::Fail);
    }

    #[test]
    fn economic_substitutability_pass() {
        let evidence = vec![
            make_evidence(
                "gdpval",
                "win-rate",
                SourceValue::Fraction(BoundedFraction::new(0.85).unwrap()),
            ),
            make_evidence(
                "rli",
                "completion-rate",
                SourceValue::Fraction(BoundedFraction::new(0.60).unwrap()),
            ),
        ];

        assert_eq!(
            evaluate_economic_substitutability(&evidence),
            ConjunctStatus::Pass
        );
    }

    #[test]
    fn economic_substitutability_insufficient_data() {
        let evidence = vec![make_evidence(
            "gdpval",
            "win-rate",
            SourceValue::Fraction(BoundedFraction::new(0.85).unwrap()),
        )];

        assert_eq!(
            evaluate_economic_substitutability(&evidence),
            ConjunctStatus::InsufficientData
        );
    }

    #[test]
    fn environmental_transfer_pass() {
        let evidence = vec![
            make_evidence(
                "arc-agi-3",
                "pass-rate",
                SourceValue::Fraction(BoundedFraction::new(0.50).unwrap()),
            ),
            make_evidence(
                "osworld",
                "completion-rate",
                SourceValue::Fraction(BoundedFraction::new(0.85).unwrap()),
            ),
        ];

        assert_eq!(
            evaluate_environmental_transfer(&evidence),
            ConjunctStatus::Pass
        );
    }

    #[test]
    fn environmental_transfer_insufficient_without_secondary() {
        let evidence = vec![make_evidence(
            "arc-agi-3",
            "pass-rate",
            SourceValue::Fraction(BoundedFraction::new(0.50).unwrap()),
        )];

        assert_eq!(
            evaluate_environmental_transfer(&evidence),
            ConjunctStatus::InsufficientData
        );
    }

    #[test]
    fn autonomous_agency_pass() {
        let evidence = vec![
            make_evidence(
                "metr-80pct-time-horizon",
                "hours",
                SourceValue::Hours(NonNegativeHours::new(168.0).unwrap()),
            ),
            make_evidence(
                "rebench",
                "success-rate",
                SourceValue::Fraction(BoundedFraction::new(0.60).unwrap()),
            ),
        ];

        assert_eq!(evaluate_autonomous_agency(&evidence), ConjunctStatus::Pass);
    }

    #[test]
    fn autonomous_agency_insufficient_without_supporting() {
        let evidence = vec![make_evidence(
            "metr-80pct-time-horizon",
            "hours",
            SourceValue::Hours(NonNegativeHours::new(168.0).unwrap()),
        )];

        assert_eq!(
            evaluate_autonomous_agency(&evidence),
            ConjunctStatus::InsufficientData
        );
    }

    #[test]
    fn autonomous_agency_fail_below_floor() {
        let evidence = vec![
            make_evidence(
                "metr-80pct-time-horizon",
                "hours",
                SourceValue::Hours(NonNegativeHours::new(4.0).unwrap()),
            ),
            make_evidence(
                "rebench",
                "success-rate",
                SourceValue::Fraction(BoundedFraction::new(0.60).unwrap()),
            ),
        ];

        assert_eq!(evaluate_autonomous_agency(&evidence), ConjunctStatus::Fail);
    }
}