Skip to content

Conversation

omarcevi
Copy link

@omarcevi omarcevi commented Sep 28, 2025

fix: #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

- 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
Copy link

Summary of Changes

Hello @omarcevi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where FunctionTool was failing to pass parameters correctly to functions that accept arbitrary keyword arguments (**kwargs), particularly affecting 'CrewAI-style' tools. The change modifies the run_async method to intelligently detect **kwargs in a function's signature and adjust parameter passing to include all relevant arguments, while still excluding internal parameters like 'self' and 'tool_context'. This fix ensures that tools relying on dynamic keyword arguments function as expected, resolving cases where parameters like 'search_query' were incorrectly received as None.

Highlights

  • Improved Parameter Filtering: The FunctionTool's parameter filtering logic has been enhanced to correctly handle functions that utilize **kwargs (keyword arguments).
  • Support for **kwargs Functions: Functions defined with **kwargs will now receive all provided parameters, with the exception of 'self' and 'tool_context', ensuring compatibility with dynamic tool patterns like those found in CrewAI.
  • Backward Compatibility: The update maintains full backward compatibility, meaning functions with explicitly defined parameters will continue to filter arguments based on their signature, as before.
  • Comprehensive Testing: New tests have been added to cover both synchronous and asynchronous **kwargs functions, as well as to explicitly verify that backward compatibility for explicit parameter functions is preserved.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot
Copy link
Collaborator

adk-bot commented Sep 28, 2025

Hello @omarcevi, thank you for your contribution!

To help us review this PR, could you please:

  1. Associate a GitHub issue with this PR. If one doesn't exist, please create one.
  2. Add a Testing Plan section to your PR description explaining how you tested these changes.
  3. Include a summary of the passed pytest results.

This information will help the reviewers to review your PR more efficiently. Thanks!

Response from ADK Triaging Agent

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to improve parameter filtering for functions with **kwargs, which is a valuable addition. However, the current implementation introduces a critical bug: if a function's signature contains both an explicit tool_context parameter and **kwargs, the logic incorrectly removes the tool_context before the function call, which would cause a TypeError. I have provided a detailed comment and a code suggestion in function_tool.py to correct this. Additionally, while the new tests are a good start, they do not cover this specific failing edge case. I've added another comment in the test file recommending a new test case to ensure the fix is validated and to prevent future regressions.

@omarcevi omarcevi changed the title fix: improve parameter filtering for functions with **kwargs fix: #3036 improve parameter filtering for functions with **kwargs Sep 28, 2025
@adk-bot adk-bot added bot triaged [Bot] This issue is triaged by ADK bot tools [Component] This issue is related to tools labels Sep 28, 2025
- Fix critical bug where tool_context was being removed for functions with both explicit tool_context and **kwargs
- Start with original args instead of args_to_call to avoid removing injected tool_context
- Re-inject tool_context only if it's an explicit parameter in the function signature
- Add comprehensive tests for edge case: functions with both tool_context and **kwargs
- Maintains all existing functionality while fixing the TypeError issue

This fixes the scenario where functions like:
def my_func(tool_context: ToolContext, **kwargs):
would fail with TypeError due to missing tool_context argument.

#non-breaking
@omarcevi
Copy link
Author

Hey @seanzhou1023 i was wondering when youll be available to review this? this fixes the issues with adk not working with crewai components

@omarcevi omarcevi changed the title fix: #3036 improve parameter filtering for functions with **kwargs fix: #3036 improve parameter filtering for CrewAI functions with **kwargs Sep 29, 2025
@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of parameter filtering for CrewAI-style tools that use **kwargs. The logic change correctly passes all necessary arguments to these functions while maintaining backward compatibility. The addition of comprehensive unit tests is also excellent, ensuring the new functionality is well-covered.

My review includes a couple of suggestions to improve the code's maintainability: one to simplify the argument filtering logic in function_tool.py and another to reduce code duplication in the new tests by using a pytest fixture. Overall, this is a solid fix.

