2026-01-19 00:09:36 +08:00
|
|
|
|
"""
|
|
|
|
|
|
智能体模型
|
|
|
|
|
|
"""
|
|
|
|
|
|
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 Agent(Base):
|
|
|
|
|
|
"""智能体表"""
|
|
|
|
|
|
__tablename__ = "agents"
|
|
|
|
|
|
|
|
|
|
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="智能体ID")
|
|
|
|
|
|
name = Column(String(100), nullable=False, comment="智能体名称")
|
|
|
|
|
|
description = Column(Text, comment="描述")
|
|
|
|
|
|
workflow_config = Column(JSON, nullable=False, comment="工作流配置")
|
2026-04-09 21:58:53 +08:00
|
|
|
|
budget_config = Column(
|
|
|
|
|
|
JSON,
|
|
|
|
|
|
nullable=True,
|
|
|
|
|
|
comment="执行预算:max_steps/max_llm_invocations/max_tool_calls(可选,覆盖全局默认)",
|
|
|
|
|
|
)
|
2026-01-19 00:09:36 +08:00
|
|
|
|
version = Column(Integer, default=1, comment="版本号")
|
|
|
|
|
|
status = Column(String(20), default="draft", comment="状态: draft/published/running/stopped")
|
|
|
|
|
|
user_id = Column(CHAR(36), ForeignKey("users.id"), comment="创建者ID")
|
|
|
|
|
|
created_at = Column(DateTime, default=func.now(), comment="创建时间")
|
|
|
|
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
|
|
|
|
|
|
|
|
|
|
|
|
# 关系
|
|
|
|
|
|
user = relationship("User", backref="agents")
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
|
return f"<Agent(id={self.id}, name={self.name})>"
|
2026-05-04 22:05:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AgentExtension(Base):
|
|
|
|
|
|
"""Agent 自主扩展记录表 — 用于 extension_log 工具"""
|
|
|
|
|
|
__tablename__ = "agent_extensions"
|
|
|
|
|
|
|
|
|
|
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="扩展记录ID")
|
|
|
|
|
|
extension_type = Column(String(50), nullable=False, comment="扩展类型: agent_created/tool_registered/code_tool_created")
|
|
|
|
|
|
name = Column(String(100), nullable=False, comment="创建的Agent或工具名称")
|
|
|
|
|
|
reason = Column(Text, comment="创建原因(为什么需要扩展)")
|
|
|
|
|
|
detail = Column(JSON, comment="扩展详情(参数、结果等)")
|
|
|
|
|
|
success_rating = Column(String(20), comment="效果评价: success/partial/failed")
|
|
|
|
|
|
note = Column(Text, comment="反馈备注")
|
|
|
|
|
|
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=True, comment="创建者ID")
|
|
|
|
|
|
created_at = Column(DateTime, default=func.now(), comment="创建时间")
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
|
return f"<AgentExtension(id={self.id}, type={self.extension_type}, name={self.name})>"
|
2026-05-05 00:27:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GlobalKnowledge(Base):
|
|
|
|
|
|
"""Agent 间知识共享表 — 跨 Agent 的全局知识池"""
|
|
|
|
|
|
__tablename__ = "global_knowledge"
|
|
|
|
|
|
|
|
|
|
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="知识ID")
|
|
|
|
|
|
content = Column(Text, nullable=False, comment="知识内容摘要")
|
|
|
|
|
|
embedding = Column(Text, nullable=True, comment="内容 embedding(JSON 序列化)")
|
|
|
|
|
|
source_agent_id = Column(CHAR(36), nullable=True, comment="来源 Agent ID")
|
|
|
|
|
|
source_user_id = Column(CHAR(36), nullable=True, comment="来源用户 ID")
|
|
|
|
|
|
tags = Column(JSON, nullable=True, comment="分类标签")
|
|
|
|
|
|
scope_kind = Column(String(50), default="agent", comment="作用域类型")
|
|
|
|
|
|
scope_id = Column(String(100), default="", comment="作用域 ID")
|
|
|
|
|
|
created_at = Column(DateTime, default=func.now(), comment="创建时间")
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
|
return f"<GlobalKnowledge(id={self.id}, source_agent={self.source_agent_id})>"
|