You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently we will need to use Annotated parameters for functions to be smoothly parsed as tools. This is not the standard documentation practice in Python however, and would often need manual labor for tool creators to convert standard python functions to tools. And this manual labor is usually copying from the ReST docstring and pasting to the Annotated description.
Describe the solution you'd like
Make create_tool_from_function support ReST-styled docstrings by default. See deepset-ai#9004
Describe alternatives you've considered
Additional context
This was a small upgrade when I was working on my personal project, but I feel like this can be standardized as a common feature. So here's the PR.
The text was updated successfully, but these errors were encountered:
I've analyzed the feature request for supporting ReST-style docstrings in the create_tool_from_function utility. This is definitely a valuable enhancement that would make tool creation more developer-friendly.
Current Implementation
Currently, create_tool_from_function only supports parameter descriptions through typing.Annotated:
defget_weather(
city: Annotated[str, "the city for which to get the weather"] ="Munich",
unit: Annotated[Literal["Celsius", "Fahrenheit"], "the unit for the temperature"] ="Celsius"):
'''A simple function to get the current weather for a location.'''# Function implementation
Proposed Enhancement
The enhancement would allow developers to use standard ReST-style docstrings for parameter descriptions:
defget_weather(city: str="Munich", unit: Literal["Celsius", "Fahrenheit"] ="Celsius"):
'''A simple function to get the current weather for a location. :param city: the city for which to get the weather :param unit: the unit for the temperature '''# Function implementation
Implementation Approach
To implement this feature, we would need to:
Parse the function's docstring to extract parameter descriptions
Add a docstring parser that specifically handles ReST-style parameter documentation (:param param_name: description)
Update create_tool_from_function to:
Extract parameter descriptions from docstrings when available
Fall back to Annotated metadata when docstring descriptions aren't available
Populate the parameter descriptions in the generated JSON schema
This would provide a more natural developer experience for Python developers who are already using ReST-style docstrings as their standard documentation approach.
Backward Compatibility
The implementation should maintain backward compatibility by:
First checking for Annotated metadata (existing approach)
Then falling back to docstring parameter descriptions if available
Ensuring existing tools created with Annotated types continue to work
This enhancement would reduce the "manual labor" mentioned in the issue description where developers need to copy descriptions from docstrings into Annotated type hints.
Is your feature request related to a problem? Please describe.
Currently we will need to use Annotated parameters for functions to be smoothly parsed as tools. This is not the standard documentation practice in Python however, and would often need manual labor for tool creators to convert standard python functions to tools. And this manual labor is usually copying from the ReST docstring and pasting to the Annotated description.
Describe the solution you'd like
Make
create_tool_from_function
support ReST-styled docstrings by default. See deepset-ai#9004Describe alternatives you've considered
Additional context
This was a small upgrade when I was working on my personal project, but I feel like this can be standardized as a common feature. So here's the PR.
The text was updated successfully, but these errors were encountered: