-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add wrapper for griptape tool #2799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @zachgiordano, 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 introduces a new GriptapeTool wrapper, enabling seamless integration of Griptape's robust tool ecosystem into the existing framework. This allows the system to leverage Griptape's pre-built tools for various tasks by converting their activity methods into a compatible format for generative AI function calling.
Highlights
- New Griptape Tool Wrapper: Introduces GriptapeTool, an adapter class that allows integrating Griptape BaseTool instances with the ADK's generative AI function calling interface.
- Dynamic Method Wrapping: The GriptapeTool dynamically wraps Griptape's @activity methods, parsing their schemas to correctly map parameters for ADK compatibility.
- Dependency Update: Adds griptape>=1.8.2 as a new dependency in pyproject.toml for both testing and extensions.
- Comprehensive Testing: Includes new unit tests (test_griptape_tool.py) to ensure proper initialization, function declaration generation, and execution of wrapped Griptape tools with various schemas.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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
-
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. ↩
Hello @zachgiordano, thank you for creating this PR! This PR is a new feature, could you please associate a GitHub issue with this PR? If there is no existing issue, could you please create one? In addition, could you please include a This information will help reviewers to review your PR more efficiently. Thanks! Response from ADK Triaging Agent |
There was a problem hiding this 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 wrapper for Griptape tools, allowing them to be used within the ADK framework. The changes include adding the griptape
dependency, implementing the GriptapeTool
wrapper class, and providing unit tests. The implementation is mostly solid, but I have identified a few areas for improvement regarding type safety, exception handling, and a functional limitation in the configuration-based setup that prevents selecting a specific tool activity when multiple are present. My feedback includes suggestions to address these points to make the wrapper more robust and flexible.
def from_config( | ||
cls: type[GriptapeTool], config: ToolArgsConfig, config_abs_path: str | ||
) -> GriptapeTool: | ||
from ..agents import config_agent_utils | ||
|
||
griptape_tool_config = GriptapeToolConfig.model_validate( | ||
config.model_dump() | ||
) | ||
tool = config_agent_utils.resolve_fully_qualified_name( | ||
griptape_tool_config.tool | ||
) | ||
name = griptape_tool_config.name | ||
description = griptape_tool_config.description | ||
return cls(tool, name=name, description=description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation of from_config
and GriptapeToolConfig
does not allow specifying the activity_method
from the configuration. If a Griptape tool has multiple @activity
decorated methods, this wrapper will always select the first one it finds, which is a significant limitation.
To provide more flexibility, I recommend the following changes:
- Add an optional
activity_method: Optional[str] = None
field to theGriptapeToolConfig
class. - Update this
from_config
method to read theactivity_method
from the config and pass it to theGriptapeTool
constructor.
_griptape_tool: Any | ||
"""The wrapped griptape tool.""" | ||
|
||
def __init__( | ||
self, | ||
tool: Any, | ||
activity_method: Optional[str] = None, | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hints for _griptape_tool
and the tool
parameter in __init__
are Any
. Since the code expects and validates that the tool is a GriptapeBaseTool
, using this more specific type in the hints would improve type safety and code clarity.
_griptape_tool: Any | |
"""The wrapped griptape tool.""" | |
def __init__( | |
self, | |
tool: Any, | |
activity_method: Optional[str] = None, | |
name: Optional[str] = None, | |
description: Optional[str] = None, | |
): | |
_griptape_tool: GriptapeBaseTool | |
"""The wrapped griptape tool.""" | |
def __init__( | |
self, | |
tool: GriptapeBaseTool, | |
activity_method: Optional[str] = None, | |
name: Optional[str] = None, | |
description: Optional[str] = None, | |
): | |
except Exception as e: | ||
# If schema parsing fails, fall back to empty params | ||
print(f'Warning: Could not parse Griptape schema: {e}') | ||
return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception handling could be improved:
- Broad Exception: Catching a generic
Exception
can hide unexpected errors. It's better to catch more specific exceptions that you anticipate during schema parsing (e.g.,AttributeError
,KeyError
,TypeError
). - Using
print
:print()
should be avoided for logging in a library. Thelogging
module provides proper logging that can be configured by the application.
Please consider refining the exception handling and using logging.warning
. You will need to import the logging
module.
except Exception as e: | |
# If schema parsing fails, fall back to empty params | |
print(f'Warning: Could not parse Griptape schema: {e}') | |
return {} | |
except (AttributeError, KeyError, TypeError) as e: | |
# If schema parsing fails, fall back to empty params | |
logging.warning('Could not parse Griptape schema: %s', e) | |
return {} | |
description
feat: Add wrapper for griptape tool: https://github.com/griptape-ai/griptape
Example:
testing plan
Closes: #2800