You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
convert_function_to_ollama_tool breaks under from __future__ import annotations (PEP 563) #1507
area/toolsTool framework, Bash/Python tools, tool call lifecyclebugSomething isn't workingp1High: important bugs (workaround exists) or high-value core features. Do soon, not on fire.
Under from __future__ import annotations (PEP 563), inspect.signature(func).parameters[...].annotation is a string (e.g. "str", "Requirement"), not the real type object. Pydantic treats these as unresolved forward references.
Builtin-type parameters (str, int, etc.) happen to resolve because Pydantic can look them up by name in builtins. Custom-class parameters fail hard:
from __future__ importannotationsfromdataclassesimportdataclassfrommellea.backends.toolsimportconvert_function_to_ollama_tool@dataclassclassRequirement:
id: strdefmy_tool(req: Requirement) ->str:
"""A tool with a custom-class param."""returnreq.idconvert_function_to_ollama_tool(my_tool)
raises:
PydanticUserError: 'my_tool' is not fully defined; you should define 'Requirement', then call 'my_tool.model_rebuild()'.
Any module that defines an Ollama tool function under from __future__ import annotations and uses a non-builtin parameter type will hit this at tool-conversion time.
Root cause
Same root cause as #1503: raw inspect.signature(func) annotations are read without resolving PEP 563 postponed (string) annotations — e.g. via inspect.signature(func, eval_str=True) or typing.get_type_hints(func).
area/toolsTool framework, Bash/Python tools, tool call lifecyclebugSomething isn't workingp1High: important bugs (workaround exists) or high-value core features. Do soon, not on fire.
Activity
test(backends): guard TC-only postponed-annotation tests against sile…
fix: resolve postponed annotations without failing on TYPE_CHECKING r…