ff40ff9dd8
- 数据库:添加 has_purchased_starter_pack 字段到 register_bonus_claims - 后端:创建静态配置管理套餐信息,支持按国家/地区区分 - 后端:新增 GET /api/v1/points/packages API 返回可用套餐 - 后端:创建 utils/paths.py 统一路径管理 - 前端:动态获取套餐信息,移除硬编码 - 前端:添加 ProductCode 枚举约束,前后端类型安全 - 配置:Profile 默认国家改为 US(ISO 3166-1 alpha-2) - 文档:更新协议文档说明新 API 和字段
94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
"""
|
|
System agents 配置加载工具
|
|
|
|
从 system_agents.yaml 加载配置并构建 RuntimeConfig
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
from pydantic import ValidationError
|
|
|
|
from schemas.agent.system_agent import SystemAgentLLMConfig
|
|
from schemas.agent.runtime_config import (
|
|
ContextSource,
|
|
ContextWindowMode,
|
|
MessageContextConfig,
|
|
RuntimeConfig,
|
|
)
|
|
from utils.paths import get_system_agents_config_path
|
|
|
|
|
|
def _default_system_agents_path() -> Path:
|
|
return get_system_agents_config_path()
|
|
|
|
|
|
def _load_system_agents_yaml(path: Path | None = None) -> dict[str, object]:
|
|
target_path = path or _default_system_agents_path()
|
|
with target_path.open("r", encoding="utf-8") as f:
|
|
loaded = yaml.safe_load(f) or {}
|
|
if not isinstance(loaded, dict):
|
|
raise ValueError(f"Invalid system agents format: {target_path}")
|
|
return loaded
|
|
|
|
|
|
def _parse_context_messages_config(
|
|
yaml_config: dict[str, object] | None,
|
|
) -> MessageContextConfig:
|
|
if not yaml_config:
|
|
return MessageContextConfig()
|
|
raw_mode = yaml_config.get("mode", "day")
|
|
mode_str = raw_mode if isinstance(raw_mode, str) else "day"
|
|
raw_count = yaml_config.get("count", 2)
|
|
count = raw_count if isinstance(raw_count, int) else 2
|
|
try:
|
|
source = ContextSource.LATEST_CHAT
|
|
except ValueError:
|
|
source = ContextSource.LATEST_CHAT
|
|
try:
|
|
window_mode = ContextWindowMode(mode_str)
|
|
except ValueError:
|
|
window_mode = ContextWindowMode.DAY
|
|
return MessageContextConfig(
|
|
source=source,
|
|
window_mode=window_mode,
|
|
window_count=count,
|
|
)
|
|
|
|
|
|
def build_runtime_config_from_system_agents(
|
|
yaml_path: Path | None = None,
|
|
) -> RuntimeConfig:
|
|
"""
|
|
从 system_agents.yaml 构建 RuntimeConfig
|
|
|
|
仅使用 worker 配置:
|
|
- worker.context_messages 配置上下文窗口
|
|
- enabled_tools 固定为空(eryao 不启用自定义工具)
|
|
"""
|
|
raw = _load_system_agents_yaml(yaml_path)
|
|
raw_agents = raw.get("agents", [])
|
|
agents_list = raw_agents if isinstance(raw_agents, list) else []
|
|
|
|
worker_config: SystemAgentLLMConfig | None = None
|
|
|
|
for agent in agents_list:
|
|
if not isinstance(agent, dict):
|
|
continue
|
|
agent_type = str(agent.get("agent_type", "")).strip().lower()
|
|
if agent_type == "worker":
|
|
config_dict = agent.get("config") or {}
|
|
try:
|
|
worker_config = SystemAgentLLMConfig.model_validate(config_dict)
|
|
except ValidationError:
|
|
worker_config = SystemAgentLLMConfig()
|
|
|
|
context_cfg = _parse_context_messages_config(
|
|
worker_config.context_messages.model_dump() if worker_config else None
|
|
)
|
|
|
|
return RuntimeConfig(
|
|
enabled_tools=[],
|
|
context=context_cfg,
|
|
)
|