Spaces:
Runtime error
Runtime error
File size: 4,060 Bytes
1ffd0a4 | 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 | """
Simulation schemas β output contract for Phase 12's simulation agent.
SimulationResult is the final output of the entire CIRO pipeline. It is
consumed by:
Phase 13 agent trace log
Mobile outcome visualization screen (before/after + actions)
Mobile Maps screen bottom sheet (dispatch_ticket)
"""
from __future__ import annotations
from datetime import datetime, timezone
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
CongestionLevel = Literal["severe", "heavy", "moderate", "light", "clear"]
AreaStatus = Literal["crisis active", "contained", "resolved"]
ActionStatus = Literal["completed", "in_progress", "pending"]
class SystemState(BaseModel):
"""Snapshot of the crisis area before or after response execution."""
model_config = ConfigDict(extra="forbid")
congestion_level: CongestionLevel
affected_area_status: AreaStatus
vehicles_rerouted: int = Field(ge=0)
emergency_units_deployed: int = Field(ge=0)
citizens_alerted: int = Field(ge=0)
ngos_activated: int = Field(ge=0)
class ExecutedAction(BaseModel):
"""A single response action from the plan, with its simulated outcome."""
model_config = ConfigDict(extra="forbid")
action: str
assigned_to: str
status: ActionStatus
simulated_effect: str
duration_minutes: int = Field(ge=0)
class DispatchedUnit(BaseModel):
"""One emergency service unit dispatched to the crisis."""
model_config = ConfigDict(extra="forbid")
service: str
units: int = Field(ge=1)
eta_minutes: int = Field(ge=1)
class DispatchTicket(BaseModel):
"""Structured emergency dispatch record shown on the Maps screen bottom sheet.
Generated deterministically for medium/high-risk crises that require
emergency services. None for low-risk crises (traffic jam, rainfall,
road_blockage).
"""
model_config = ConfigDict(extra="forbid")
ticket_id: str # e.g. "CIR-2025-0047"
status: str # "DISPATCHED"
crisis_id: str
crisis_type: str
location_label: str
severity: int = Field(ge=1, le=5)
units_dispatched: list[DispatchedUnit]
issued_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
class SimulationResult(BaseModel):
"""Full output of the simulation agent β final stage of the CIRO pipeline.
Attributes:
before: System state at crisis onset (deterministic).
after: System state after response execution (LLM).
actions_executed: Each plan action with its simulated effect (LLM).
dispatch_ticket: Emergency dispatch record; None for low-risk crises.
outcome_summary: Plain-English paragraph describing what happened.
time_to_resolution_estimate: e.g. "25β40 minutes".
"""
model_config = ConfigDict(extra="forbid")
before: SystemState
after: SystemState
actions_executed: list[ExecutedAction]
dispatch_ticket: DispatchTicket | None
outcome_summary: str
time_to_resolution_estimate: str
# ββ Agent output shape (subset of SimulationResult) βββββββββββββββββββββββββββ
#
# The simulation agent generates only the variable parts β `before` and
# `dispatch_ticket` are constructed deterministically and injected by
# `run_simulation()` before the final SimulationResult is assembled.
class SimulationAgentOutput(BaseModel):
"""Structured output contract for the simulation agent itself.
`before` and `dispatch_ticket` are excluded because they are built
deterministically from SituationReport severity and crisis type β the
agent should not invent ticket IDs or severity mappings.
"""
model_config = ConfigDict(extra="forbid")
after: SystemState
actions_executed: list[ExecutedAction]
outcome_summary: str
time_to_resolution_estimate: str
reasoning: str
confidence: float = Field(default=0.8, ge=0.0, le=1.0)
|