minions-ai-agents/src/config.py

158 lines
5.1 KiB
Python

"""
Central Configuration for Arthur Agent.
Manages all configuration from environment variables and Docker Secrets.
"""
import os
import logging
from dotenv import load_dotenv
from dataclasses import dataclass
from typing import Optional
# Load environment variables
load_dotenv()
# Setup Logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)
logger = logging.getLogger("ArthurConfig")
@dataclass
class QdrantConfig:
"""Qdrant vector database configuration."""
host: str = "localhost"
port: int = 6333
collection_name: str = "arthur_knowledge"
use_grpc: bool = False
on_disk: bool = True # Per PRD: optimize RAM usage
@dataclass
class PostgresConfig:
"""PostgreSQL database configuration."""
host: str = "postgres"
port: int = 5432
database: str = "arthur_db"
user: str = "arthur"
password: Optional[str] = None
min_pool_size: int = 2
max_pool_size: int = 10
@dataclass
class LLMConfig:
"""Local LLM configuration for CPU inference."""
# Triage Model (1B - Fast)
triage_model: str = "llama3.2:1b"
triage_threads: int = 4
# Specialist Model (8B - Reasoning)
specialist_model: str = "llama3.1:8b"
specialist_threads: int = 12
# Ollama endpoint
ollama_base_url: str = "http://localhost:11434"
# Context windows
triage_context: int = 2048
specialist_context: int = 8192
@dataclass
class ZabbixConfig:
"""Zabbix API configuration."""
url: str = "https://noc.itguys.com.br/api_jsonrpc.php"
api_token: Optional[str] = None
verify_ssl: bool = True
timeout: int = 30
@dataclass
class MailConfig:
"""Email configuration."""
imap_host: str = "mail.itguys.com.br"
imap_port: int = 993
smtp_host: str = "mail.itguys.com.br"
smtp_port: int = 587
email_address: str = "arthur.servicedesk@itguys.com.br"
password: Optional[str] = None
class Config:
"""
Central Configuration for Arthur Agent.
"""
@staticmethod
def get_qdrant_config() -> QdrantConfig:
"""Returns Qdrant connection configuration."""
return QdrantConfig(
host=os.getenv("QDRANT_HOST", "qdrant"),
port=int(os.getenv("QDRANT_PORT", "6333")),
collection_name=os.getenv("QDRANT_COLLECTION", "arthur_knowledge"),
use_grpc=os.getenv("QDRANT_USE_GRPC", "false").lower() == "true",
on_disk=os.getenv("QDRANT_ON_DISK", "true").lower() == "true",
)
@staticmethod
def get_postgres_config() -> PostgresConfig:
"""Returns PostgreSQL configuration."""
return PostgresConfig(
host=os.getenv("POSTGRES_HOST", "postgres"),
port=int(os.getenv("POSTGRES_PORT", "5432")),
database=os.getenv("POSTGRES_DB", "arthur_db"),
user=os.getenv("POSTGRES_USER", "arthur"),
password=os.getenv("POSTGRES_PASSWORD"),
min_pool_size=int(os.getenv("POSTGRES_MIN_POOL", "2")),
max_pool_size=int(os.getenv("POSTGRES_MAX_POOL", "10")),
)
@staticmethod
def get_llm_config() -> LLMConfig:
"""Returns LLM Configuration for Local Inference."""
return LLMConfig(
triage_model=os.getenv("LLM_TRIAGE_MODEL", "llama3.2:1b"),
triage_threads=int(os.getenv("LLM_TRIAGE_THREADS", "4")),
specialist_model=os.getenv("LLM_SPECIALIST_MODEL", "llama3.1:8b"),
specialist_threads=int(os.getenv("LLM_SPECIALIST_THREADS", "12")),
ollama_base_url=os.getenv("OLLAMA_BASE_URL", "http://localhost:11434"),
triage_context=int(os.getenv("LLM_TRIAGE_CONTEXT", "2048")),
specialist_context=int(os.getenv("LLM_SPECIALIST_CONTEXT", "8192")),
)
@staticmethod
def get_zabbix_config() -> ZabbixConfig:
"""Returns Zabbix API configuration."""
return ZabbixConfig(
url=os.getenv("ZABBIX_API_URL", "https://noc.itguys.com.br/api_jsonrpc.php"),
api_token=os.getenv("ZABBIX_API_TOKEN"),
verify_ssl=os.getenv("ZABBIX_VERIFY_SSL", "true").lower() == "true",
timeout=int(os.getenv("ZABBIX_TIMEOUT", "30")),
)
@staticmethod
def get_mail_config() -> MailConfig:
"""Returns email configuration."""
return MailConfig(
imap_host=os.getenv("MAIL_IMAP_HOST", "mail.itguys.com.br"),
imap_port=int(os.getenv("MAIL_IMAP_PORT", "993")),
smtp_host=os.getenv("MAIL_SMTP_HOST", "mail.itguys.com.br"),
smtp_port=int(os.getenv("MAIL_SMTP_PORT", "587")),
email_address=os.getenv("MAIL_ADDRESS", "arthur.servicedesk@itguys.com.br"),
password=os.getenv("MAIL_PASSWORD"),
)
@staticmethod
def is_production() -> bool:
"""Check if running in production mode."""
return os.getenv("ENVIRONMENT", "development").lower() == "production"
@staticmethod
def get_log_level() -> int:
"""Get configured log level."""
level = os.getenv("LOG_LEVEL", "INFO").upper()
return getattr(logging, level, logging.INFO)