Skip to content

fix: exclude *args and **kwargs from converted tool parameters - #738

Open
betacatsling wants to merge 1 commit into
ollama:mainfrom
betacatsling:fix/tool-conversion-varargs
Open

betacatsling wants to merge 1 commit into
ollama:mainfrom
betacatsling:fix/tool-conversion-varargs

Conversation

@betacatsling

Copy link
Copy Markdown

Summary

Fixes #735.

convert_function_to_tool turns every parameter in a function's signature into a required string property, including *args and **kwargs. For example, def f(x: int, *args, **kwargs) produces a tool schema with properties: {x, args, kwargs} and required: ['x', 'args', 'kwargs'] — the model is then told it must supply meaningless args/kwargs string arguments.

Variadic parameters cannot be expressed in the tool JSON schema, so this skips VAR_POSITIONAL and VAR_KEYWORD parameters when building the pydantic model used to generate the schema. Named parameters are unaffected.

Validation

  • New regression test test_function_with_varargs in tests/test_utils.py asserts the generated parameters contain only x and required == ['x'].
  • Before this change: fails — properties were {'x', 'args', 'kwargs'} and required included 'args'/'kwargs'.
  • After: pytest tests/test_utils.py — 11 passed; full suite pytest tests/ — 98 passed.
  • ruff check and ruff format --check pass on changed files.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert_function_to_tool exposes *args and **kwargs as required string parameters

1 participant