Skip to content

Phase 2 + 3 from Google Jules #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Environment variables for the Backend Service

# -- Database Configuration (Supabase PostgreSQL) --
# Format: postgresql://postgres:[YOUR-PASSWORD]@[AWS-REGION].pooler.supabase.com:6543/postgres
SUPABASE_DATABASE_URL="postgresql://postgres:[email protected]:6543/postgres"

# -- OpenAI Configuration --
OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# -- Service Security Note --
# Client authentication is handled by an upstream Supabase Edge Function (`auth-gateway`).
# Refer to `backend/docs/supabase_edge_functions.md` for details.

# -- Tool Credentials (Example) --
MOCK_WEATHER_TOOL_API_KEY="test_weather_key"

# -- Logging Configuration --
# LOG_LEVEL="INFO" # Optional: DEBUG, INFO, WARNING, ERROR, CRITICAL. Defaults to INFO.

# -- OpenTelemetry Configuration --
# Endpoint for the OTLP collector (e.g., Jaeger, Grafana Tempo, OpenTelemetry Collector).
# For HTTP exporter, typically ends with /v1/traces.
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318/v1/traces"
# Service name to identify this backend in traces.
OTEL_SERVICE_NAME="ai_assistant_backend"
# Optional: Set to "true" to print traces to console (for debugging, very verbose)
# OTEL_EXPORTER_OTLP_TRACES_EXPORTER="console"

# -- Optional: Agent Behavior --
# DEFAULT_AGENT_PERSONA_NAME="greeter"

# -- Optional: Uvicorn/FastAPI settings --
# HOST="0.0.0.0"
# PORT="8000"
# WORKERS="4"

# Note:
# - Rename this file to .env and fill in your actual values.
# - Add .env to your .gitignore file.
# - For testing, consider a separate .env.test file.
47 changes: 47 additions & 0 deletions backend/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Local Docker Development Environment Variables for the Backend Service
# Rename this to .env.local (or a name referenced in docker-compose.yml)

# --- Database Configuration ---
# For local development with Docker Compose, you might connect to:
# 1. A cloud-hosted Supabase instance (recommended for ease).
# 2. A local Supabase instance running via its own Docker setup (more complex, see Supabase docs).
# 3. A standard PostgreSQL container (if not using Supabase-specific features heavily during dev).

# Option 1: Connect to your cloud Supabase instance (most common for dev)
# Replace with your actual Supabase project's connection string.
SUPABASE_DATABASE_URL="postgresql://postgres:[email protected]:6543/postgres"

# Option 2: Example if Supabase was running locally via Docker on default port 5432
# This assumes the backend service can reach the Supabase stack on 'host.docker.internal' (from Docker Desktop)
# or a specific service name if part of the same docker-compose network.
# SUPABASE_DATABASE_URL="postgresql://postgres:[email protected]:5432/postgres"
# Or if 'supabase_db' was a service name in docker-compose:
# SUPABASE_DATABASE_URL="postgresql://postgres:your-local-supabase-password@supabase_db:5432/postgres"


# --- OpenAI Configuration ---
# Your API key for OpenAI services.
# It's recommended to use a development-specific key if possible.
OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"


# --- Tool Credentials (Example) ---
# API key for the mock weather tool.
MOCK_WEATHER_TOOL_API_KEY="test_weather_key"


# --- Logging Configuration ---
# Optional: Set the log level for the application (DEBUG, INFO, WARNING, ERROR, CRITICAL).
# Defaults to INFO if not set in the application.
LOG_LEVEL="DEBUG" # Often useful for local development


# --- Mock A2A Server URL (if needed by backend to know its own mock's URL, usually not) ---
# Generally, the A2A service discovers other agents. If the backend needs to point to the
# mock A2A server for some reason (e.g., if an agent definition card in the backend
# explicitly needs to point to the mock server by its Docker service name), you might add:
# MOCK_A2A_SERVER_BASE_URL="http://mock_a2a_server:8001"
# However, MOCK_AGENT_CARDS in a2a_communication_service.py already has http://localhost:8001,
# which works when all services are mapped to localhost ports. If running purely container-to-container,
# then service names would be used.
```
34 changes: 34 additions & 0 deletions backend/.env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Example .env.test file for configuring tests
# Rename this to .env.test and fill in actual values if needed for your test environment.
# python-dotenv (if used in your test setup) can load this file.

# --- OpenAI API Key ---
# For running integration tests that might make real calls to OpenAI (if not mocked).
# Most unit/integration tests in this project mock the OpenAI client.
# OPENAI_API_KEY="sk-your_actual_openai_api_key_for_testing"

# --- Supabase Database URL for Integration Testing ---
# Optional: If you want to run integration tests (`test_conversation_flow.py`, `test_a2a_flow.py`)
# against a real Supabase PostgreSQL instance instead of the default SQLite.
# The tests are configured to use this environment variable if set.
# Format: postgresql://postgres:[YOUR-PASSWORD]@[AWS-REGION].pooler.supabase.com:6543/postgres
# TEST_SUPABASE_DATABASE_URL="postgresql://postgres:[email protected]:6543/postgres"

# --- Logging Level for Tests ---
# Optional: Set the log level for test runs (e.g., DEBUG, INFO, WARNING).
# The application's logging_config.py will use this if set.
# LOG_LEVEL="DEBUG"

# --- Authentication Note for Backend Tests ---
# The backend's AG-UI endpoint now expects an "X-Auth-Validation-Status: success" header,
# which is assumed to be set by an upstream Supabase Edge Function that validates the original
# client's X-API-KEY.
# Therefore, `EXPECTED_API_KEY` is NO LONGER configured directly in the backend's .env file
# for runtime. For tests that hit these protected endpoints (like integration tests),
# the test client directly sets the "X-Auth-Validation-Status: success" header.
# The Supabase Edge Function itself would need an `EXPECTED_API_KEY_SECRET` configured in its own environment.

# --- Other Test-Specific Settings ---
# If your agent personas or other services load config from env vars for testing:
# AGENT_PERSONA_DEFAULT_NAME="testGreeter"
# MOCK_A2A_SERVER_URL="http://localhost:8001" # If the mock A2A server URL needs to be configurable for tests
42 changes: 42 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Use an official Python runtime as a parent image
FROM python:3.11-slim

# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Install system dependencies that might be needed by Python packages
# Example: psycopg2 might need libpq-dev if not using the binary version
# RUN apt-get update && apt-get install -y --no-install-recommends \
# build-essential \
# libpq-dev \
# && rm -rf /var/lib/apt/lists/*

# Copy the requirements file into the container at /app
COPY requirements.txt .

# Install Python dependencies
# --no-cache-dir: Disables the pip cache, reducing image size.
# --upgrade pip: Ensures pip is up-to-date.
RUN pip install --no-cache-dir --upgrade pip -r requirements.txt

# Copy the rest of the backend application code into the container at /app
# This includes all subdirectories like services, routers, models, etc.
COPY . .

# Expose the port the app runs on
# This should match the port Uvicorn is configured to use.
EXPOSE 8000

# Define the command to run the application
# Use 0.0.0.0 to make the server accessible externally (from outside the container).
# The --reload flag is typically for development; for production, you might remove it
# or control it via an environment variable (e.g., APP_ENV=development).
# For this Dockerfile, we'll include --reload for easier dev with docker-compose volume mounts.
# If you want a production-ready image, create a separate Dockerfile or use multi-stage builds
# to remove dev dependencies and disable reload.
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
```
Loading