hyf-backend/th_agenter/models/agent_config.py

44 lines
1.6 KiB
Python
Raw Normal View History

2026-01-21 13:45:39 +08:00
"""Agent configuration model."""
from typing import Optional
from sqlalchemy import String, Text, Boolean, JSON
from sqlalchemy.orm import Mapped, mapped_column
from ..db.base import BaseModel
class AgentConfig(BaseModel):
"""Agent configuration model."""
__tablename__ = "agent_configs"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
name: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
# Agent configuration
enabled_tools: Mapped[list] = mapped_column(JSON, nullable=False, default=list)
max_iterations: Mapped[int] = mapped_column(default=10)
temperature: Mapped[str] = mapped_column(String(10), default="0.1")
system_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
verbose: Mapped[bool] = mapped_column(Boolean, default=True)
# Model configuration
model_name: Mapped[str] = mapped_column(String(100), default="gpt-3.5-turbo")
max_tokens: Mapped[int] = mapped_column(default=2048)
# Status
is_active: Mapped[bool] = mapped_column(default=True)
is_default: Mapped[bool] = mapped_column(default=False)
def __repr__(self):
return f"<AgentConfig(id={self.id}, name='{self.name}', is_active={self.is_active})>"
def __str__(self):
return f"{self.name}[{self.id}] Active: {self.is_active}"
def to_dict(self):
"""Convert to dictionary."""
data = super().to_dict()
data['enabled_tools'] = self.enabled_tools or []
return data