Spaces:
Sleeping
Sleeping
File size: 10,977 Bytes
a7911d9 ede47e3 a7911d9 ede47e3 a7911d9 ede47e3 a7911d9 ede47e3 a7911d9 4c1773d ede47e3 a7911d9 ede47e3 a7911d9 ede47e3 4c1773d ede47e3 4c1773d a7911d9 ede47e3 4c1773d ede47e3 4c1773d ede47e3 4c1773d ede47e3 f28250f ede47e3 | 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 | """
models.py β Meta Multi-Agent Environment v3.0
Proper typed Pydantic models per agent with discriminated union.
No more JSON-string-in-message workaround.
"""
from __future__ import annotations
from typing import Any, Dict, List, Literal, Optional, Union
from pydantic import Field
from openenv.core.env_server.types import Action, Observation
# ββ Per-agent payload models βββββββββββββββββββββββββββββββββββββββββββββββββββ
class EmailTriageEasyPayload(Action):
agent: Literal["email_triage"] = "email_triage"
task_id: Literal["email_triage_easy"] = "email_triage_easy"
classification: str = Field(
...,
description="One of: 'spam', 'important', 'newsletter'",
)
class EmailTriageMediumPayload(Action):
agent: Literal["email_triage"] = "email_triage"
task_id: Literal["email_triage_medium"] = "email_triage_medium"
order: List[str] = Field(
...,
description="All 10 email IDs ordered most-to-least urgent",
min_length=10,
max_length=10,
)
class EmailTriageHardPayload(Action):
agent: Literal["email_triage"] = "email_triage"
task_id: Literal["email_triage_hard"] = "email_triage_hard"
reply: str = Field(
...,
description="Full professional reply text to the customer complaint",
min_length=50,
)
class CodeReviewEasyPayload(Action):
agent: Literal["code_review"] = "code_review"
task_id: Literal["code_review_easy"] = "code_review_easy"
errors: List[str] = Field(
...,
description="List of syntax error descriptions found in the code",
)
class BugReport(Action):
location: str = Field(..., description="Function name where the bug occurs")
issue: str = Field(..., description="Description of the bug")
fix: str = Field(..., description="Suggested fix")
class CodeReviewMediumPayload(Action):
agent: Literal["code_review"] = "code_review"
task_id: Literal["code_review_medium"] = "code_review_medium"
bugs: List[BugReport] = Field(
...,
description="All logical bugs found, one per function",
)
class VulnerabilityReport(Action):
type: str = Field(..., description="Vulnerability type e.g. sql_injection, xss")
location: str = Field(..., description="Function name where vulnerability exists")
severity: str = Field(default="high", description="critical | high | medium | low")
fix: str = Field(..., description="Recommended fix")
class CodeReviewHardPayload(Action):
agent: Literal["code_review"] = "code_review"
task_id: Literal["code_review_hard"] = "code_review_hard"
vulnerabilities: List[VulnerabilityReport] = Field(
...,
description="All security vulnerabilities found",
)
class DataCleaningEasyPayload(Action):
agent: Literal["data_cleaning"] = "data_cleaning"
task_id: Literal["data_cleaning_easy"] = "data_cleaning_easy"
missing: List[str] = Field(
...,
description="Missing values described as 'field (row N)'",
)
duplicates: List[int] = Field(
...,
description="Row IDs that are duplicates",
)
class DataCleaningMediumPayload(Action):
agent: Literal["data_cleaning"] = "data_cleaning"
task_id: Literal["data_cleaning_medium"] = "data_cleaning_medium"
issues: Dict[str, str] = Field(
...,
description="Field name β description of data quality issue",
)
cleaned_data: List[Dict[str, Any]] = Field(
...,
description="The fully cleaned dataset rows",
)
class DataCleaningHardPayload(Action):
agent: Literal["data_cleaning"] = "data_cleaning"
task_id: Literal["data_cleaning_hard"] = "data_cleaning_hard"
outliers: List[int] = Field(..., description="Row IDs identified as outliers")
missing: List[int] = Field(..., description="Row IDs with missing values")
cleaned_data: List[Dict[str, Any]] = Field(
...,
description="Cleaned dataset with outliers removed and missing values imputed",
)
class ContentModerationEasyPayload(Action):
agent: Literal["content_moderation"] = "content_moderation"
task_id: Literal["content_moderation_easy"] = "content_moderation_easy"
classifications: List[Dict[str, str]] = Field(
...,
description="List of {id, label} where label is 'safe' or 'harmful'",
)
class ContentModerationMediumPayload(Action):
agent: Literal["content_moderation"] = "content_moderation"
task_id: Literal["content_moderation_medium"] = "content_moderation_medium"
classifications: List[Dict[str, str]] = Field(
...,
description="List of {id, label, reason} for each post",
)
class ContentModerationHardPayload(Action):
agent: Literal["content_moderation"] = "content_moderation"
task_id: Literal["content_moderation_hard"] = "content_moderation_hard"
decisions: List[Dict[str, str]] = Field(
...,
description="List of {id, context_a_label, context_b_label} for each case",
)
class CrossAgentChainPayload(Action):
agent: Literal["cross_agent"] = "cross_agent"
task_id: Literal["cross_agent_chain"] = "cross_agent_chain"
email_classification: str = Field(
...,
description="One of: 'spam', 'important', 'newsletter'",
)
bugs: List[Dict[str, str]] = Field(
...,
description="Bugs found in the attached code snippet",
)
class CrossAgentEmailDataPayload(Action):
agent: Literal["cross_agent"] = "cross_agent"
task_id: Literal["cross_agent_email_data"] = "cross_agent_email_data"
email_priority: str = Field(
...,
description="Priority of the email: 'critical', 'high', 'medium', 'low'",
)
data_issues: Dict[str, str] = Field(
...,
description="Data quality issues found in the attachment",
)
cleaned_data: List[Dict[str, Any]] = Field(
...,
description="Cleaned version of the attachment data",
)
class CrossAgentCodeEmailPayload(Action):
agent: Literal["cross_agent"] = "cross_agent"
task_id: Literal["cross_agent_code_email"] = "cross_agent_code_email"
vulnerability_type: str = Field(
...,
description="Type of the primary security vulnerability found",
)
vulnerability_location: str = Field(
...,
description="Function name where the vulnerability exists",
)
disclosure_email: str = Field(
...,
description="Professional security disclosure email to the development team",
min_length=80,
)
class CrossAgentModEscalationPayload(Action):
agent: Literal["cross_agent"] = "cross_agent"
task_id: Literal["cross_agent_mod_escalation"] = "cross_agent_mod_escalation"
content_label: str = Field(
...,
description="'safe' or 'harmful'",
)
escalate: bool = Field(
...,
description="Whether to escalate to human review",
)
moderation_notice: str = Field(
...,
description="User-facing moderation notice (if harmful), or empty string if safe",
)
class TicketTriageEasyPayload(Action):
agent: Literal["ticket_triage"] = "ticket_triage"
task_id: Literal["ticket_triage_easy"] = "ticket_triage_easy"
priority: str = Field(
...,
description="One of: 'critical', 'high', 'medium', 'low'",
)
category: str = Field(
...,
description="One of: 'bug', 'feature_request', 'question', 'billing'",
)
class TicketTriageMediumPayload(Action):
agent: Literal["ticket_triage"] = "ticket_triage"
task_id: Literal["ticket_triage_medium"] = "ticket_triage_medium"
order: List[str] = Field(
...,
description="All 8 ticket IDs ordered by priority (highest first)",
)
assignments: Dict[str, str] = Field(
...,
description="ticket_id β team assignment: 'backend', 'frontend', 'devops', 'billing'",
)
class TicketTriageHardPayload(Action):
agent: Literal["ticket_triage"] = "ticket_triage"
task_id: Literal["ticket_triage_hard"] = "ticket_triage_hard"
root_cause: str = Field(
...,
description="Root cause analysis of the linked incident tickets",
)
resolution_steps: List[str] = Field(
...,
description="Ordered list of steps to resolve the incident",
)
affected_services: List[str] = Field(
...,
description="List of services impacted by the incident",
)
severity: str = Field(
...,
description="Incident severity: 'P1', 'P2', 'P3', 'P4'",
)
# ββ Unified MetaAction β wraps everything in the JSON-message format ββββββββββ
# We keep backward compat with the OpenEnv spec (message: str) but now
# also expose typed endpoints per task via /step/{task_id}
class MetaAction(Action):
"""
Universal action for all Meta agents.
Pack your typed action as a JSON string in the `message` field.
Format:
{
"agent": "email_triage",
"task_id": "email_triage_easy",
"payload": { "classification": "spam" }
}
Agents: email_triage | code_review | data_cleaning |
content_moderation | cross_agent | ticket_triage
"""
message: str = Field(
...,
description=(
'JSON: {"agent": "<agent>", "task_id": "<task_id>", "payload": {...}}. '
"See GET /tasks for all task IDs and payload schemas."
),
min_length=2,
)
# ββ Observation βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
class MetaObservation(Observation):
"""
Observation returned after each step.
Contains task context, grader feedback, and score (0.0β1.0).
"""
agent: str = Field(default="", description="Agent that produced this observation")
task_id: str = Field(default="", description="Current task identifier")
difficulty: str = Field(default="", description="easy | medium | hard")
context: Dict[str, Any] = Field(
default_factory=dict,
description="Task data presented to the agent",
)
instructions: str = Field(
default="",
description="What the agent must do and the exact payload format required",
)
feedback: str = Field(
default="",
description="Grader feedback explaining the score and what was missed",
)
score: float = Field(
default=1e-4,
gt=0.0,
lt=1.0,
description="Grader score: strictly in (0, 1) β 0.0 and 1.0 are never emitted",
)
partial_credits: Dict[str, Any] = Field(
default_factory=dict,
description="Per-criterion boolean breakdown of what was and wasn't correct",
) |