File size: 2,110 Bytes
c782fbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from pathlib import Path
from typing import Literal

from agents.hero.schema import HeroEpisodeStats
from agents.master.schema import DMObservation, WorldDefinition
from agents.shared.model_schema import StrictModel


class ClosedLoopEpisodeArtifacts(StrictModel):
    episode_dir: str
    world_generation_attempts_path: str
    world_definition_path: str
    run_record_path: str
    hero_trace_path: str
    transcript_path: str

    @classmethod
    def from_episode_dir(cls, episode_dir: Path) -> "ClosedLoopEpisodeArtifacts":
        return cls(
            episode_dir=str(episode_dir),
            world_generation_attempts_path=str(episode_dir / "world_generation_attempts.jsonl"),
            world_definition_path=str(episode_dir / "world_definition.json"),
            run_record_path=str(episode_dir / "run_record.json"),
            hero_trace_path=str(episode_dir / "hero_trace.jsonl"),
            transcript_path=str(episode_dir / "transcript.jsonl"),
        )


class ClosedLoopEpisodeRecord(StrictModel):
    episode_id: str
    status: Literal["complete", "failed", "compile_failed", "policy_error"]
    target_ratio: float
    compile_attempts: int
    dm_repair_errors: list[str]
    hero_policy_error: str | None = None
    hero_episode_stats: HeroEpisodeStats | None = None
    declared_difficulty_target: float | None = None
    difficulty_target_matches_target_ratio: bool | None = None
    world_definition: WorldDefinition | None = None
    observation: DMObservation
    artifacts: ClosedLoopEpisodeArtifacts


class ClosedLoopEpisodeSummary(StrictModel):
    episode_id: str
    status: str
    reward: float | None = None
    player_won: bool | None = None
    ratio: float | None = None
    compile_error: str | None = None
    hero_policy_error: str | None = None


class ClosedLoopAggregateReport(StrictModel):
    episodes: int
    compile_valid_rate: float
    policy_error_rate: float
    playable_rate: float
    solve_rate: float
    mean_dense_return: float
    mean_invalid_action_penalty: float
    mean_repeat_noop_penalty: float