
""" AgentOS – TaskPlan ORM model. Stores the selected execu...
Prompt
""" AgentOS – TaskPlan ORM model. Stores the selected execution plan for a Task, including all candidate plans, their scores, and the S3 key of the human-readable plan document. """ from __future__ import annotations import uuid from datetime import datetime from typing import TYPE_CHECKING, Optional from sqlalchemy import DateTime, Float, ForeignKey, Integer, String, Text, func from sqlalchemy.dialects.postgresql import JSONB, UUID from sqlalchemy.orm import Mapped, mapped_column, relationship from core.database import Base if TYPE_CHECKING: from models.task import Task class TaskPlan(Base): __tablename__ = "task_plans" id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), primary_key=True, default=uuid.uuid4 ) task_id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), ForeignKey("tasks.id", ondelete="CASCADE"), nullable=False, unique=True, index=True, ) # ── Selected plan ───────────────────────────────────────────────────────── # JSON representation of the full DAG (list of subtask specs) plan_graph: Mapped[dict] = mapped_column(JSONB, nullable=False) # S3 key of the human-readable plan document (Markdown / JSON) plan_document_key: Mapped[Optional[str]] = mapped_column( String(1024), nullable=True ) # Score of the selected plan (0–1) plan_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) # ── Scoring breakdown (selected plan) ───────────────────────────────────── utility_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) reliability_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) cost_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) latency_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) risk_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) confidence_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True) # ── Alternative plans ───────────────────────────────────────────────────── # Full list of candidate plans with their scores alternative_plans: Mapped[Optional[list]] = mapped_column(JSONB, nullable=True) # ── Topology summary ────────────────────────────────────────────────────── total_subtasks: Mapped[int] = mapped_column(Integer, nullable=False, default=0) parallel_groups: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) critical_path_length: Mapped[Optional[int]] = mapped_column( Integer, nullable=True ) # ── Execution progress ──────────────────────────────────────────────────── completed_subtasks: Mapped[int] = mapped_column(Integer, nullable=False, default=0) failed_subtasks: Mapped[int] = mapped_column(Integer, nullable=False, default=0) skipped_subtasks: Mapped[int] = mapped_column(Integer, nullable=False, default=0) # ── Budget estimates ────────────────────────────────────────────────────── estimated_cost_usd: Mapped[Optional[float]] = mapped_column(Float, nullable=True) estimated_latency_seconds: Mapped[Optional[int]] = mapped_column( Integer, nullable=True ) # ── Timestamps ──────────────────────────────────────────────────────────── created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now() ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now(), onupdate=func.now(), ) # ── Relationship ────────────────────────────────────────────────────────── task: Mapped["Task"] = relationship( "Task", back_populates="plan", lazy="select" ) def __repr__(self) -> str: return ( f"<TaskPlan id={self.id} task_id={self.task_id} " f"subtasks={self.total_subtasks}>" ) Send back the complete code with all the fixes. Fix each of the listed errors one by one, making sure to actually correct them so that there are 0 errors remaining. Keep the original imports, since the files exist. Write out every single character; do not abbreviate anything. Fix every error. There must be exactly one file. Do not write anything else; just output the complete code, and it must not contain any comments. Never, under any circumstances, use simplified, substitute, dummy, simulated, or fake code. Write the entire file as complete, unabridged, production-ready code in a single code block. It must be 100% error-free, a complete, error-free file, and must be submitted as a downloadable file. These requirements are mandatory and must be strictly adhered to. If no list of errors is provided, you must find all the errors and fix them. If there were comments in the original code, delete them. And most importantly: YOU MUST NEVER SIMPLIFY!