Files
aiagent/backend/app/models/task.py
renjianbo beff3fac8d fix: delete agent 500 error + dynamic personality + deployment guide
- Fix delete agent 500: clean up FK records (agent_llm_logs, permissions,
  schedules, executions, team_members) and unbind goals/tasks before delete
- Remove hardcoded personality templates in Android, replace with dynamic
  system prompt generation from name + description
- Set promptSectionsEnabled=false to bypass PromptComposer for personality
- Add Tencent Cloud Linux deployment guide (Docker Compose)
- Accumulated backend service updates, frontend UI fixes, Android app changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-29 01:17:21 +08:00

65 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
任务模型 — Goal 拆解的子任务
"""
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, Boolean, ForeignKey, Index, func
from sqlalchemy.dialects.mysql import CHAR
from sqlalchemy.orm import relationship
from app.core.database import Base
import uuid
class Task(Base):
"""任务表 — Main Agent 将目标分解为可执行的子任务"""
__tablename__ = "tasks"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="任务ID")
goal_id = Column(CHAR(36), ForeignKey("goals.id"), nullable=False, comment="所属目标ID")
title = Column(String(500), nullable=False, comment="任务标题")
description = Column(Text, comment="任务描述")
status = Column(
String(20), default="pending",
comment="状态: pending/in_progress/awaiting_approval/completed/failed/cancelled"
)
priority = Column(Integer, default=5, comment="优先级 1-10")
# 任务编排配置
task_config = Column(JSON, comment="编排配置: {orchestration_mode, agents:[], workflow_id, input_data}")
# 依赖关系(参考 Claude Code task_system 设计)
parent_task_id = Column(CHAR(36), ForeignKey("tasks.id"), nullable=True, comment="父任务ID")
depends_on = Column(JSON, default=list, comment="前置依赖任务ID列表 (blockedBy)")
blocks = Column(JSON, default=list, comment="被此任务阻塞的任务ID列表")
# 认领机制(参考 Claude Code claimTask
owner = Column(String(200), nullable=True, comment="认领此任务的 Agent 标识 (区别于 assigned_agent_id)")
# 执行结果
result = Column(JSON, comment="执行输出结果")
error_message = Column(Text, comment="错误信息")
execution_id = Column(CHAR(36), ForeignKey("executions.id"), nullable=True, comment="关联的执行记录ID")
# 分配
assigned_agent_id = Column(CHAR(36), ForeignKey("agents.id"), nullable=True, comment="分配的 Agent ID")
assigned_agent_name = Column(String(200), comment="分配的 Agent 名称(冗余便于展示)")
# 审批
requires_approval = Column(Boolean, default=False, comment="是否需要人工审批")
approver_id = Column(CHAR(36), ForeignKey("users.id"), nullable=True, comment="审批人ID")
approval_status = Column(String(20), comment="审批状态: pending/approved/rejected")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.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="更新时间")
# 关系
goal = relationship("Goal", backref="tasks")
assigned_agent = relationship("Agent", backref="assigned_tasks")
execution = relationship("Execution", backref="task")
def __repr__(self):
return f"<Task(id={self.id}, title={self.title}, status={self.status})>"