Repository navigation
Conversation
_get_required_fields used `not schema.nullable` to decide requiredness,
confusing "nullable" (value may be null) with "optional" (argument may be
omitted). An `Optional[T]` parameter without a default (e.g.
`def f(x: str | None)`) was therefore dropped from the declaration
required list, while FunctionTool._get_mandatory_args still treats it as
mandatory. This mismatch made the model omit the argument and force an
extra round-trip ("mandatory input parameters are not present").
Derive required from the callable signature instead, matching
FunctionTool._get_mandatory_args.
7 of 9 tasks
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
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.
Summary
build_function_declarationcomputes required parameters via_get_required_fields, which decides requiredness withnot schema.nullable. That conflates "nullable" (the value may be null) with "optional" (the argument may be omitted). As a result, anOptional[T]parameter without a default value (e.g.def f(x: str | None)) is wrongly dropped from the declaration'srequiredlist.Problem
In Python,
Optional[str]with no default is still a required argument (it just permitsNone). But:FunctionTool._get_mandatory_args(function_tool.py:641) usesparam.default == inspect.Parameter.empty, so it correctly treats such a parameter as mandatory;requiredlist (via_get_required_fields) drops it.The model is told the argument may be omitted, then the runtime rejects the call with "mandatory input parameters are not present" and forces an extra round-trip.
Root cause:
types.Schema.defaultcannot distinguish "no default" from an explicit= Nonedefault (both leavedefaultasNone), andnullableonly means "may be null", not "may be omitted".Changes
In
from_function_with_options, deriverequireddirectly frominspect.signature(func).parameters(param.default is inspect.Parameter.empty), matchingFunctionTool._get_mandatory_args, instead of calling_get_required_fields.Tests
Two new cases:
test_build_declaration_marks_optional_without_default_as_required:def f(name: str, nickname: str | None)->required == ['name', 'nickname']test_build_declaration_omits_optional_with_none_default:def f(name: str, nickname: str | None = None)->required == ['name']