The app_server.py is a production-ready server that matches the Java AppServer.java implementation with:
- Multiple runner support (PostgresRunner, InMemoryRunner)
- Automatic fallback to InMemoryRunner if database connection fails
- Fast startup (doesn't block on DB connection)
- Config file support (INI format)
- Separate handler file for request processing
# 1. Create config.ini file
cp config.ini.example config.ini
# Edit config.ini with your database URL
# 2. Run server
python -m google.adk.server.app_server [port] [config_path] [environment]Examples:
# Default (port 8000, default config path, production)
python -m google.adk.server.app_server
# Custom port
python -m google.adk.server.app_server 8080
# Custom port and config file
python -m google.adk.server.app_server 8080 /path/to/config.ini
# Custom port, config, and environment
python -m google.adk.server.app_server 8080 /path/to/config.ini development# Set database URL
export DATABASE_URL="postgresql://username:password@hostname:5432/database"
# Run server
python -m google.adk.server.app_serverCreate config.ini:
[default]
runner_type = postgres
database_url = postgresql://postgres:postgres@localhost:5432/adk_db
[production]
database_url = postgresql://username:password@hostname:5432/database
db_schema = your_schema_name
runner_type = postgres
[development]
database_url = postgresql://postgres:postgres@localhost:5432/adk_db_dev
runner_type = inmemory- Uses PostgreSQL for session and memory storage
- Falls back to InMemoryRunner if connection fails
- Configured via
database_urlin config orDATABASE_URLenv var
- Fast startup, no database required
- Good for development/testing
- Data is not persisted (lost on restart)
The server automatically falls back to InMemoryRunner if:
- PostgresRunner fails to initialize
- Database connection fails
- Database URL is not provided
This ensures fast startup even if the database is unavailable.
curl http://localhost:8000/healthResponse:
{
"status": "ok",
"runner_type": "PostgresRunner"
}curl --location 'http://localhost:8000/chat' \
--header 'BUSINESS_UNIT: BUS' \
--header 'COUNTRY: IND' \
--header 'Content-Type: application/json' \
--header 'X-CLIENT: SELF_HELP' \
--data '{
"message": "Hi",
"orderItemUUID": "8dc29a95411be00600ec264701020100"
}'Matching Java AppServer.java:
python -m google.adk.server.app_server [port] [config_path] [environment]
port: Server port (default: 8000)config_path: Path to config.ini file (default:/Users/arun.parmar/go/src/adk-java/core/config.ini)environment: Environment name (default: 'production')
# Production with custom config
python -m google.adk.server.app_server 8000 /path/to/config.ini production
# Development with in-memory runner
python -m google.adk.server.app_server 8000 /path/to/config.ini development
# Test with in-memory (no config needed)
python -m google.adk.server.app_server 8080app_server.py
├── Loads config.ini
├── Initializes agent (GenericOrchestrator.init_agent())
├── Creates runner (with fallback)
└── Starts FastAPI server
server_handler.py
├── handle_chat() - Processes /chat requests
└── handle_health() - Processes /health requests
✅ Multiple Runner Support - PostgresRunner, InMemoryRunner ✅ Automatic Fallback - Fast startup even if DB fails ✅ Config File Support - INI format like Java ✅ Environment Support - Production, development, test ✅ Fast Startup - Non-blocking initialization ✅ Separate Handler - Clean separation of concerns