60 lines
3.1 KiB
Python
60 lines
3.1 KiB
Python
"""IR Pydantic models for EdgeMind: LocalProblem, SharedSignals, PlanDelta, SafetyContract, AuditLog, AdapterContract
|
|
|
|
This module provides compact, well-documented Pydantic models that serve both
|
|
as runtime types and as a single-source-of-truth for JSON Schema generation.
|
|
"""
|
|
from typing import Dict, List, Optional, Any
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class LocalProblem(BaseModel):
|
|
id: str = Field(..., description="Unique task id")
|
|
goal_type: str = Field(..., description="Type of goal, e.g., reach, survey, charge")
|
|
state_vars: Dict[str, Any] = Field(default_factory=dict, description="Observed or tracked state variables")
|
|
hard_constraints: List[str] = Field(default_factory=list, description="List of boolean predicates (string form) that must hold")
|
|
soft_costs: Dict[str, float] = Field(default_factory=dict, description="Named soft-cost terms to optimize")
|
|
energy_budget: Optional[float] = Field(None, description="Available energy budget (Joules)")
|
|
time_window: Optional[Dict[str, Any]] = Field(None, description="Optional time window, e.g. {\"start\":..., \"end\":...}")
|
|
actuator_interface: Optional[str] = Field(None, description="Target actuator adapter id")
|
|
|
|
|
|
class SharedSignals(BaseModel):
|
|
signals: Dict[str, Any] = Field(default_factory=dict, description="Versioned, privacy-bounded signals shared between agents")
|
|
version: Optional[str] = Field(None, description="Schema or contract version")
|
|
|
|
|
|
class PlanDelta(BaseModel):
|
|
plan_id: str = Field(..., description="Plan this delta applies to")
|
|
timestamp: float = Field(..., description="Unix epoch timestamp")
|
|
patch: Dict[str, Any] = Field(..., description="Minimal patch representation (CRDT-ish) describing changes")
|
|
safety_tags: List[str] = Field(default_factory=list, description="Tags indicating safety relevance or categories")
|
|
vector_clock: Optional[Dict[str, int]] = Field(None, description="Optional version vector for merges")
|
|
|
|
|
|
class SafetyContract(BaseModel):
|
|
contract_id: str = Field(..., description="Unique contract id")
|
|
invariants: List[str] = Field(default_factory=list, description="Boolean predicates that must hold pre/post plan")
|
|
fail_actions: List[str] = Field(default_factory=lambda: ["halt"], description="Actions to take when contract violated")
|
|
|
|
|
|
class AuditLog(BaseModel):
|
|
entries: List[Dict[str, Any]] = Field(default_factory=list, description="List of audit records")
|
|
privacy_budget: Optional[float] = Field(None, description="Optional privacy budget remaining for this log")
|
|
|
|
|
|
class AdapterContract(BaseModel):
|
|
adapter_id: str = Field(..., description="Adapter identifier")
|
|
supported_domains: List[str] = Field(default_factory=list, description="Domains this adapter can handle, e.g., nav, sensor")
|
|
contract_version: Optional[str] = Field(None, description="Semantic version of the adapter contract")
|
|
metadata: Dict[str, Any] = Field(default_factory=dict, description="Per-message metadata schema hints")
|
|
|
|
|
|
__all__ = [
|
|
"LocalProblem",
|
|
"SharedSignals",
|
|
"PlanDelta",
|
|
"SafetyContract",
|
|
"AuditLog",
|
|
"AdapterContract",
|
|
]
|