Main Agent 数字员工工厂基础设施: - 新增 Goal 和 Task SQLAlchemy 数据模型 - Agent 模型新增 agent_type / input_schema / output_schema - Execution 模型新增 goal_id 关联 - 新增 Goal/Task CRUD 服务层(含依赖检查、任务树、进度计算) - 新增 /api/v1/goals (9端点) + /api/v1/tasks (8端点) - 数据库迁移 013_add_goals_tasks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
"""
|
||
执行记录模型
|
||
"""
|
||
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, ForeignKey, func
|
||
from sqlalchemy.dialects.mysql import CHAR
|
||
from sqlalchemy.orm import relationship
|
||
from app.core.database import Base
|
||
import uuid
|
||
|
||
|
||
class Execution(Base):
|
||
"""执行记录表"""
|
||
__tablename__ = "executions"
|
||
|
||
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="执行ID")
|
||
agent_id = Column(CHAR(36), ForeignKey("agents.id"), nullable=True, comment="智能体ID")
|
||
workflow_id = Column(CHAR(36), ForeignKey("workflows.id"), nullable=True, comment="工作流ID")
|
||
input_data = Column(JSON, comment="输入数据")
|
||
output_data = Column(JSON, comment="输出数据")
|
||
status = Column(
|
||
String(32),
|
||
nullable=False,
|
||
comment="状态: pending/running/completed/failed/awaiting_approval",
|
||
)
|
||
error_message = Column(Text, comment="错误信息")
|
||
execution_time = Column(Integer, comment="执行时间(ms)")
|
||
task_id = Column(String(100), comment="Celery任务ID")
|
||
schedule_id = Column(
|
||
CHAR(36), ForeignKey("agent_schedules.id"), nullable=True, comment="定时任务ID"
|
||
)
|
||
parent_execution_id = Column(
|
||
CHAR(36), ForeignKey("executions.id"), nullable=True, comment="父执行ID"
|
||
)
|
||
depth = Column(Integer, default=0, nullable=False, comment="执行深度(根为0)")
|
||
pause_state = Column(JSON, nullable=True, comment="挂起快照(审批节点 HITL,恢复时消费)")
|
||
goal_id = Column(CHAR(36), ForeignKey("goals.id"), nullable=True, comment="关联目标ID")
|
||
created_at = Column(DateTime, default=func.now(), comment="创建时间")
|
||
|
||
# 关系
|
||
agent = relationship("Agent", backref="executions")
|
||
workflow = relationship("Workflow", backref="executions")
|
||
|
||
def __repr__(self):
|
||
return f"<Execution(id={self.id}, status={self.status})>"
|