-
Open the file you want to debug:
src/google/adk/server/server_handler.py -
Set breakpoints by clicking in the gutter (left margin) next to line numbers:
- Click on line 95 (where session handling starts)
- Click on line 97 (get_session call)
- Click on line 110 (create_session call)
- Click on line 123 (run_async call)
-
Start debugging:
- Press
F5or go toRun > Start Debugging - Or use the Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
- Select "Python: App Server" configuration
- Click the green play button
- Press
-
Send a test request:
curl --location 'http://localhost:8080/chat' \ --header 'BUSINESS_UNIT: BUS' \ --header 'COUNTRY: IND' \ --header 'Content-Type: application/json' \ --header 'X-CLIENT: SELF_HELP' \ --data '{"message": "Hi", "orderItemUUID": "8dc29a95411be00600ec264701020100"}'
-
Debug controls:
- F10 - Step Over (execute current line)
- F11 - Step Into (go into function calls)
- Shift+F11 - Step Out (exit current function)
- F5 - Continue (resume execution)
- Shift+F5 - Stop debugging
While debugging, you can:
- Hover over variables to see their values
- Watch specific variables in the Watch panel
- Inspect variables in the Variables panel (left sidebar)
- Evaluate expressions in the Debug Console (bottom panel)
When debugging handle_chat:
body- The request bodysession_id- The session ID (from orderItemUUID)user_message- The user's messageapp_name- Should be "ADK_SUPER_AGENT"user_id- Defaults to "default"initial_state- Contains headers and order infosession- The session object
- Set breakpoint at line 95 (
if session_id:) - Step through to see if
session_idis set correctly - Step into
get_session(F11) to see what happens - Check if exception is caught at line 100
- Set breakpoint at line 123 (
async for event in self.runner.run_async) - Step through to see events being generated
- Check the event structure at line 129
- Set breakpoint in
postgres_session_service.pyat line 147 (stored_session = self._get_session_from_db) - Step into
_get_session_from_dbto see database query - Check for database connection errors
import pdb; pdb.set_trace()Add this line where you want to break:
# In server_handler.py, line 95
session = None
if session_id:
import pdb; pdb.set_trace() # Break here
try:
session = await self.runner.session_service.get_session(...)Run with:
python -m google.adk.server.app_server 8080# In server_handler.py
if session_id:
breakpoint() # Opens debugger
try:
session = await self.runner.session_service.get_session(...)Add detailed logging:
logger.debug('Session ID: %s', session_id)
logger.debug('User ID: %s', user_id)
logger.debug('App Name: %s', app_name)
logger.debug('Initial State: %s', initial_state)Then run with debug logging:
PYTHONPATH=src python -m google.adk.server.app_server 8080 --log-level DEBUGIf you need to debug a running server:
- Install debugpy:
pip install debugpy- Add to your code:
import debugpy
debugpy.listen(5678)
debugpy.wait_for_client() # Optional: wait for debugger to attach- In VS Code, create a "Remote Attach" configuration
-
Use conditional breakpoints: Right-click on breakpoint → Edit Breakpoint → Add condition
- Example:
session_id == "8dc29a95411be00600ec264701020100"
- Example:
-
Use logpoints: Right-click on line → Add Logpoint
- Logs without stopping execution
-
Check the Debug Console: View logs and evaluate expressions while debugging
-
Use the Call Stack: See the sequence of function calls that led to the current point