Spaces:
Configuration error
Configuration error
File size: 3,556 Bytes
ff32501 | 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 | """
models.py β Pydantic schemas for EmailTriage OpenEnv
"""
from pydantic import BaseModel, Field
from typing import List, Dict, Optional, Literal, Union
from enum import Enum
# βββββββββββββββββββββββββββ Enums ββββββββββββββββββββββββββββ
class Label(str, Enum):
spam = "spam"
low = "low"
med = "med"
high = "high"
escalate = "escalate"
class ActionType(str, Enum):
label = "label"
draft = "draft"
delete = "delete"
escalate = "escalate"
archive = "archive"
# βββββββββββββββββββββββββββ Core Data ββββββββββββββββββββββββ
class Email(BaseModel):
"""Visible email fields (priority/ground_truth hidden from agent)."""
id: str
subject: str
body: str
sender: str
model_config = {"frozen": True}
class EmailView(BaseModel):
"""What the agent actually sees per email."""
id: str
subject: str
body: str
sender: str
labeled: bool = False
label: Optional[str] = None
# βββββββββββββββββββββββββββ Action βββββββββββββββββββββββββββ
class Action(BaseModel):
"""
Agent action. One of:
- label(email_id, value: spam|low|med|high|escalate)
- draft(email_id, value: <reply text>)
- delete(email_id)
- escalate(email_id)
- archive(email_id)
"""
type: ActionType
email_id: str
value: Optional[str] = Field(default=None, description="Label value or draft reply text")
model_config = {"use_enum_values": True}
# βββββββββββββββββββββββββββ Observation ββββββββββββββββββββββ
class Stats(BaseModel):
total: int
unread: int
labeled: int
deleted: int
escalated: int
drafts: int
class ActionSummary(BaseModel):
step: int
action_type: str
email_id: str
reward: float
class Observation(BaseModel):
"""Full observation returned to agent after each step."""
current_emails: List[EmailView]
stats: Stats
history: List[ActionSummary] = []
done: bool = False
step: int = 0
# βββββββββββββββββββββββββββ State ββββββββββββββββββββββββββββ
class State(BaseModel):
"""Full internal environment state (not exposed to agent directly)."""
inbox: Dict[str, Email] = {}
labels: Dict[str, str] = {} # email_id -> label string
replies: Dict[str, str] = {} # email_id -> draft text
deleted: List[str] = []
archived: List[str] = []
task: str = "easy"
step_count: int = 0
# βββββββββββββββββββββββββββ Step Result ββββββββββββββββββββββ
class StepResult(BaseModel):
observation: Observation
reward: float
done: bool
info: Dict
# βββββββββββββββββββββββββββ Grader βββββββββββββββββββββββββββ
class GraderResult(BaseModel):
score: float = Field(ge=0.0, le=1.0)
breakdown: Dict[str, float]
details: Dict[str, str] = {}
|