Files
agent-framework/python/packages
T
Giles Odigwe cb96347c95 Python: Fix PydanticSchemaGenerationError when using from __future__ import annotations with @tool (#4822)
* Fix PydanticSchemaGenerationError with PEP 563 annotations in @tool

_resolve_input_model used raw param.annotation from inspect.signature(),
which returns string annotations when 'from __future__ import annotations'
is active (PEP 563). This caused Pydantic's create_model to fail for
complex types like Optional[int] or FunctionInvocationContext.

Use typing.get_type_hints() to resolve annotations to actual types before
passing them to create_model, matching the approach already used by
_discover_injected_parameters.

Fixes #4809

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Apply pre-commit auto-fixes

* Remove reproduction report and unused test imports

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(tests): strengthen PEP 563 regression tests per review feedback (#4809)

- Verify type correctness in schema assertions (not just key presence)
- Fix ctx annotation to FunctionInvocationContext | None for type consistency
- Add test for Optional[CustomType] pattern (original bug trigger)
- Add test for get_type_hints() fallback with unresolvable forward refs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Apply pre-commit auto-fixes

* Address review feedback for #4809: Python: [Bug]: PydanticSchemaGenerationError in FunctionInvocationContext

---------

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cb96347c95 ยท 2026-03-23 21:47:12 +00:00
History
..