adk-samples icon indicating copy to clipboard operation
adk-samples copied to clipboard

Data Science Agent fails - unterminated string literal

Open jainsourabh2 opened this issue 1 year ago • 7 comments

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:

Image

Deployed to Cloud Run as below: sourabhsjain@agents:~/adk-samples/python/agents/data-science$ adk deploy cloud_run --project=<> --region=<> --service_name=nlp2bq-final --with_ui ./data_science/

jainsourabh2 avatar Jul 11 '25 11:07 jainsourabh2

`(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 "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/init.py", line 17, in from . import agent File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/agent.py", line 29, in from .sub_agents import bqml_agent File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/sub_agents/init.py", line 15, in from .bqml.agent import root_agent as bqml_agent File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/sub_agents/bqml/agent.py", line 31, in from data_science.sub_agents.bigquery.agent import database_agent as bq_db_agent File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/sub_agents/bigquery/agent.py", line 23, in from . import tools File "/home/admin_sourabhsjain_altostrat_com/adk-samples/python/agents/data-science/data_science/sub_agents/bigquery/tools.py", line 48 return f"'{value.replace('\', '\\').replace("'", "''")}'" ^ SyntaxError: Fail to load 'data_science' module. unterminated string literal (detected at line 48) INFO: 104.135.200.127:1410 - "GET /apps/data_science/users/user/sessions/062ebd18-fe2e-4895-a74e-39fc6b2acc74 HTTP/1.1" 200 OK INFO: 104.135.200.127:37922 - "GET /debug/trace/session/062ebd18-fe2e-4895-a74e-39fc6b2acc74 HTTP/1.1" 200 OK `

jainsourabh2 avatar Jul 21 '25 10:07 jainsourabh2

I am having the same issue.

Fail to load 'data_science' module. unterminated string literal (detected at line 48) (tools.py, line 48)

leebaro avatar Jul 28 '25 08:07 leebaro

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.

mstyer-google avatar Jul 28 '25 13:07 mstyer-google

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.

mstyer-google avatar Jul 28 '25 16:07 mstyer-google

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

mstyer-google avatar Jul 28 '25 16:07 mstyer-google

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.

mstyer-google avatar Jul 29 '25 08:07 mstyer-google

When I used python 3.12, the problem was solved.

leebaro avatar Aug 07 '25 00:08 leebaro