Spaces:
Sleeping
Sleeping
File size: 1,795 Bytes
09e32d2 | 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 | """
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 # requests per last N steps
is_viral: bool
last_accessed: int # step number
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 # was incoming_file already cached?
recent_hit_rate: float # rolling hit rate last 20 steps
time_of_day: float # 0.0 to 1.0 (normalized)
queue_preview: List[str] # next 3 file_ids coming
class Action(BaseModel):
"""What the agent decides to do."""
evict_file_id: Optional[str] = None # None = do nothing / already cached
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
|