Repository navigation
fix: resolve postponed annotations when creating a tool from a function - #12739
Merged
julian-risch merged 2 commits intoSep 22, 2026
Merged
julian-risch merged 2 commits into
julian-risch merged 2 commits into
Conversation
With `from __future__ import annotations`, inspect.signature returns string annotations. create_tool_from_function passed them to pydantic, which cannot resolve names like Annotated, and the State check never matched. deepset-ai#12185 resolved them for the Agent and component paths but not here. Resolve them with _resolve_parameter_types, which now takes include_extras so Annotated descriptions survive.
alanhuangyoo
requested review from
julian-risch
and removed request for
a team
September 13, 2026 22:05
Contributor
|
@alanhuangyoo is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @alanhuangyoo, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
alanhuangyoo
force-pushed
the
fix/tool-from-function-postponed-annotations
branch
from
September 21, 2026 17:22
3b47803 to
6bc7dcf
Compare
julian-risch
approved these changes
Sep 22, 2026
julian-risch
left a comment
Member
There was a problem hiding this comment.
LGTM! Thank you @alanhuangyoo !
5 tasks done
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
create_tool_from_functionside of fix: deferred annotation pickup in Agent #12185, which resolved postponed annotations for the Agent, components and hooks.Proposed Changes:
In a module with
from __future__ import annotations,inspect.signaturereturns every annotation as a string.create_tool_from_functionpasses those strings straight to pydantic'screate_model, which cannot resolve names likeAnnotatedorDocument, and itsStatecheck compares a string with the class. So@toolfails at import time for any parameter that isn't typed with a builtin:Annotated[str, "..."]is the documented way to add parameter descriptions, so this hits the common case.The fix resolves the annotations with
_resolve_parameter_types(added in #12185) before the loop. That helper callsget_type_hintswithoutinclude_extras, which would strip theAnnotateddescriptions, so it gets a keyword-onlyinclude_extrasflag. Its default keeps the current behavior for the other callers.How did you test it?
test_from_function_with_postponed_annotations: string annotations withAnnotated,Literaland an optionalStategive the same schema as the eager version. It fails without the fix.TestResolveParameterTypes::test_keeps_annotated_metadata_with_include_extrasfor the new flag.from __future__ import annotations, a@toolwith aStateparameter now builds, and an Agent with a scripted chat generator injects the state and the tool writes to it. On main, creating that tool raises.pytest -m "not integration" test/tools test/core/test_type_utils.py test/core/component test/components/agents test/hooks: 2064 passed.ruff check,ruff format --check, andmypyon the four changed Python files pass.Checklist
This PR was fully generated with an AI assistant, including the fix, the tests and this description. The checks above are the ones that were actually run.