26 lines
1.6 KiB
Python
26 lines
1.6 KiB
Python
|
|
"""Agent 自主学习模式表:记录工具使用模式,支持自主学习优化"""
|
||
|
|
import uuid
|
||
|
|
from datetime import datetime
|
||
|
|
from sqlalchemy import Column, String, Text, Float, Integer, DateTime
|
||
|
|
from app.core.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class AgentLearningPattern(Base):
|
||
|
|
"""Agent 学习模式 — 记录工具调用序列与任务类型的关系"""
|
||
|
|
__tablename__ = "agent_learning_patterns"
|
||
|
|
|
||
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||
|
|
scope_kind = Column(String(16), nullable=False, index=True, comment="作用域类型: agent/bare")
|
||
|
|
scope_id = Column(String(64), nullable=False, index=True, comment="作用域 ID: agent_id/user_id")
|
||
|
|
task_category = Column(String(64), nullable=False, default="general", comment="任务分类")
|
||
|
|
task_keywords = Column(String(256), default="", comment="任务关键词")
|
||
|
|
suggested_tools = Column(Text, nullable=False, comment="推荐工具序列 (JSON array)")
|
||
|
|
effectiveness_score = Column(Float, default=0.0, comment="有效评分 0-1")
|
||
|
|
total_runs = Column(Integer, default=1, comment="总运行次数")
|
||
|
|
successful_runs = Column(Integer, default=1, comment="成功次数")
|
||
|
|
avg_iterations = Column(Float, default=1.0, comment="平均迭代次数")
|
||
|
|
avg_tool_calls = Column(Float, default=1.0, comment="平均工具调用数")
|
||
|
|
last_used_at = Column(DateTime, default=datetime.utcnow, comment="最后使用时间")
|
||
|
|
created_at = Column(DateTime, default=datetime.utcnow, comment="创建时间")
|
||
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment="更新时间")
|