Skip to content

Implement Tool.from_dict #1006

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

Merged
merged 4 commits into from
Apr 14, 2025

Conversation

albertvillanova
Copy link
Member

Implement Tool.from_dict, the inverse of the existing to_dict method, allowing tools to be recreated from their dictionary representation.

"""
if "code" not in tool_dict:
raise ValueError("Tool dictionary must contain 'code' key with the tool source code")
return cls.from_code(tool_dict["code"], **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe raise a warning if the tool requirements are not installed locally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review.

I would suggest not enforcing that at this stage, as we intentionally allow tools to be defined (either by subclassing Tool or using the @tool decorator) without requiring their dependencies to be installed locally.

One common use case is sending the tool to be executed in a separate environment, such as a Docker container, where the necessary requirements will be installed.

Let me know if you have thoughts or other ideas around this!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, good point!

@albertvillanova albertvillanova merged commit 2c08619 into huggingface:main Apr 14, 2025
3 checks passed
@albertvillanova albertvillanova deleted the tool-from-dict branch April 14, 2025 13:02
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.

2 participants