examples/integration-google-adk/README.md
This example demonstrates how to test Google Agent Development Kit (ADK) agents using promptfoo. It shows both single-turn and multi-turn conversation patterns with automatic session management.
You can run this example with:
npx promptfoo@latest init --example integration-google-adk
cd integration-google-adk
get_weather toolpip install google-adk
Get a Google API key from the Google AI Studio and set it as an environment variable:
export GOOGLE_API_KEY="your-google-api-key-here"
pip install -r requirements.txt
Note: The session management is now handled entirely in JavaScript using Node.js native fetch, eliminating the need for additional Python HTTP libraries.
From this directory, run:
export GOOGLE_API_KEY="your-api-key-here"
adk api_server
You should see output like:
INFO: Started server process [12345]
INFO: Application startup complete.
INFO: Uvicorn running on http://localhost:8000
Keep this server running in one terminal.
In a new terminal, choose either:
Single-turn testing (isolated sessions):
promptfoo eval -c promptfooconfig-single-turn.yaml
Multi-turn testing (shared conversation):
promptfoo eval -c promptfooconfig-multi-turn.yaml --max-concurrency 1
Both configurations will:
Single-turn - Each test uses a separate session:
✅ Weather query for New York
✅ Weather query for London (independent session)
✅ Context isolation test: "I don't have memory of previous conversations"
Pass Rate: 100% (demonstrates session isolation)
Multi-turn - All tests share one session:
✅ Initial weather query
✅ Follow-up weather query
✅ Memory test: "Comparing New York (sunny, 72°F) vs London (cloudy, 58°F)"
Pass Rate: 100% (demonstrates conversation memory)
This example follows the official ADK pattern:
weather_agent/agent.py)from google.adk.agents import Agent
def get_weather(city: str) -> dict:
# Mock weather function - replace with real API in production
return {"status": "success", "report": "..."}
root_agent = Agent(
name="weather_agent",
model="gemini-2.5-flash", # Real Gemini 2.5 Flash model
description="Agent to answer questions about weather in various cities",
instruction="You are a helpful weather assistant...",
tools=[get_weather]
)
adk-session-hook.js: Session management using Node.js native fetchadk-response-transform.js: Extracts text responses from ADK's event-based formatweather_agent/: The actual ADK agent code (Python)ADK sessions are stateful conversation contexts that maintain memory between interactions. This is crucial for building conversational agents.
Sessions follow this hierarchy:
/apps/{app_name}/users/{user_id}/sessions/{session_id}
app_name: Your agent (e.g., weather_agent)user_id: User identifier (e.g., test_user)session_id: Conversation thread (e.g., session_shared)Multi-turn (Shared Session):
# promptfooconfig-multi-turn.yaml
body:
session_id: 'conversation' # Same for all tests
Benefits: Agent remembers context across tests Use case: Testing conversational flow and memory
Single-turn (Separate Sessions):
# promptfooconfig-single-turn.yaml
vars:
session_id: 'session_ny' # Different per test
body:
session_id: '{{session_id}}'
Benefits: Complete isolation, no test interference Use case: Independent validation scenarios
Our example uses automatic session management:
beforeAll hook creates session before testsafterAll hook removes session after testsTo change session strategy, modify the session hook or use test-specific session IDs.
Authentication errors:
export GOOGLE_API_KEY="your-key-from-ai-google-dev"
500 Internal Server Error:
"Agent not found" error: Make sure the ADK server can find the weather_agent directory