# docker-compose.yml — Chanakya agent stack
# Run from the project root:   docker compose up
# Build only:                  docker compose build
# Rebuild on code change:      docker compose up --build

# ── Environment ────────────────────────────────────────────────────────────
# Copy .env.example to .env and fill in the values before running.
# Variables can also be passed on the command line:
#   LITELLM_PROVIDER_BASE_URL=http://... docker compose up

x-agent-env: &agent-env          # shared env block for all three services
  LITELLM_PROVIDER_BASE_URL: ${LITELLM_PROVIDER_BASE_URL}
  LITELLM_PROVIDER_MODEL_NAME: ${LITELLM_PROVIDER_MODEL_NAME:-gemini/gemini-2.5-flash}
  LITELLM_API_KEY: ${LITELLM_API_KEY:-}
  LOGFIRE_TOKEN: ${LOGFIRE_TOKEN:-}

services:

  # ── Gmail A2A sub-agent (DISABLED — code preserved, not started) ────────
  # Uncomment to re-enable.
  # gmail-agent:
  #   build:
  #     context: .
  #     dockerfile: backend/chanakya/gmail/Dockerfile
  #   image: chanakya/gmail-agent:latest
  #   environment:
  #     <<: *agent-env
  #     GMAIL_AGENT_HOST: "0.0.0.0"
  #     GMAIL_AGENT_PORT: "8001"
  #     PYLOGUE_DB_PATH: "/data/chat_history.db"
  #   ports:
  #     - "${GMAIL_AGENT_PORT:-8001}:8001"
  #   volumes:
  #     - ./data/conversation-histories/gmail:/data
  #   healthcheck:
  #     test: ["CMD", "python", "-c",
  #            "import urllib.request; urllib.request.urlopen('http://localhost:8001/.well-known/agent-card.json')"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 5
  #     start_period: 15s
  #   restart: unless-stopped

  # ── Jira A2A sub-agent (DISABLED — code preserved, not started) ─────────
  # Uncomment to re-enable.
  # jira-agent:
  #   build:
  #     context: .
  #     dockerfile: backend/chanakya/jira/Dockerfile
  #   image: chanakya/jira-agent:latest
  #   environment:
  #     <<: *agent-env
  #     JIRA_AGENT_HOST: "0.0.0.0"
  #     JIRA_AGENT_PORT: "8002"
  #     PYLOGUE_DB_PATH: "/data/chat_history.db"
  #   ports:
  #     - "${JIRA_AGENT_PORT:-8002}:8002"
  #   volumes:
  #     - ./data/conversation-histories/jira:/data
  #   healthcheck:
  #     test: ["CMD", "python", "-c",
  #            "import urllib.request; urllib.request.urlopen('http://localhost:8002/.well-known/agent-card.json')"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 5
  #     start_period: 15s
  #   restart: unless-stopped

  # ── Insurance A2A sub-agent (DISABLED — code preserved, not started) ────
  # Uncomment to re-enable.
  # insurance-agent:
  #   build:
  #     context: .
  #     dockerfile: backend/chanakya/insurance/Dockerfile
  #   image: chanakya/insurance-agent:latest
  #   environment:
  #     <<: *agent-env
  #     INSURANCE_AGENT_HOST: "0.0.0.0"
  #     INSURANCE_AGENT_PORT: "8004"
  #     INSURANCE_DB_HOST: ${INSURANCE_DB_HOST:-db.divami.com}
  #     INSURANCE_DB_PORT: ${INSURANCE_DB_PORT:-5432}
  #     INSURANCE_DB_NAME: ${INSURANCE_DB_NAME}
  #     INSURANCE_DB_USER: ${INSURANCE_DB_USER}
  #     INSURANCE_DB_PASSWORD: ${INSURANCE_DB_PASSWORD}
  #     POSTGRES_SCHEMA_PATH: "/app/backend/chanakya/insurance/schema.sql"
  #     PYLOGUE_DB_PATH: "/data/chat_history.db"
  #   ports:
  #     - "${INSURANCE_AGENT_PORT:-8004}:8004"
  #   volumes:
  #     - ./data/conversation-histories/insurance:/data
  #   healthcheck:
  #     test: ["CMD", "python", "-c",
  #            "import urllib.request; urllib.request.urlopen('http://localhost:8004/.well-known/agent-card.json')"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 5
  #     start_period: 15s
  #   restart: unless-stopped

  # ── Infinithesim A2A sub-agent (DISABLED — code preserved, not started) ──
  # Uncomment to re-enable.
  # infinithesim-agent:
  #   build:
  #     context: .
  #     dockerfile: backend/chanakya/infinithesim/Dockerfile
  #   image: chanakya/infinithesim-agent:latest
  #   environment:
  #     <<: *agent-env
  #     INFINITHESIM_AGENT_HOST: "0.0.0.0"
  #     INFINITHESIM_AGENT_PORT: "8006"
  #     INFINITHESIM_DB_HOST: ${INFINITHESIM_DB_HOST:-localhost}
  #     INFINITHESIM_DB_PORT: ${INFINITHESIM_DB_PORT:-5432}
  #     INFINITHESIM_DB_NAME: ${INFINITHESIM_DB_NAME}
  #     INFINITHESIM_DB_USER: ${INFINITHESIM_DB_USER}
  #     INFINITHESIM_DB_PASSWORD: ${INFINITHESIM_DB_PASSWORD}
  #     INFINITHESIM_SCHEMA_PATH: "/app/backend/chanakya/infinithesim/schema.sql"
  #     PYLOGUE_DB_PATH: "/data/chat_history.db"
  #   ports:
  #     - "${INFINITHESIM_AGENT_PORT:-8006}:8006"
  #   volumes:
  #     - ./data/conversation-histories/infinithesim:/data
  #   healthcheck:
  #     test: ["CMD", "python", "-c",
  #            "import urllib.request; urllib.request.urlopen('http://localhost:8006/.well-known/agent-card.json')"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 5
  #     start_period: 15s
  #   restart: unless-stopped

  # ── Tatasteel A2A sub-agent ──────────────────────────────────────────────
  tatasteel-agent:
    build:
      context: .
      dockerfile: backend/chanakya/tatasteel/Dockerfile
    image: chanakya/tatasteel-agent:latest
    environment:
      <<: *agent-env
      TATASTEEL_AGENT_HOST: "0.0.0.0"
      TATASTEEL_AGENT_PORT: "${TATASTEEL_AGENT_PORT:-7005}"
      TATASTEEL_DB_HOST: ${TATASTEEL_DB_HOST:-db.divami.com}
      TATASTEEL_DB_PORT: ${TATASTEEL_DB_PORT:-5432}
      TATASTEEL_DB_NAME: ${TATASTEEL_DB_NAME}
      TATASTEEL_DB_USER: ${TATASTEEL_DB_USER}
      TATASTEEL_DB_PASSWORD: ${TATASTEEL_DB_PASSWORD}
      TATASTEEL_SCHEMA_PATH: "/app/backend/chanakya/tatasteel/schema.sql"
      PYLOGUE_DB_PATH: "/data/chat_history.db"
    ports:
      - "${TATASTEEL_AGENT_PORT:-7005}:${TATASTEEL_AGENT_PORT:-7005}"
    volumes:
      - ./data/conversation-histories/tatasteel:/data
    healthcheck:
      test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:${TATASTEEL_AGENT_PORT:-7005}/.well-known/agent-card.json')\""]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s
    restart: unless-stopped

  # ── Chanakya A2A server + pylogue chat UI ─────────────────────────────
  # A2A:  POST http://localhost:8010/
  # Chat: GET  http://localhost:8010/chat
  chanakya-ui:
    build:
      context: .
      dockerfile: backend/chanakya/Dockerfile
    image: chanakya/hub:latest
    command:
      - uvicorn
      - backend.chanakya.rt_agent.server:app
      - --host
      - "0.0.0.0"
      - --port
      - "${CHANAKYA_PORT:-7010}"
    environment:
      <<: *agent-env
      TATASTEEL_AGENT_HOST: tatasteel-agent
      TATASTEEL_AGENT_PORT: "${TATASTEEL_AGENT_PORT:-7005}"
      CHANAKYA_PORT: "${CHANAKYA_PORT:-7010}"
      PYLOGUE_DB_PATH: "/data/chat_history.db"
    ports:
      - "${CHANAKYA_PORT:-7010}:${CHANAKYA_PORT:-7010}"
    volumes:
      - ./data/conversation-histories/chanakya:/data
    depends_on:
      tatasteel-agent:
        condition: service_healthy
    restart: unless-stopped

networks:
  default:
    name: chanakya-network
