Skip to content

feat: Add ability to set messages as required in Agent through required_variables#11062

Draft
sjrl wants to merge 1 commit intomainfrom
fix-agent-messages-optionality
Draft

feat: Add ability to set messages as required in Agent through required_variables#11062
sjrl wants to merge 1 commit intomainfrom
fix-agent-messages-optionality

Conversation

@sjrl
Copy link
Copy Markdown
Contributor

@sjrl sjrl commented Apr 9, 2026

Related Issues

  • fixes #issue-number

Proposed Changes:

How did you test it?

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.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Apr 9, 2026 8:13am

Request Review

@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 24179852747

Warning

No base build found for commit acc73d9 on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 92.845%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 17164
Covered Lines: 15936
Line Coverage: 92.85%
Coverage Strength: 0.93 hits per line

💛 - Coveralls

Comment on lines +414 to +423
def __post_init__(self) -> None:
"""
Called by ComponentMeta after input/output sockets are parsed from the run method signature.

Used to retroactively make the ``messages`` input required when ``"messages"`` is listed
in ``required_variables``, which cannot be done inside ``__init__`` because the socket
hasn't been parsed yet at that point.
"""
if isinstance(self.required_variables, list) and "messages" in self.required_variables:
component.set_input_type(self, name="messages", type=list[ChatMessage])
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.

@julian-risch a __post_init__ was needed to do this because we are unable to run set_input_type on a param in the run method that is positional and already has a type.

Comment on lines 263 to +265
raise ComponentError(
"set_input_types()/set_input_type() cannot override the parameters of the 'run' method"
"set_input_types()/set_input_type() cannot override the parameters of the 'run' method.\n"
f"Conflict found for parameter '{param_name}': {existing_socket} vs {new_socket}"
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.

@julian-risch this is what throws an error if the set_input_type is done in the init method.

Comment on lines +326 to +329
# Call __post_init__ if defined, allowing components to adjust sockets after
# the run method signature has been parsed (e.g. to make an existing socket required).
if callable(getattr(instance, "__post_init__", None)):
instance.__post_init__()
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.

@julian-risch this is what I'm most concerned about since one could argue it's a pretty big feature to add support for __post_init__ to initializing components. It could be fine/a good idea to add, but I'd appreciate your thoughts.

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