| """ |
| Typed Pydantic models for the CDN Cache Optimizer environment. |
| Implements OpenEnv spec: Observation, Action, Reward. |
| """ |
|
|
| from pydantic import BaseModel, Field |
| from typing import List, Optional, Dict |
|
|
|
|
| class FileEntry(BaseModel): |
| """Represents a file currently in the cache.""" |
| file_id: str |
| size_mb: float |
| request_frequency: float |
| is_viral: bool |
| last_accessed: int |
|
|
|
|
| class Observation(BaseModel): |
| """What the agent sees at each step.""" |
| step: int |
| cache_used_mb: float |
| cache_capacity_mb: float |
| cache_fill_ratio: float |
| cached_files: List[FileEntry] |
| incoming_file_id: str |
| incoming_file_size_mb: float |
| incoming_file_is_viral: bool |
| cache_hit: bool |
| recent_hit_rate: float |
| time_of_day: float |
| queue_preview: List[str] |
|
|
|
|
| class Action(BaseModel): |
| """What the agent decides to do.""" |
| evict_file_id: Optional[str] = None |
|
|
|
|
| class Reward(BaseModel): |
| """Reward breakdown for transparency.""" |
| total: float |
| cache_hit_bonus: float |
| eviction_penalty: float |
| thrash_penalty: float |
| bandwidth_saved: float |
| wasted_capacity_penalty: float |
|
|
|
|
| class StepResult(BaseModel): |
| """Full result returned by step().""" |
| observation: Observation |
| reward: Reward |
| done: bool |
| info: Dict |
|
|
|
|
| class TaskConfig(BaseModel): |
| """Configuration for a specific task.""" |
| task_id: str |
| name: str |
| difficulty: str |
| cache_capacity_mb: float |
| num_files: int |
| viral_ratio: float |
| episode_length: int |
| description: str |
|
|