Skip to content

fix: deferred annotation pickup in Agent - #12185

Merged
sjrl merged 3 commits into
mainfrom
fix-deferred-annotations-get-func-params
Jul 29, 2026
Merged

fix: deferred annotation pickup in Agent#12185
sjrl merged 3 commits into
mainfrom
fix-deferred-annotations-get-func-params

Conversation

@sjrl

@sjrl sjrl commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Related Issues

  • fixes #issue-number

Proposed Changes:

  • Tool functions defined in a module using from __future__ import annotations are now inspected correctly by Agent. Postponed annotations are stored as strings, so a parameter annotated with State was not recognized and the live State object was not injected into the tool call. The annotations are now resolved before they are inspected.

  • Also consolidated the repeated logic into one util function.

How did you test it?

New tests.

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@sjrl
sjrl requested a review from a team as a code owner July 29, 2026 08:23
@sjrl
sjrl requested review from anakin87 and removed request for a team July 29, 2026 08:23
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Jul 29, 2026 10:52am

Request Review

@sjrl sjrl self-assigned this Jul 29, 2026
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jul 29, 2026
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/agents
  tool_calling.py
  haystack/core
  type_utils.py
  haystack/core/component
  component.py
  haystack/hooks
  from_function.py
Project Total  

This report was generated by python-coverage-comment-action

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a minor comment

hints = {}
# Every parameter is always in the returned dict; only its type may stay unresolved, as the raw string.
return {
name: hints.get(name, param.annotation) if isinstance(param.annotation, str) else param.annotation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
name: hints.get(name, param.annotation) if isinstance(param.annotation, str) else param.annotation
name: hints.get(name, param.annotation)

we don't need the condition, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we technically want to keep this b/c this allows us to prefer param.annotation over the hints. This is b/c the hints can expand a param's type to include optional if its default value is None. E.g. param: int = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I understand and I see that this is true for Python <= 3.10
In 3.11, they changed this aspect -> https://docs.python.org/3/whatsnew/3.11.html#typing
Worth a small comment in the code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 09c8a2d

@sjrl
sjrl enabled auto-merge (squash) July 29, 2026 10:52
@sjrl
sjrl merged commit c42f9bc into main Jul 29, 2026
24 checks passed
@sjrl
sjrl deleted the fix-deferred-annotations-get-func-params branch July 29, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants