mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: #3036 parameter filtering for CrewAI functions with **kwargs
Merge https://github.com/google/adk-python/pull/3037 fix: [#3036](https://github.com/google/adk-python/issues/3036) - Fix FunctionTool parameter filtering to support CrewAI-style tools - Functions with **kwargs now receive all parameters except 'self' and 'tool_context' - Maintains backward compatibility with explicit parameter functions - Add comprehensive tests for **kwargs functionality Fixes parameter filtering issue where CrewAI tools using **kwargs pattern would receive empty parameter dictionaries, causing search_query and other parameters to be None. #non-breaking COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3037 from omarcevi:fix/function-tool-kwargs-parameter-filtering 012bbfcfd68e83a29635ac74718a1bd1323c5187 PiperOrigin-RevId: 825275686
This commit is contained in:
committed by
Copybara-Service
parent
15afbcd158
commit
74a3500fc5
@@ -22,6 +22,15 @@ from google.adk.tools.tool_context import ToolContext
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_tool_context() -> ToolContext:
|
||||
"""Fixture that provides a mock ToolContext for testing."""
|
||||
mock_invocation_context = MagicMock(spec=InvocationContext)
|
||||
mock_invocation_context.session = MagicMock(spec=Session)
|
||||
mock_invocation_context.session.state = MagicMock()
|
||||
return ToolContext(invocation_context=mock_invocation_context)
|
||||
|
||||
|
||||
def function_for_testing_with_no_args():
|
||||
"""Function for testing with no args."""
|
||||
pass
|
||||
@@ -394,3 +403,28 @@ async def test_run_async_with_require_confirmation():
|
||||
tool_context=tool_context_mock,
|
||||
)
|
||||
assert result == {"received_arg": "hello"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_async_parameter_filtering(mock_tool_context):
|
||||
"""Test that parameter filtering works correctly for functions with explicit parameters."""
|
||||
|
||||
def explicit_params_func(arg1: str, arg2: int):
|
||||
"""Function with explicit parameters (no **kwargs)."""
|
||||
return {"arg1": arg1, "arg2": arg2}
|
||||
|
||||
tool = FunctionTool(explicit_params_func)
|
||||
|
||||
# Test that unexpected parameters are still filtered out for non-kwargs functions
|
||||
result = await tool.run_async(
|
||||
args={
|
||||
"arg1": "test",
|
||||
"arg2": 42,
|
||||
"unexpected_param": "should_be_filtered",
|
||||
},
|
||||
tool_context=mock_tool_context,
|
||||
)
|
||||
|
||||
assert result == {"arg1": "test", "arg2": 42}
|
||||
# Explicitly verify that unexpected_param was filtered out and not passed to the function
|
||||
assert "unexpected_param" not in result
|
||||
|
||||
Reference in New Issue
Block a user