- Backend: workspace_id isolation for 14 model tables + safe migration/backfill - Backend: RBAC system with 4 roles and 23 permissions, seeded on startup - Backend: workspace admin endpoints (list/manage all workspaces) - Backend: admin user management API (CRUD, reset password) - Backend: billing API with subscription plans, usage tracking, rate limiting - Backend: fix system_logs.py UNION query and wrong column references - Backend: WebSocket JWT auth and workspace enforcement - Frontend: sidebar navigation replacing top dropdown menu - Frontend: user management page (Users.vue) for admins - Frontend: enhanced Workspaces.vue with admin table view - Frontend: workspace RBAC computed properties in user store - Android: agent marketplace, billing/subscription UI, onboarding wizard - Android: phone login, analytics tracker, crash handler, network diagnostics - Android: splash screen, encrypted token storage, app update enhancements - Docs: multi-tenant RBAC guide with 8 sections and role-permission matrix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
2.8 KiB
Python
59 lines
2.8 KiB
Python
"""
|
||
Agent 执行日志模型 — 结构化记录每次 Agent 执行的完整信息
|
||
用于知识自进化系统的数据基础
|
||
"""
|
||
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, Float, Boolean, ForeignKey
|
||
from sqlalchemy.dialects.mysql import CHAR
|
||
from app.core.database import Base
|
||
import uuid
|
||
from datetime import datetime
|
||
|
||
|
||
class AgentExecutionLog(Base):
|
||
"""Agent 每次执行的完整结构化日志"""
|
||
__tablename__ = "agent_execution_logs"
|
||
|
||
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="日志ID")
|
||
agent_id = Column(String(36), nullable=True, index=True, comment="Agent ID")
|
||
agent_name = Column(String(200), nullable=True, comment="Agent 名称")
|
||
goal_id = Column(String(36), nullable=True, index=True, comment="关联 Goal ID")
|
||
task_id = Column(String(36), nullable=True, index=True, comment="关联 Task ID")
|
||
user_id = Column(String(36), nullable=True, index=True, comment="用户 ID")
|
||
session_id = Column(String(100), nullable=True, comment="会话标识")
|
||
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, index=True, comment="工作区ID")
|
||
|
||
# 输入/输出
|
||
input_text = Column(Text, nullable=True, comment="用户输入文本")
|
||
output_text = Column(Text, nullable=True, comment="Agent 输出文本")
|
||
output_truncated = Column(Boolean, default=False, comment="输出是否被截断")
|
||
|
||
# 执行结果
|
||
success = Column(Boolean, default=True, comment="是否成功")
|
||
error_message = Column(Text, nullable=True, comment="错误信息")
|
||
|
||
# 性能指标
|
||
latency_ms = Column(Integer, nullable=True, comment="总耗时(ms)")
|
||
iterations_used = Column(Integer, default=0, comment="ReAct 迭代次数")
|
||
tool_calls_made = Column(Integer, default=0, comment="工具调用总次数")
|
||
|
||
# 结构化明细(JSON)
|
||
tool_chain = Column(JSON, nullable=True, comment="工具调用链: [{tool_name, input, output, duration_ms}]")
|
||
llm_calls = Column(JSON, nullable=True, comment="LLM调用明细: [{model, prompt_tokens, completion_tokens, latency_ms}]")
|
||
steps = Column(JSON, nullable=True, comment="执行步骤详情(精简版)")
|
||
|
||
# 模型信息
|
||
model = Column(String(100), nullable=True, comment="使用的模型")
|
||
provider = Column(String(50), nullable=True, comment="模型提供商")
|
||
|
||
# 用户反馈(后续补充)
|
||
user_rating = Column(Integer, nullable=True, comment="用户评分(1-5)")
|
||
user_feedback = Column(Text, nullable=True, comment="用户反馈文本")
|
||
|
||
# 知识提取标记
|
||
knowledge_extracted = Column(Boolean, default=False, comment="是否已提取知识")
|
||
|
||
created_at = Column(DateTime, default=datetime.now, comment="创建时间")
|
||
|
||
def __repr__(self):
|
||
return f"<AgentExecutionLog(id={self.id}, agent={self.agent_name}, success={self.success})>"
|