…and updating tests with mock ToolContext

- Updated FunctionTool to defensively remove 'self' from arguments when handling **kwargs.
- Refactored tests to utilize a mock ToolContext for better isolation and clarity.
- Ensured backward compatibility with existing functionality while enhancing test coverage. #non-breaking
@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an issue with parameter filtering for functions that use **kwargs, ensuring compatibility with CrewAI-style tools. The implementation correctly passes all arguments to functions with **kwargs while preserving the original filtering behavior for functions with explicit parameters, thus maintaining backward compatibility. The accompanying tests are comprehensive, covering synchronous and asynchronous functions, backward compatibility, and edge cases with tool_context. I have one minor suggestion to improve a code comment for better clarity and long-term maintainability.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the parameter filtering issue for CrewAI-style functions that use **kwargs. The implementation in function_tool.py is clean, correctly identifying functions with **kwargs and passing arguments appropriately, while ensuring backward compatibility for functions with explicit parameters. The accompanying tests are comprehensive, covering various scenarios like sync/async functions and the interaction with tool_context. My feedback includes suggestions to refactor the new tests to reduce code duplication, which will enhance their long-term maintainability.

…ext handling

- Introduced synchronous and asynchronous CrewAI-style tools for testing.
- Refactored tests to utilize parameterized inputs for better coverage of **kwargs handling.
- Ensured both synchronous and asynchronous functions are tested with tool_context and **kwargs.
- Improved clarity and maintainability of test cases while preserving existing functionality. #non-breaking
@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a great improvement by adding support for CrewAI-style tool functions that use **kwargs, enhancing flexibility. The change correctly identifies functions with **kwargs and avoids filtering their arguments, while maintaining backward compatibility for functions with explicit parameters. The accompanying tests are comprehensive and cover the new functionality well.

My main feedback is regarding a subtle issue in the handling of the tool_context parameter for functions with **kwargs. The implementation doesn't fully match the PR description, potentially allowing tool_context from the args dictionary to be passed through, which could lead to unexpected behavior. I've provided a suggestion to align the code with the intended logic and recommended an additional test case.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the FunctionTool class to correctly handle functions that accept **kwargs, addressing an issue where such functions would receive empty parameter dictionaries. The changes include modifications to the run_async method to detect and appropriately pass arguments to functions with **kwargs, along with the addition of comprehensive tests to ensure the new functionality works as expected and maintains backward compatibility. The code changes look good and the tests are comprehensive.

- Added an assertion to ensure that unexpected parameters are filtered out and not passed to the function in the test for backward compatibility with **kwargs.
- This enhancement improves the robustness of the tests by explicitly checking for parameter handling. #non-breaking
@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses an issue with parameter filtering for functions that use **kwargs, a pattern common in frameworks like CrewAI. The implementation correctly identifies functions with **kwargs and ensures all relevant arguments are passed, while also preserving backward compatibility for functions with explicitly defined parameters. The accompanying tests are comprehensive, covering synchronous and asynchronous cases, backward compatibility, and interactions with tool_context. My feedback includes a suggestion to refactor a logic block for improved clarity and a minor cleanup in the test suite to remove a redundant assertion. Overall, this is a solid contribution that enhances the tool's flexibility.

@omarcevi
Copy link
Author

omarcevi commented Oct 2, 2025

@seanzhou1023 Hello any chance you can review this? :)

@omarcevi
Copy link
Author

omarcevi commented Oct 4, 2025

Hey @seanzhougoogle , :)

please let me know if anything is missing here. without this fix users cant work with crew ai tools with adk. made sure to also test for backwards compatibility. glad to help if there are any edits necessary here.

im including screen shots of the test results:
image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot triaged [Bot] This issue is triaged by ADK bot tools [Component] This issue is related to tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FunctionTool parameter filtering breaks CrewAI-style tools with **kwargs
3 participants