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
11 changes: 9 additions & 2 deletions src/google/adk/tools/skill_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,13 @@ async def execute_script_async(
stdout = parsed.get("stdout", "")
stderr = parsed.get("stderr", "")
rc = parsed.get("returncode", 0)
if rc != 0 and not stderr:
stderr = f"Exit code {rc}"
if rc != 0:
exit_code_message = f"Exit code {rc}"
stderr = (
f"{stderr.rstrip()}\n{exit_code_message}"
if stderr
else exit_code_message
)
except (json.JSONDecodeError, ValueError):
pass

Expand Down Expand Up @@ -745,6 +750,8 @@ def _build_wrapper_code(
" _r = subprocess.run(",
f" {arr!r},",
" capture_output=True, text=True,",
# Keep shell output decoding independent from the host locale.
" encoding='utf-8', errors='replace',",
f" timeout={timeout!r}, cwd=td,",
" )",
" print(_json.dumps({",
Expand Down
2 changes: 2 additions & 0 deletions tests/unittests/tools/test_skill_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ async def test_execute_script_shell_success(mock_skill1):
code_input = call_args[0][1]
assert "subprocess.run" in code_input.code
assert "bash" in code_input.code
assert "encoding='utf-8'" in code_input.code
assert "errors='replace'" in code_input.code
assert "__shell_result__" in code_input.code


Expand Down