Repository navigation
Python: Fix Agent Framework tool parameter defaults #14346
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
base: main
Are you sure you want to change the base?
Changes from all commits
ff7fbf2
5403348
0a9db0f
084034f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,12 +451,15 @@ def as_agent_framework_tool( | |
| fields = {} | ||
| for param in self.parameters: | ||
| if param.include_in_function_choices: | ||
| if param.default_value is not None: | ||
| # Requiredness is explicit metadata: None can be a legitimate | ||
| # default for optional parameters and must remain a Pydantic default. | ||
| if param.is_required: | ||
| fields[param.name] = (param.type_, Field(description=param.description)) | ||
| else: | ||
| fields[param.name] = ( | ||
| param.type_, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserving the None default also needs a nullable field annotation. For the new test function, metadata stores |
||
| Field(description=param.description, default=param.default_value), | ||
| ) | ||
| fields[param.name] = (param.type_, Field(description=param.description)) | ||
| input_model = create_model("InputModel", **fields) # type: ignore | ||
|
ump45nose marked this conversation as resolved.
Resolved
|
||
|
|
||
| async def wrapper(*args: Any, **kwargs: Any) -> Any: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
param.is_requireddoes not distinguishx: str | Nonefromx: str | None = None: the decorator marks both optional. With a nullable annotation but no Python default, this branch now createsField(default=None), andtool.input_model()accepts the missing required argument. I reproduced this with a decorateddef f(x: str | None). Preserve the missing-default distinction from the callable signature (or metadata) and add a regression for nullable-but-required parameters.