Skip to content

fix: handle annotated ChatMessage lists in ComponentTool - #13311

Closed
WhyTan00 wants to merge 1 commit into
deepset-ai:mainfrom
WhyTan00:fix/annotated-chat-message-component-tool
Closed

WhyTan00 wants to merge 1 commit into
deepset-ai:mainfrom
WhyTan00:fix/annotated-chat-message-component-tool

Conversation

@WhyTan00

Copy link
Copy Markdown

Related Issues

Independently reproduced on main at c6c46c6. No matching issue, PR, or commit was found in the targeted searches before implementation.

Proposed Changes

A component accepting Annotated[list[ChatMessage], ...] currently advertises private _role and _content fields instead of the public serialized message shape. Invoking its ComponentTool with messages produced by ChatMessage.to_dict() raises ToolInvocationError because the Annotated wrapper prevents the existing dataclass conversion from running.

Resolve the type inside Annotated while retaining its metadata for schema generation. For plain and optional annotated dataclass/list inputs, insert automatic conversion beneath the original annotation validators, preserving their ordering and constraints. BeforeValidator and WrapValidator still receive the original input. The placement of Optional still determines whether those validators observe None. Primitive annotations and broader Annotated unions retain their previous validation paths; this patch does not add automatic conversion to broader unions.

How did you test it?

  • Identical focused tests against original source: 6 failed, 17 passed. With this fix: all 23 passed. Covers sync/async invocation, three Annotated/optional forms, public ChatMessage schema fields and minItems, minimum-length validation, BeforeValidator and WrapValidator raw-input semantics, optional None, primitive validation, and non-message union alternatives.
  • Combined tools and agent tool-calling unit suites: 383 passed, 2 skipped, 12 deselected.
  • Scoped mypy: no issues found in the three changed Python files.
  • All applicable changed-file pre-commit hooks passed; git diff --check passed.
  • A standalone public API reproduction fails before the fix and passes afterward. No provider or model API was called.
  • An independent automated technical review also passed all 23 focused cases.

Tests ran through Hatch on Python 3.12.14 with a temporary local Hatch configuration containing focused test dependencies. That configuration is excluded from the change. The full repository and live integration suites were not run.

Notes for the reviewer

This PR was fully generated with an AI assistant. The assistant ran the listed regression and quality checks. Contributor review and any required CLA completion remain with the submitter; no human-review claim or agreement acceptance is implied.

Checklist

  • The assistant read the contributor guidelines and repository agent instructions.
  • Added unit regressions for the changed behavior and compatibility controls.
  • Used a conventional fix: title.
  • Added the required Reno release note.
  • Ran the relevant tests, scoped type checks, and pre-commit hooks.
  • Related issue update: not applicable; no existing matching issue was found.
  • Contributor review and CLA: to be completed by the submitter if required; this draft does not claim either is complete.

@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

@WhyTan00 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sjrl sjrl added the cla-pending PR is in draft until the contributor signs the CLA label Nov 11, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @WhyTan00, just a friendly reminder: this PR is still in draft because the Contributor License Agreement (CLA) hasn't been signed yet. We'd love to review your contribution! Please sign the CLA via the link in the license/cla check, and this PR will automatically be marked ready for review.

args = get_args(_type)

if origin is Annotated:
return Annotated[_resolve_type(args[0]), *args[1:]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#13516 was merged and adds a converting keyword to _resolve_type. Could you rebase on main and pass it through here? Without it, dataclasses that refer to each other only through Annotated fields recurse until RecursionError.

Suggested change
return Annotated[_resolve_type(args[0]), *args[1:]]
return Annotated[_resolve_type(args[0], converting=converting), *args[1:]]

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @WhyTan00, this PR is still waiting for the Contributor License Agreement (CLA) to be signed. Please note that if the CLA isn't signed within the next 4 days, this PR will be automatically closed as stale. Signing only takes a minute via the link in the license/cla check, and the PR will then automatically be marked ready for review.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @WhyTan00, this PR is still waiting for the Contributor License Agreement (CLA) to be signed. Please note that if the CLA isn't signed within the next 24 hours, this PR will be automatically closed. Signing only takes a minute via the link in the license/cla check, and the PR will then automatically be marked ready for review.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @WhyTan00, we're closing this PR because the Contributor License Agreement (CLA) wasn't signed within 48 hours. Thanks a lot for your interest in contributing to Haystack! If you'd still like to see this change merged, please sign the CLA and reopen this PR — it will then automatically be marked ready for review.

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

Labels

cla-pending PR is in draft until the contributor signs the CLA topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants