Skip to content
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

fix: tool name showing as function_template in phidata #1213

Merged
merged 2 commits into from
Jan 20, 2025
Merged

Conversation

Devanshusisodiya
Copy link
Contributor

@Devanshusisodiya Devanshusisodiya commented Jan 20, 2025

Phidata toolkit was showing composio toolnames as function_template. Changed function signature to the lowercase enum to fix this.


Important

Fix tool name display issue by setting __name__ to lowercase in function_template and update return types in get_actions and get_tools.

  • Behavior:
    • Fix tool name display issue by setting __name__ to lowercase in function_template in toolset.py.
    • Update get_actions and get_tools in toolset.py to return t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]].
  • Imports:
    • Correct import for Assistant in phidata_demo.py to from phi.assistant.assistant import Assistant.

This description was created by Ellipsis for 59f4d77. It will automatically update as commits are pushed.

Copy link

vercel bot commented Jan 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2025 3:30pm

@@ -83,6 +85,7 @@ def function_template(*args, **kwargs) -> str:
# Apply the signature and annotations to the function
func.__signature__ = sig
func.__annotations__ = annotations
func.__setattr__("__name__", name.lower())

Choose a reason for hiding this comment

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

The __setattr__ call is unsafe and could allow attribute injection. Use a direct attribute assignment with func.__name__ = name.lower() instead.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func.__setattr__("__name__", name.lower())
func.__name__ = name.lower()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't assign __name__ attribute of type ToolFunction defined by phidata

Comment on lines 109 to 111
def get_actions(
self, actions: t.Sequence[ActionType]
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:

Choose a reason for hiding this comment

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

Return type annotation uses | operator which requires Python 3.10+. Should use Union from typing module for better compatibility across Python versions.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
def get_actions(
self, actions: t.Sequence[ActionType]
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:
def get_actions(
self, actions: t.Sequence[ActionType]
) -> t.Union[t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]], None]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines 133 to 136
*,
processors: t.Optional[ProcessorsType] = None,
check_connected_accounts: bool = True,
) -> t.List[Toolkit]:
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:

Choose a reason for hiding this comment

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

Returning None in get_actions() and get_tools() could cause runtime errors if callers expect a List. Should return empty list instead of None for consistency.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
*,
processors: t.Optional[ProcessorsType] = None,
check_connected_accounts: bool = True,
) -> t.List[Toolkit]:
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not returning None anymore, will always return List[Tool | ToolKit, Callable, Function]

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to d7f52f2 in 46 seconds

More details
  • Looked at 60 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. python/plugins/phidata/composio_phidata/toolset.py:136
  • Draft comment:
    The return type in the function signature includes | None, but the docstring specifies List[Toolkit]. Consider updating the docstring to reflect the possibility of a None return value.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_IFTo5eEFw3zU20aG


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

def get_actions(self, actions: t.Sequence[ActionType]) -> t.List[Toolkit]:
def get_actions(
self, actions: t.Sequence[ActionType]
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

The return type in the function signature includes | None, but the docstring specifies List[Toolkit]. Consider updating the docstring to reflect the possibility of a None return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not returning None anymore, will always return List[Tool | ToolKit, Callable, Function]

def get_actions(self, actions: t.Sequence[ActionType]) -> t.List[Toolkit]:
def get_actions(
self, actions: t.Sequence[ActionType]
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The return type annotation t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None indicates this method can return None, but there's no documentation or clear indication of when None would be returned. Consider:

  1. Adding documentation about when None is returned
  2. Adding runtime validation for the None case
  3. Updating the docstring to reflect this possibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not returning None anymore, will always return List[Tool | ToolKit, Callable, Function]



toolset = ComposioToolSet()
composio_tools = toolset.get_tools(
actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]
)

assistant = Assistant(tools=composio_tools, show_tool_calls=True)
assistant = Assistant(run_id=None, tools=composio_tools, show_tool_calls=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The addition of run_id=None parameter should be documented. Consider adding a comment explaining why this parameter is needed and what it does. This will help future maintainers understand the purpose of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

def get_actions(self, actions: t.Sequence[ActionType]) -> t.List[Toolkit]:
def get_actions(
self, actions: t.Sequence[ActionType]
) -> t.List[t.Union[Tool, Toolkit, t.Callable, t.Dict, Function]] | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this chance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assumed lowercase as mentioned in phidata's chat.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Changes Overview

  • Fixed tool name display by adding proper name attribution using __setattr__
  • Updated return type annotations in get_actions and get_tools methods
  • Modified imports for better specificity and added new tool-related imports
  • Updated Assistant initialization with run_id parameter

Positive Aspects

✅ Fixes the core issue of tool name display
✅ Improves type safety with more specific return types
✅ Better code formatting and readability
✅ Maintains backward compatibility with proper deprecation notices

Suggestions for Improvement

  1. Document when methods might return None in the new return type annotations
  2. Add explanation for the run_id=None parameter in phidata_demo.py
  3. Consider updating docstrings to reflect the new return types

Overall Assessment

The changes are well-structured and solve the immediate issue while improving type safety. The code quality is good, with proper attention to backward compatibility. With the suggested documentation improvements, this PR would be ready for merge.

Rating: 8/10 - Good quality changes with room for minor documentation improvements.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 59f4d77 in 33 seconds

More details
  • Looked at 36 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. python/plugins/phidata/composio_phidata/toolset.py:111
  • Draft comment:
    The return type hint should not include | None since the method always returns a list. Apply this change to both get_actions and get_tools methods.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_21N8ZFymPk9sVQIQ


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@Devanshusisodiya Devanshusisodiya changed the title fix: tool name not showing as function_template fix: tool name showing as function_template Jan 20, 2025
@Devanshusisodiya Devanshusisodiya changed the title fix: tool name showing as function_template fix: tool name showing as function_template in phidata Jan 20, 2025
@kaavee315 kaavee315 merged commit 620689c into master Jan 20, 2025
25 of 26 checks passed
@kaavee315 kaavee315 deleted the phidata_fix branch January 20, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants