""" 目标模型 — Main Agent 管理的顶层目标 """ from sqlalchemy import Column, String, Text, Integer, Float, DateTime, JSON, ForeignKey, func from sqlalchemy.dialects.mysql import CHAR from sqlalchemy.orm import relationship from app.core.database import Base import uuid class Goal(Base): """目标表 — Main Agent 数字员工的顶层工作目标""" __tablename__ = "goals" id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="目标ID") title = Column(String(500), nullable=False, comment="目标标题") description = Column(Text, comment="目标描述(自然语言)") status = Column(String(20), default="active", comment="状态: active/paused/completed/failed/cancelled") priority = Column(Integer, default=5, comment="优先级 1-10") progress = Column(Float, default=0.0, comment="完成进度 0.0 - 1.0") # Main Agent 分解后的结构化计划 plan = Column(JSON, comment="执行计划: [{phase, tasks:[], assigned_agent_id, deadline}]") # 自主循环配置 autonomy_config = Column(JSON, comment="自主循环配置: {check_interval_minutes, max_idle_hours, auto_replan, notify_on_progress}") # 关联 creator_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, comment="创建者ID") main_agent_id = Column(CHAR(36), ForeignKey("agents.id"), nullable=True, comment="管理此目标的 Main Agent ID") parent_goal_id = Column(CHAR(36), ForeignKey("goals.id"), nullable=True, comment="父目标ID,支持目标嵌套") # 时间 started_at = Column(DateTime, comment="开始时间") completed_at = Column(DateTime, comment="完成时间") deadline = Column(DateTime, comment="截止时间") created_at = Column(DateTime, default=func.now(), comment="创建时间") updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间") # 关系 creator = relationship("User", backref="goals") main_agent = relationship("Agent", backref="managed_goals") def __repr__(self): return f""