Files
aiagent/backend/app/models/agent_llm_log.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

38 lines
1.9 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")
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"),
)