Skip to content

Conversation

@baonudesifeizhai
Copy link
Contributor

  • Add parameter_defaults field to ToolFunctionDef and ToolFunctionDefDict
  • Implement automatic default extraction from function signatures using inspect
  • Add manual default specification support
  • Update JSON schema generation to include default values
  • Add comprehensive test coverage for default parameter values
  • Maintain backward compatibility with existing tool definitions

Closes #90

- Add parameter_defaults field to ToolFunctionDef and ToolFunctionDefDict
- Implement automatic default extraction from function signatures using inspect
- Add manual default specification support
- Update JSON schema generation to include default values
- Add comprehensive test coverage for default parameter values
- Maintain backward compatibility with existing tool definitions

Closes lmstudio-ai#90
@github-actions
Copy link

github-actions bot commented Aug 17, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@baonudesifeizhai
Copy link
Contributor Author

Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have read the CLA Document and I hereby sign the CLA

@github-actions github-actions bot added the CLA signed Indicates that all contributors have signed label Aug 17, 2025
@baonudesifeizhai
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Collaborator

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this!

I think we should go for an inline default format using the same style as Zod in TypeScript, as well as JSON schema itself, allowing the type fields to contain {"type": some_type, "default": some_value} instead of simply the type annotation. At the same time, we can tighten up the type hinting to make it clear that parameter type declarations need to be valid type hints, not entirely arbitrary objects.

The rest of the comments are largely just a first pass at exploring the implications of that design clarification (I haven't tested them, or even type checked them, but they're at least a step in the desired direction)

One potential simplification is that once the defaults are being correctly populated, msgspec should take care of populating the generated JSON schema appropriately.

…e parameter_defaults with inline format - Use generic TypedDict with NotRequired for better type safety - Remove manual default value injection, rely on msgspec auto-handling - Update all tests to use inline format instead of separate mapping
@baonudesifeizhai baonudesifeizhai force-pushed the feature/default-parameter-values branch from 32ed2f8 to c5cee65 Compare August 18, 2025 22:53
Copy link
Collaborator

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

There are a few minor cleanups still needed (details inline), but I'll go ahead and make those myself before merging.

@baonudesifeizhai
Copy link
Contributor Author

Thanks for the update!

There are a few minor cleanups still needed (details inline), but I'll go ahead and make those myself before merging.

i see some test fail , i will figure out

@ncoghlan
Copy link
Collaborator

Oh, that's annoying (Python 3.10):

TypeError: cannot inherit from both a TypedDict type and a non-TypedDict base class

It's due to python/cpython#89026 (the limitation was resolved in Python 3.11).

I'll just put a version guard on the ToolParameterDefDict definition, and use Any instead of the TypeVar on 3.10

@baonudesifeizhai baonudesifeizhai force-pushed the feature/default-parameter-values branch from 75b1f4c to 1f1c225 Compare August 19, 2025 03:17
@ncoghlan ncoghlan merged commit a7cd8af into lmstudio-ai:main Aug 19, 2025
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 19, 2025
@ncoghlan
Copy link
Collaborator

Thank you for the PR! This will be released as part of lmstudio-python 1.5.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CLA signed Indicates that all contributors have signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool definitions should allow for default parameter values

2 participants