8000 fix: do not convert "false" value to dict · charsoft/adk-python@60ceea7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60ceea7

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: do not convert "false" value to dict
This causes information loss, and is unexpected from user. PiperOrigin-RevId: 764558190
1 parent b70e74c commit 60ceea7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/google/adk/tools/function_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ async def run_async(
107107
or hasattr(self.func, '__call__')
108108
and inspect.iscoroutinefunction(self.func.__call__)
109109
):
110-
return await self.func(**args_to_call) or {}
110+
return await self.func(**args_to_call)
111111
else:
112-
return self.func(**args_to_call) or {}
112+
return self.func(**args_to_call)
113113

114114
# TODO(hangfei): fix call live for function stream.
115115
async def _call_live(

tests/unittests/tools/test_function_tool.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ def function_for_testing_with_4_arg_and_no_tool_context(arg1, arg2, arg3, arg4):
8686
pass
8787

8888

89+
def function_returning_none() -> None:
90+
"""Function for testing with no return value."""
91+
return None
92+
93+
94+
def function_returning_empty_dict() -> dict[str, str]:
95+
"""Function for testing with empty dict return value."""
96+
return {}
97+
98+
8999
def test_init():
90100
"""Test that the FunctionTool is initialized correctly."""
91101
tool = FunctionTool(function_for_testing_with_no_args)
@@ -94,6 +104,20 @@ def test_init():
94104
assert tool.func == function_for_testing_with_no_args
95105

96106

107+
def test_function_returning_none():
108+
"""Test that the function returns with None actually returning None."""
109+
tool = FunctionTool(function_returning_none)
110+
result = await tool.run_async(args={}, tool_context=MagicMock())
111+
assert result is None
112+
113+
114+
def test_function_returning_empty_dict():
115+
"""Test that the function returns with empty dict actually returning empty dict."""
116+
tool = FunctionTool(function_returning_empty_dict)
117+
result = await tool.run_async(args={}, tool_context=MagicMock())
118+
assert isinstance(result, dict)
119+
120+
97121
@pytest.mark.asyncio
98122
async def test_run_async_with_tool_context_async_func():
99123
"""Test that run_async calls the function with tool_context when tool_context is in signature (async function)."""

0 commit comments

Comments
 (0)
0