Allow RunContext
to not be documented when require_parameter_descriptions=True
as it's not passed to the model anyway
#1750
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refines the behavior of the
require_parameter_descriptions=True
argument in the@agent.tool
and@agent.tool_plain
decorators to be more permissive and robust. Previously, this setting exhibited incorrect behavior by raising errors in scenarios where docstrings either omitted descriptions for theRunContext
parameter or included descriptions for parameters not present in the function signature. The latter case was particularly problematic as the error message incorrectly indicated missing descriptions when the issue was the presence of descriptions for non-existent parameters.With this change, the following is now allowed when
require_parameter_descriptions=True
:RunContext
Descriptions: The docstring of a tool function can now omit a description for theRunContext
parameter. SinceRunContext
is not typically a parameter directly consumed by the agent's logic, requiring its description was often unnecessary and could clutter docstrings.Examples:
Before this PR, with
require_parameter_descriptions=True
, an error would be raised because the docstring lacked a description for thectx
parameter. This is now allowed, streamlining docstrings for tools utilizingRunContext
.Next, consider a function with a parameter description that doesn't match a function parameter:
Before this fix, the presence of the
:param tz:
in the docstring would incorrectly trigger the error message:This was misleading because the issue wasn't a missing description, but rather the presence of a description for a non-existent parameter. Now, the description for the non-existent
tz
parameter is correctly and silently ignored, and no error is raised.P.S. Yes, Gemini helped me rewrite and refine this description. However, I encountered the issues described above and made necessary changes in the code myself. Hope you'll find them helpful.