-
Notifications
You must be signed in to change notification settings - Fork 17
feat(toolbox-core): Add support for optional parameters #290
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
+282
−20
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/gcbrun |
kurtisvg
previously approved these changes
Jun 19, 2025
kurtisvg
previously approved these changes
Jun 20, 2025
958be67
to
c31eb0c
Compare
c31eb0c
to
d2d2027
Compare
kurtisvg
previously approved these changes
Jun 24, 2025
57aeeb2
to
d6a153e
Compare
1c598a4
to
90f7472
Compare
90f7472
to
7e38892
Compare
kurtisvg
approved these changes
Jul 2, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
The previous implementation of
toolbox-core
treated all tool parameters as implicitly required. This limited the flexibility of tool definitions and did not align with common use cases where tools have optional arguments with default behaviors.This PR introduces full support for optional parameters, corresponding to the feature added to the Toolbox server (#617), enabling developers to create more versatile and powerful tools. The changes ensure that optionality is correctly reflected and handled at every stage: from the function signature and type hinting down to the final payload sent to the server.
Proposed Changes
This PR introduces a series of coordinated changes across the parameter handling and tool invocation pipeline:
1.
ParameterSchema
EnhancementParameterSchema
of the Toolbox protocol, allowing tool manifest authors to explicitly mark parameters as optional.__get_type()
method now correctly wraps the type intyping.Optional
when a parameter hasrequired=False
.to_param()
method now constructs aninspect.Parameter
withdefault=None
for optional parameters.2. Correct Signature Generation
ToolboxTool.__init__
method, the list of tool parameters is now sorted to place all required parameters before optional ones.ValueError: non-default argument follows default argument
that could occur if a manifest defined an optional parameter before a required one.3. Aligned Pydantic Validation
The
params_to_pydantic_model
utility function has been updated to be aware of therequired
flag. It now generates Pydantic Field definitions withdefault=None
for optional fields, ensuring runtime validation is consistent with the function signature.4. Cleaner API Payloads
null
value.Impact
my_tool(required_arg: str, optional_arg: Optional[str] = "Some Value")). Standard tools like
help()` and editor autocompletion will work as expected.