Skip to content
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
5 changes: 4 additions & 1 deletion examples/agents/bigtable-ai-health-concierge/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ GOOGLE_CALLBACK_URL=http://127.0.0.1:5000/auth/callback
BIGTABLE_INSTANCE_ID=your-bigtable-instance-id

# Google Cloud Model Armor Configuration (Optional)
# MODEL_ARMOR_TEMPLATE_NAME=projects/your-google-cloud-project-id/locations/us-central1/templates/your-template-name
# MODEL_ARMOR_TEMPLATE_NAME=projects/your-google-cloud-project-id/locations/us-central1/templates/your-template-name

# Demo Mode Configuration
USE_DEMO_PATIENT=true
6 changes: 5 additions & 1 deletion examples/agents/bigtable-ai-health-concierge/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ADK Agent Web Chat with Memory Bank
# ADK Agent Web Chat with Bigtable and Memory Bank

This project implements a personalized AI agent using Google Cloud's Agent Development Kit (ADK) and Agent Platform Memory Bank, integrated into a Next.js web application with Google OAuth 2.0 login.

Expand All @@ -25,8 +25,12 @@ GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_CALLBACK_URL=http://127.0.0.1:5000/auth/callback
BIGTABLE_INSTANCE_ID=your-bigtable-instance-id
USE_DEMO_PATIENT=true
```

> [!NOTE]
> Setting **`USE_DEMO_PATIENT=true`** forces the agent to query the default hardcoded demo patient profile (`john.doe@gmail.com`). Set this to `false` in your `.env` file to instruct the agent to dynamically utilize the email address of the logged-in Google OAuth user instead.

### 2. Backend Setup (Flask)

#### 2.1 Set up dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ async def get_profile_info(callback_context: CallbackContext):
"""Returns the patient's demographic information such as age, gender, home zip code, and work zip code to help personalize responses. Use zip codes when searching for nearby medical facilities and pharmacies."""
if callback_context.state.get("_patient_demographics"):
return None
query = f"SELECT profile FROM patients WHERE _key='john.doe@gmail.com'"
patient_key = str(callback_context.session.user_id or "").replace("'", "''")
query = f"SELECT profile FROM patients WHERE _key='{patient_key}'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

Constructing SQL queries using f-strings with user identifiers like patient_key is a security risk (SQL injection). Furthermore, avoid hardcoding or manually passing user identifiers in queries. Instead, use dynamic values from the session or callback context (e.g., callback_context.session.user_id) to ensure the application functions correctly and securely for different users.

References
  1. Avoid hardcoding user identifiers, such as email addresses, in database queries. Instead, use dynamic values from the session or callback context (e.g., callback_context.session.user_id) to ensure the application functions correctly for different users.

res = await query_tool.execute_sql(
project_id=PROJECT_ID,
instance_id=BIGTABLE_INSTANCE_ID,
Expand Down
5 changes: 4 additions & 1 deletion examples/agents/bigtable-ai-health-concierge/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def chat():
message = data.get("message")
user_name = session['name']
#user_id = session['google_id']
user_email = os.getenv("DEMO_PATIENT_EMAIL", "john.doe@gmail.com")
if os.getenv("USE_DEMO_PATIENT", "true").lower() in ["true", "on", "1"]:
user_email = "john.doe@gmail.com"
else:
user_email = session.get('email', "john.doe@gmail.com")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When USE_DEMO_PATIENT is set to false, falling back to the demo email (john.doe@gmail.com) if the session email is missing might be confusing and lead to unexpected behavior. It is safer to handle the missing email case explicitly to ensure the agent uses the correct user identity.

Suggested change
user_email = session.get('email', "john.doe@gmail.com")
user_email = session.get('email')
if not user_email:
return jsonify({"error": "User email not found in session"}), 400

access_token = session.get('access_token')
refresh_token = session.get('refresh_token')

Expand Down
Loading