Files
aiagent/backend/app/models/agent_llm_log.py
renjianbo 876789fac1 feat: multi-tenant workspace isolation, RBAC, sidebar nav, billing, and Android enhancements
- 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>
2026-07-04 01:00:22 +08:00

39 lines
2.0 KiB
Python

"""
Agent LLM 调用日志模型 — 记录每次 Agent Runtime 发起的 LLM 调用
"""
from sqlalchemy import Column, String, Text, Integer, DateTime, ForeignKey, Index, func
from sqlalchemy.dialects.mysql import CHAR
from app.core.database import Base
import uuid
class AgentLLMLog(Base):
"""Agent LLM 调用日志表"""
__tablename__ = "agent_llm_logs"
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="Agent ID")
session_id = Column(String(100), nullable=True, comment="会话ID")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=True, comment="用户ID")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, index=True, comment="工作区ID")
model = Column(String(100), nullable=False, comment="模型名称")
provider = Column(String(50), nullable=True, comment="提供商")
prompt_tokens = Column(Integer, default=0, comment="提示 tokens")
completion_tokens = Column(Integer, default=0, comment="生成 tokens")
total_tokens = Column(Integer, default=0, comment="总 tokens")
latency_ms = Column(Integer, default=0, comment="调用耗时(ms)")
iteration_number = Column(Integer, default=0, comment="ReAct 迭代轮次")
step_type = Column(String(20), nullable=True, comment="步骤类型: think/final")
tool_name = Column(String(100), nullable=True, comment="工具名称(如是工具调用)")
status = Column(String(20), default="success", comment="状态: success/error")
error_message = Column(Text, nullable=True, comment="错误信息")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
__table_args__ = (
Index("idx_llm_agent_id", "agent_id"),
Index("idx_llm_user_id", "user_id"),
Index("idx_llm_session_id", "session_id"),
Index("idx_llm_created_at", "created_at"),
Index("idx_llm_agent_created", "agent_id", "created_at"),
)