- agent_runtime: orchestrator、core/memory/schemas 调整 - agent_monitoring API、service、agent_llm_log 模型与 database 注册 - 前端 AgentDashboard、AgentConfig、Agents/MainLayout/路由与 AgentChat - 文档:(红头)项目核心文档汇总、自主AI Agent改造完成情况、AI agent改造计划 Made-with: Cursor
30 lines
1.6 KiB
Python
30 lines
1.6 KiB
Python
"""
|
|
Agent LLM 调用日志模型 — 记录每次 Agent Runtime 发起的 LLM 调用
|
|
"""
|
|
from sqlalchemy import Column, String, Text, Integer, DateTime, ForeignKey, 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="创建时间")
|