hxf/backend/th_agenter/models/agent_config.py

43 lines
1.5 KiB
Python
Raw Normal View History

2025-12-04 14:48:38 +08:00
"""Agent configuration model."""
2025-12-16 13:55:16 +08:00
from sqlalchemy import String, Text, Boolean, JSON
from sqlalchemy.orm import Mapped, mapped_column
2025-12-04 14:48:38 +08:00
from ..db.base import BaseModel
class AgentConfig(BaseModel):
"""Agent configuration model."""
__tablename__ = "agent_configs"
2025-12-16 13:55:16 +08:00
id: Mapped[int] = mapped_column(primary_key=True, index=True)
name: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
2025-12-04 14:48:38 +08:00
# Agent configuration
2025-12-16 13:55:16 +08:00
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[str | None] = mapped_column(Text, nullable=True)
verbose: Mapped[bool] = mapped_column(Boolean, default=True)
2025-12-04 14:48:38 +08:00
# Model configuration
2025-12-16 13:55:16 +08:00
model_name: Mapped[str] = mapped_column(String(100), default="gpt-3.5-turbo")
max_tokens: Mapped[int] = mapped_column(default=2048)
2025-12-04 14:48:38 +08:00
# Status
2025-12-16 13:55:16 +08:00
is_active: Mapped[bool] = mapped_column(default=True)
is_default: Mapped[bool] = mapped_column(default=False)
2025-12-04 14:48:38 +08:00
def __repr__(self):
return f"<AgentConfig(id={self.id}, name='{self.name}', is_active={self.is_active})>"
2025-12-16 13:55:16 +08:00
def __str__(self):
return f"{self.name}[{self.id}] Active: {self.is_active}"
2025-12-04 14:48:38 +08:00
def to_dict(self):
"""Convert to dictionary."""
2025-12-16 13:55:16 +08:00
data = super().to_dict()
data['enabled_tools'] = self.enabled_tools or []
return data