This guide explains how to properly configure environment variables for PolyAgent's Docker Compose deployment.
- Overview
- Environment Variable Loading
- Required Configuration
- Common Issues and Solutions
- Best Practices
PolyAgent uses environment variables for sensitive configuration like API keys, service endpoints, and feature flags. Proper configuration is essential for the platform to function correctly.
Docker Compose loads environment variables in this order of precedence:
- Shell environment variables (highest priority)
.envfile in the docker-compose directoryenv_filedirective in docker-compose.ymlenvironmentsection in docker-compose.yml (lowest priority)
Create .env in the project root by copying the example:
cp .env.example .env
# Edit .env with your actual API keysDocker Compose looks for .env in the same directory as the docker-compose.yml file:
cd deploy/compose
ln -sf ../../.env .envThis symlink ensures Docker Compose can find your environment variables.
Test that your environment variables are loaded correctly:
# From project root
docker compose -f deploy/compose/docker-compose.yml config | grep EXA_API_KEY
# Check inside running container
docker compose -f deploy/compose/docker-compose.yml exec llm-service env | grep EXA# LLM Provider Keys (at least one required)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
# Web Search (optional but recommended)
EXA_API_KEY=your-exa-key-here
FIRECRAWL_API_KEY=your-firecrawl-key-here
# Model Selection (optional)
COMPLEXITY_MODEL_ID=gpt-4o-mini
DECOMPOSITION_MODEL_ID=gpt-4o# Token Budget (optional)
WORKFLOW_SYNTH_BYPASS_SINGLE=true
# Rate Limiting (optional)
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_INTERVAL_MS=60000Symptom: Error message in agent execution:
Error: No web search provider configured. Please set one of:
- EXA_API_KEY environment variable for Exa search
- FIRECRAWL_API_KEY environment variable for Firecrawl search
Solution:
- Ensure
.envfile contains the API keys - Create the symlink:
cd deploy/compose && ln -sf ../../.env .env - Restart services:
docker compose -f deploy/compose/docker-compose.yml up -d
Symptom: Warnings like:
level=warning msg="The \"EXA_API_KEY\" variable is not set. Defaulting to a blank string."
Solution: These warnings appear during the build phase when Docker Compose evaluates the docker-compose.yml file. They can be safely ignored if:
- The symlink exists (
deploy/compose/.env -> ../../.env) - The variables are correctly set inside the container (verify with
docker compose exec llm-service env)
Symptom: "Rate limit exceeded" errors when multiple agents run in parallel
Solution: This is now fixed in the codebase (rate limiting is per-session, not global). If you still see issues:
- Check the rate limit configuration in your tools
- Ensure you're using the latest code version
- Keep
.envin.gitignore - Use
.env.exampleas a template with placeholder values - Store production secrets in a secure vault
- Use UPPER_CASE_WITH_UNDERSCORES for environment variables
- Prefix service-specific variables (e.g.,
LLM_SERVICE_URL)
- Maintain
.env.examplewith all required variables - Include descriptions as comments
- Specify which variables are optional vs required
Services should validate required environment variables on startup:
# Example in Python service
import os
import sys
required_vars = ["OPENAI_API_KEY", "REDIS_HOST"]
missing = [var for var in required_vars if not os.getenv(var)]
if missing:
print(f"Missing required environment variables: {missing}")
sys.exit(1)For different environments:
.env.development
.env.staging
.env.productionLoad the appropriate file:
# Development
ln -sf ../../.env.development deploy/compose/.env
# Production
ln -sf ../../.env.production deploy/compose/.envAdd these helpful commands to your Makefile:
# Setup environment
.PHONY: setup-env
setup-env:
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "Created .env file - please edit with your API keys"; \
fi
@cd deploy/compose && ln -sf ../../.env .env
@echo "Environment setup complete"
# Validate environment
.PHONY: check-env
check-env:
@echo "Checking environment configuration..."
@docker compose -f deploy/compose/docker-compose.yml config > /dev/null 2>&1
@docker compose -f deploy/compose/docker-compose.yml exec llm-service env | grep -q EXA_API_KEY || \
echo "Warning: EXA_API_KEY not set in container"
@echo "Environment check complete"# Check if .env file exists
ls -la .env deploy/compose/.env
# View current environment in container
docker compose -f deploy/compose/docker-compose.yml exec llm-service env | sort
# Test with explicit env file
docker compose --env-file .env -f deploy/compose/docker-compose.yml up -d
# Export shell variables (temporary, for testing)
export $(grep -v '^#' .env | xargs)
docker compose -f deploy/compose/docker-compose.yml up -d- Always create the symlink:
cd deploy/compose && ln -sf ../../.env .env - Verify variables are loaded: Check inside the container, not just docker-compose output
- Keep secrets secure: Never commit actual API keys to the repository
- Document requirements: Maintain clear documentation of required variables
Following these guidelines will prevent environment configuration issues and ensure smooth deployment of the PolyAgent platform.