feat: 将 Agent 接入运行时镜像挂载式部署

This commit is contained in:
2026-09-20 17:34:25 +08:00
parent 5393ad3423
commit 67c2d58c32
20 changed files with 499 additions and 40 deletions
+36 -4
View File
@@ -1,14 +1,46 @@
"""应用配置(环境变量)。"""
"""应用配置:按 AGENT_ENV 加载 .env.{env},环境变量优先。"""
from __future__ import annotations
import os
from functools import lru_cache
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
# 与后端 Spring profile 对齐:dev | test | pre | prod
_AGENT_ENV = (os.getenv("AGENT_ENV") or "dev").strip().lower() or "dev"
def _resolve_env_files() -> tuple[str, ...]:
"""加载 .env.{AGENT_ENV};仅 dev 额外允许 .env 覆盖(本机密钥)。"""
files: list[str] = []
profile = Path(f".env.{_AGENT_ENV}")
if profile.is_file():
files.append(str(profile))
if _AGENT_ENV == "dev":
local = Path(".env")
if local.is_file():
files.append(str(local))
if not files:
# 兼容:尚无分环境文件时回退 .env
if Path(".env").is_file():
files.append(".env")
else:
files.append(f".env.{_AGENT_ENV}")
return tuple(files)
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
model_config = SettingsConfigDict(
env_file=_resolve_env_files(),
env_file_encoding="utf-8",
extra="ignore",
)
app_name: str = "ecom-dmb-agent"
# 当前环境名(只读展示;实际由 AGENT_ENV 决定加载哪个文件)
agent_env: str = _AGENT_ENV
host: str = "0.0.0.0"
port: int = 8200
cors_origins: str = "http://localhost:5173,http://localhost:5666"
@@ -20,14 +52,14 @@ class Settings(BaseSettings):
mongo_uri: str = "mongodb://ecom_dmb_agent_dev:ecom_dmb_agent_dev@192.168.3.100:27017/?authSource=ecom_dmb_agent_dev"
mongo_db: str = "ecom_dmb_agent_dev"
# 须与 Server Redis 同库,才能命中 agent:llm:rt:{companyId}
# 须与同环境 Server Redis 同库,才能命中 agent:llm:rt:* 缓存
redis_url: str = "redis://:redis_qinghua@192.168.3.100:6379/2"
llm_cache_ttl_seconds: int = 600
# Java Server 根地址(内部拉 LLM 运行时)
server_base_url: str = "http://localhost:8080"
# 仅本地开发:公司未配置时的 fallback(生产勿用)
# 仅本地开发:公司未配置时的 fallback(test/pre/prod 应关闭)
llm_fallback_enabled: bool = True
llm_fallback_base_url: str = "https://api.openai.com/v1"
llm_fallback_api_key: str = ""