Skip to content

Commit 2a47fd4

Browse files
committed
chore: Make separation of required/optional params more efficient
1 parent de27831 commit 2a47fd4

File tree

1 file changed

+8
-6
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+8
-6
lines changed

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ def __init__(
8989
self.__params = params
9090
self.__pydantic_model = params_to_pydantic_model(name, self.__params)
9191

92-
# Sort parameters to ensure required ones (required=True) come before
93-
# optional ones (required=False). This prevents the "non-default argument
94-
# follows default argument" error when creating the signature.
95-
sorted_params = sorted(self.__params, key=lambda p: p.required, reverse=True)
96-
inspect_type_params = [param.to_param() for param in sorted_params]
92+
# Separate parameters into required (no default) and optional (with
93+
# default) to prevent the "non-default argument follows default
94+
# argument" error when creating the function signature.
95+
required_params = [p for p in self.__params if p.required]
96+
optional_params = [p for p in self.__params if not p.required]
97+
ordered_params = required_params + optional_params
98+
inspect_type_params = [param.to_param() for param in ordered_params]
9799

98100
# the following properties are set to help anyone that might inspect it determine usage
99101
self.__name__ = name
@@ -468,4 +470,4 @@ def bind_param(
468470
the tool's definition.
469471
470472
"""
471-
return self.bind_params({param_name: param_value})
473+
return self.bind_params({param_name: param_value})

0 commit comments

Comments
 (0)