Agent 서버 구축: 멀티테넌트 협상 PoC (UCB Q-Table 학습 + /chat + 14 API + 학습검증 하네스), config 단일화(local.toml) + 빌드 경량화

This commit is contained in:
HyeongBaeYang committed 2026-06-17 11:10:03 +09:00
1 parent 212725e5f9
commit 951d6eab84
140 files changed
+6689 -214

No files matched your search

View File
Whitespace-only changes.
+32
View File
@@ -0,0 +1,32 @@
import tomllib
from typing import Optional, Type, Dict, TypeVar
from pydantic import BaseModel
class ConfigModel(BaseModel):
pass
# APP_ENV (backend 와 동일 규약)
# local : 로컬 환경(개인 pc) / dev : 개발환경 / prod : 서비스 환경
# 실행 시: export APP_ENV=dev (linux) / set APP_ENV=dev (windows)
class Configs:
ConfigType = TypeVar("ConfigType", bound=ConfigModel)
def __init__(self, file_path: str):
self._settings: Dict[Type["Configs.ConfigType"], "Configs.ConfigType"] = self._load_settings_from_toml(file_path)
def _load_settings_from_toml(self, file_path: str) -> Dict[Type[ConfigType], ConfigType]:
with open(file_path, "rb") as f:
toml_content = tomllib.load(f)
config_subclasses = ConfigModel.__subclasses__()
configs = {
config_class: config_class.model_validate(toml_content[config_class.__name__])
for config_class in config_subclasses
if config_class.__name__ in toml_content
}
return configs
def get(self, config_class: Type[ConfigType]) -> Optional[ConfigType]:
return self._settings.get(config_class)
+62
View File
@@ -0,0 +1,62 @@
from config.config_loader import ConfigModel
class WebServerConfig(ConfigModel):
server_name: str = ""
port: int = 0
process_count: int = 1
is_ssl: bool = False
is_test: bool = False
class LogConfig(ConfigModel):
print_console: bool = True
log_level: str = "debug"
# DB Read/Write 분리 설정. backend 와 동일 구조 (negosium_db 공유).
class MainDBConfig(ConfigModel):
db_type: str = "postgresql"
name: str = ""
write_host: str = ""
write_port: int = 5432
write_id: str = ""
write_pw: str = ""
read_host: str = ""
read_port: int = 5432
read_id: str = ""
read_pw: str = ""
show_log: bool = False
pool_size: int = 10
max_overflow: int = 20
class OpenAIConfig(ConfigModel):
"""LLM(OpenAI/Azure) 접속 설정. 프로젝트 컨벤션대로 toml 로 관리.
⚠️ api_key 는 시크릿 — config.local.toml 은 외부 공개 저장소에 push 하지 말 것.
"""
provider: str = "openai" # "openai" | "azure"
api_key: str = ""
model: str = "gpt-4o-mini" # openai: 모델명 / azure: 배포(deployment) 이름
base_url: str = "" # openai 호환 게이트웨이용(옵션)
# azure 전용
azure_endpoint: str = ""
api_version: str = ""
class AgentConfig(ConfigModel):
"""협상 에이전트 전역 설정. 테넌트별 세부 설정은 tenants/<id>/tenant.yaml (TenantConfig, P1).
여기에는 서버군 공통값만 둔다.
"""
# 테넌트 정적 리소스 루트 (tenants/<id>/...)
tenants_dir: str = "tenants"
# TenantConfig TTL 캐시(초). 0 이면 매 요청 로드.
config_cache_ttl_seconds: int = 300
# default tenant 금지 (KT 사고 방지). 미들웨어가 헤더 부재 시 400.
allow_default_tenant: bool = False
# 서버 기동 시 공유 베이스(_base)가 없으면 자동 시드 (운영 자동화).
auto_seed_base: bool = True
base_action_space: int = 9 # 베이스 Q-Table action 차원 (신규 테넌트와 호환돼야 복제됨)
base_seed_episodes: int = 300 # 베이스 시드 학습 에피소드 수
+22
View File
@@ -0,0 +1,22 @@
import os
from config.config_loader import Configs
from config.config_models import WebServerConfig, LogConfig, MainDBConfig, AgentConfig, OpenAIConfig
# 실행 환경 결정 (기본 local). 환경변수 APP_ENV 로 변경. (backend 와 동일)
APP_ENV = os.environ.get("APP_ENV", "local")
_config_dir = os.path.dirname(__file__)
_config_file = os.path.join(_config_dir, f"config.{APP_ENV}.toml")
# 운영 전제: 항상 APP_ENV=local 로 띄운다 → config.local.toml 사용 (test/docker 도 local 로 실행).
if not os.path.exists(_config_file):
raise FileNotFoundError(f"설정 파일이 없습니다: {_config_file} (APP_ENV={APP_ENV}). APP_ENV=local 로 실행하세요.")
configs = Configs(_config_file)
web_server_config: WebServerConfig = configs.get(WebServerConfig)
log_config: LogConfig = configs.get(LogConfig)
main_db_config: MainDBConfig = configs.get(MainDBConfig)
agent_config: AgentConfig = configs.get(AgentConfig)
openai_config: OpenAIConfig = configs.get(OpenAIConfig) or OpenAIConfig()