The application uses ADK, Gemini, LangChain tools to power an SQL Agent.
Frontend: Streamlit app (streamlit_ui.py)
Backend: FastAPI service (main.py)
Agents:
- Coordinator: sql_agent (sql_agent.py)
- Subagents:
- Rephraser agent (rewrite_prompt.py)
- Generator agent (generator.py)
- Analyzer agent (analyzer.py)
- Reflexion agent (reflexion.py)
- Routing agent (routing.py)
Function Tools:
- get_schema tool (db_tools.py)
- run_sql_query tool (db_tools.py)
Models:
- Gemini 2.5 pro
git clone https://github.com/gabrielpreda/adk-sql-agent.git
cd adk-sql-agentThe file should contain the following:
GOOGLE_GENAI_USE_VERTEXAI=TRUE
GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
GOOGLE_CLOUD_LOCATION=YOUR_REGION
Run:
pip install -r requirements.txtRun:
uvicorn main:app --reloadRun:
streamlit run streamlit_ui.pyFrom the root folder run:
adk webThen select the sql_agent folder. ADK web will discover in agent.py the root_agent and you will be able to test, monitor, debug the application.
The Agentic workflow is shown in the following figure (current step: Generator agent receives the result from run_sql_query tool).
The next figure shows the result of Generator Agent.
The next figure shows:
- Result of Analyzer Agent.
- Resolution of the Reflection Agent, based on previous agent analysis.
- The rationale for Routing Agent to route to Rewrite Query Agent.
- The reasoning of Rewrite Query Agent and the new query generated.
Agent Engine is Google Cloud's managed service for deploying ADK agents.
- Google Cloud Project with billing enabled
- gcloud CLI installed and configured
- ADK CLI version 1.3.0+
- Set your project ID and region:
export GOOGLE_CLOUD_PROJECT=your-project-id
export GOOGLE_CLOUD_LOCATION=us-central1- Run the deployment script:
./deploy.sh- Test your deployed agent:
adk run --project=$GOOGLE_CLOUD_PROJECT --region=$GOOGLE_CLOUD_LOCATION --agent=adk-sql-agentAlternative deployment using Google Cloud Run for broader region availability.
- Set your project ID and region:
export GOOGLE_CLOUD_PROJECT=your-project-id
export GOOGLE_CLOUD_LOCATION=us-central1- Run the Cloud Run deployment script:
./deploy_cloudrun.sh- The script will output your service URL. Test it:
# Check status
curl https://your-service-url/status
# Send a query
curl -X POST https://your-service-url/query \
-H 'Content-Type: application/json' \
-d '{"query": "Show me the top 10 customers"}'If you prefer manual deployment:
# Build container
gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/adk-sql-agent
# Deploy to Cloud Run
gcloud run deploy adk-sql-agent \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/adk-sql-agent \
--platform managed \
--region $GOOGLE_CLOUD_LOCATION \
--allow-unauthenticated \
--set-env-vars GOOGLE_GENAI_USE_VERTEXAI=TRUE \
--set-env-vars GOOGLE_CLOUD_PROJECT=$GOOGLE_CLOUD_PROJECT \
--set-env-vars GOOGLE_CLOUD_LOCATION=$GOOGLE_CLOUD_LOCATION \
--memory 4Gi \
--cpu 2We show here the sequence of operations for one query.







