Newer
Older
cortex-hub / poc-grpc-agent / agent_node / config.py
import os
import platform
import yaml

# Path to the generated config file in the bundled distribution
CONFIG_PATH = "agent_config.yaml"

# Default values
_defaults = {
    "node_id": "agent-node-007",
    "node_description": "Modular Stateful Node",
    "hub_url": "https://ai.jerxie.com",
    "grpc_endpoint": "localhost:50051",
    "auth_token": os.getenv("AGENT_AUTH_TOKEN", "cortex-secret-shared-key"),
    "sync_root": "/tmp/cortex-sync",
    "tls": True,
    "max_skill_workers": 5,
    "health_report_interval": 10,
}

# 1. Load from YAML if present
_config = _defaults.copy()
if os.path.exists(CONFIG_PATH):
    try:
        with open(CONFIG_PATH, 'r') as f:
            yaml_config = yaml.safe_load(f) or {}
            _config.update(yaml_config)
            print(f"[*] Loaded node configuration from {CONFIG_PATH}")
    except Exception as e:
        print(f"[!] Error loading {CONFIG_PATH}: {e}")

# 2. Override with Environment Variables (12-Factor style)
NODE_ID = os.getenv("AGENT_NODE_ID", _config["node_id"])
NODE_DESC = os.getenv("AGENT_NODE_DESC", _config["node_description"])
SERVER_HOST_PORT = os.getenv("GRPC_ENDPOINT", _config["grpc_endpoint"]) # e.g. "ai.jerxie.com:50051"
AUTH_TOKEN = os.getenv("AGENT_AUTH_TOKEN", _config["auth_token"])
SYNC_DIR = os.getenv("CORTEX_SYNC_DIR", _config["sync_root"])
TLS_ENABLED = os.getenv("AGENT_TLS_ENABLED", str(_config["tls"])).lower() == 'true'

HEALTH_REPORT_INTERVAL = int(os.getenv("HEALTH_REPORT_INTERVAL", _config["health_report_interval"]))
MAX_SKILL_WORKERS = int(os.getenv("MAX_SKILL_WORKERS", _config["max_skill_workers"]))

SECRET_KEY = os.getenv("AGENT_SECRET_KEY", _config.get("secret_key", "dev-secret-key-1337"))

# These are still available but likely replaced by AUTH_TOKEN / TLS_ENABLED logic
CERT_CA = os.getenv("CERT_CA", "certs/ca.crt")
CERT_CLIENT_CRT = os.getenv("CERT_CLIENT_CRT", "certs/client.crt")
CERT_CLIENT_KEY = os.getenv("CERT_CLIENT_KEY", "certs/client.key")