refactor(config): rename user_agent_catalog to system_agents

This commit is contained in:
qzl
2026-03-04 11:07:49 +08:00
parent 2d410e8e84
commit 5bbfec52ab
2 changed files with 21 additions and 21 deletions
+21 -21
View File
@@ -13,7 +13,7 @@ from core.db.session import AsyncSessionLocal
from core.logging import get_logger from core.logging import get_logger
from models.llm import Llm from models.llm import Llm
from models.llm_factory import LlmFactory from models.llm_factory import LlmFactory
from models.user_agent_catalog import UserAgentCatalog from models.system_agents import SystemAgents
logger = get_logger("core.config.initial.init_data") logger = get_logger("core.config.initial.init_data")
@@ -34,15 +34,15 @@ class LlmCatalogSeed(BaseModel):
llms: list[LlmSeed] llms: list[LlmSeed]
class UserAgentCatalogSeed(BaseModel): class SystemAgentsSeed(BaseModel):
agent_type: str agent_type: str
llm_model_code: str llm_model_code: str
status: str status: str
config: dict[str, Any] config: dict[str, Any]
class UserAgentCatalogYaml(BaseModel): class SystemAgentsYaml(BaseModel):
agents: list[UserAgentCatalogSeed] agents: list[SystemAgentsSeed]
def _default_catalog_path() -> Path: def _default_catalog_path() -> Path:
@@ -74,28 +74,28 @@ def load_llm_catalog(catalog_path: Path | None = None) -> dict[str, Any]:
return parsed.model_dump() return parsed.model_dump()
def _default_user_agent_catalog_path() -> Path: def _default_system_agents_path() -> Path:
return ( return (
Path(__file__).resolve().parents[1] Path(__file__).resolve().parents[1]
/ "static" / "static"
/ "database" / "database"
/ "user_agent_catalog.yaml" / "system_agents.yaml"
) )
def load_user_agent_catalog(catalog_path: Path | None = None) -> dict[str, Any]: def load_system_agents(catalog_path: Path | None = None) -> dict[str, Any]:
path = catalog_path or _default_user_agent_catalog_path() path = catalog_path or _default_system_agents_path()
with path.open("r", encoding="utf-8") as file: with path.open("r", encoding="utf-8") as file:
loaded = yaml.safe_load(file) or {} loaded = yaml.safe_load(file) or {}
if not isinstance(loaded, dict): if not isinstance(loaded, dict):
raise ValueError(f"Invalid user agent catalog format: {path}") raise ValueError(f"Invalid system agents format: {path}")
raw_agents = loaded.get("agents", []) raw_agents = loaded.get("agents", [])
if not isinstance(raw_agents, list): if not isinstance(raw_agents, list):
raise ValueError(f"Invalid user agent catalog agents section: {path}") raise ValueError(f"Invalid system agents agents section: {path}")
try: try:
parsed = UserAgentCatalogYaml.model_validate({"agents": list(raw_agents)}) parsed = SystemAgentsYaml.model_validate({"agents": list(raw_agents)})
except ValidationError as exc: except ValidationError as exc:
raise ValueError(f"Invalid user agent catalog data: {path}") from exc raise ValueError(f"Invalid system agents data: {path}") from exc
return parsed.model_dump() return parsed.model_dump()
@@ -135,7 +135,7 @@ async def _upsert_llm(
llm.factory_id = factory_id llm.factory_id = factory_id
async def _upsert_user_agent_catalog( async def _upsert_system_agents(
session: AsyncSession, session: AsyncSession,
*, *,
agent_type: str, agent_type: str,
@@ -144,13 +144,13 @@ async def _upsert_user_agent_catalog(
config: dict[str, Any], config: dict[str, Any],
) -> None: ) -> None:
result = await session.execute( result = await session.execute(
select(UserAgentCatalog).where(UserAgentCatalog.agent_type == agent_type) select(SystemAgents).where(SystemAgents.agent_type == agent_type)
) )
catalog_entry = result.scalar_one_or_none() catalog_entry = result.scalar_one_or_none()
if catalog_entry is None: if catalog_entry is None:
session.add( session.add(
UserAgentCatalog( SystemAgents(
agent_type=agent_type, agent_type=agent_type,
llm_id=llm_id, llm_id=llm_id,
status=status, status=status,
@@ -163,9 +163,9 @@ async def _upsert_user_agent_catalog(
catalog_entry.config = config catalog_entry.config = config
async def initialize_user_agent_catalog() -> None: async def initialize_system_agents() -> None:
"""Initialize user agent catalog from YAML.""" """Initialize system agents from YAML."""
catalog = load_user_agent_catalog() catalog = load_system_agents()
async with AsyncSessionLocal() as session: async with AsyncSessionLocal() as session:
async with session.begin(): async with session.begin():
@@ -179,7 +179,7 @@ async def initialize_user_agent_catalog() -> None:
f"LLM model '{agent['llm_model_code']}' not found for agent type '{agent['agent_type']}'" f"LLM model '{agent['llm_model_code']}' not found for agent type '{agent['agent_type']}'"
) )
await _upsert_user_agent_catalog( await _upsert_system_agents(
session, session,
agent_type=agent["agent_type"], agent_type=agent["agent_type"],
llm_id=llm.id, llm_id=llm.id,
@@ -187,7 +187,7 @@ async def initialize_user_agent_catalog() -> None:
config=agent["config"], config=agent["config"],
) )
logger.info("Initialized user agent catalog") logger.info("Initialized system agents")
async def initialize_llm_catalog() -> None: async def initialize_llm_catalog() -> None:
@@ -225,6 +225,6 @@ async def initialize_llm_catalog() -> None:
async def initialize_data() -> bool: async def initialize_data() -> bool:
"""Initialize bootstrap data.""" """Initialize bootstrap data."""
await initialize_llm_catalog() await initialize_llm_catalog()
await initialize_user_agent_catalog() await initialize_system_agents()
return True return True