Data Science Agent fails - unterminated string literal
When I deployed the Data science agent with the latest changes on cloud run, the deployment succeeds but I am not able to interact with the agent. I am getting below error:
Deployed to Cloud Run as below:
sourabhsjain@agents:~/adk-samples/python/agents/data-science$ adk deploy cloud_run --project=<
`(venv) admin_sourabhsjain_altostrat_com@demo:~/adk-samples/python/agents/data-science$ adk web --host 0.0.0.0 INFO: Started server process [796080] INFO: Waiting for application startup.
+-----------------------------------------------------------------------------+ | ADK Web Server started | | | | For local testing, access at http://localhost:8000. | +-----------------------------------------------------------------------------+
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: 104.135.200.127:1410 - "GET / HTTP/1.1" 307 Temporary Redirect
INFO: 104.135.200.127:1410 - "GET /dev-ui/ HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "GET /dev-ui/main-JAAWEV7F.js HTTP/1.1" 200 OK
INFO: 104.135.200.127:3159 - "GET /dev-ui/polyfills-B6TNHZQ6.js HTTP/1.1" 200 OK
INFO: 104.135.200.127:37922 - "GET /dev-ui/styles-4VDSPQ37.css HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "GET /dev-ui/assets/config/runtime-config.json HTTP/1.1" 200 OK
INFO: 104.135.200.127:37922 - "GET /dev-ui/assets/ADK-512-color.svg HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "GET /list-apps?relative_path=./ HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "GET /dev-ui/adk_favicon.svg HTTP/1.1" 200 OK
2025-07-21 10:06:21,674 - INFO - fast_api.py:445 - New session created
INFO: 104.135.200.127:1410 - "POST /apps/data_science/users/user/sessions HTTP/1.1" 200 OK
INFO: 104.135.200.127:3159 - "GET /apps/data_science/eval_results HTTP/1.1" 200 OK
INFO: 104.135.200.127:37922 - "GET /apps/data_science/eval_sets HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "GET /apps/data_science/users/user/sessions HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "GET /apps/data_science/users/user/sessions HTTP/1.1" 200 OK
INFO: 104.135.200.127:1410 - "POST /run_sse HTTP/1.1" 200 OK
2025-07-21 10:06:24,221 - INFO - envs.py:47 - Loaded .env file for data_science at /home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/.env
2025-07-21 10:06:24,223 - INFO - envs.py:47 - Loaded .env file for data_science at /home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/.env
2025-07-21 10:06:24,256 - ERROR - fast_api.py:820 - Error in event_generator: Fail to load 'data_science' module. unterminated string literal (detected at line 48) (tools.py, line 48)
Traceback (most recent call last):
File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/venv/lib/python3.11/site-packages/google/adk/cli/fast_api.py", line 808, in event_generator
runner = await _get_runner_async(req.app_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/venv/lib/python3.11/site-packages/google/adk/cli/fast_api.py", line 953, in _get_runner_async
root_agent = agent_loader.load_agent(app_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/venv/lib/python3.11/site-packages/google/adk/cli/utils/agent_loader.py", line 164, in load_agent
agent = self._perform_load(agent_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/venv/lib/python3.11/site-packages/google/adk/cli/utils/agent_loader.py", line 142, in _perform_load
if root_agent := self._load_from_module_or_package(agent_name):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/venv/lib/python3.11/site-packages/google/adk/cli/utils/agent_loader.py", line 81, in _load_from_module_or_package
raise e
File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/venv/lib/python3.11/site-packages/google/adk/cli/utils/agent_loader.py", line 53, in _load_from_module_or_package
module_candidate = importlib.import_module(agent_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "
I am having the same issue.
Fail to load 'data_science' module. unterminated string literal (detected at line 48) (tools.py, line 48)
If you're experiencing this issue, please check that you have cloned the most recent version of the repo.
The error message above reports the problematic line as
return f"'{value.replace('\', '\\').replace("'", "''")}'".
In the latest version of the agent, however, line 48 of sub_agents/bigquery/tools.py is:
return f"'{value.replace('\\', '\\\\').replace("'", "''")}'"
Note the two extra backslashes in the first replace(...) call.
Just did a little more digging (thanks to @jainsourabh2). The code in question was introduced in PR #246. That code depends on Python 3.12, but it looks like adk deploy cloud_run uses a Python 3.11 base container image.
I filed an issue with adk-python about the Python version in the adk deploy cloud_run base container: https://github.com/google/adk-python/issues/2219
For the record, this should not be true of Agent Engine deployments. When deploying to Agent Engine, the aiplatform SDK creates the package spec using the Python system version it detected running in the local environment:
https://github.com/googleapis/python-aiplatform/blob/4fcfcb98a4225e9853fcee1de704f7d7bd2626e9/vertexai/agent_engines/_agent_engines.py#L487
So if you're running your local deployment code in a Python 3.12 virtual env, that will be picked up and used to package the AE deployment as well.
When I used python 3.12, the problem was solved.