feat: Add ability to set messages as required in Agent through required_variables#11062
feat: Add ability to set messages as required in Agent through required_variables#11062
required_variables#11062Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Coverage Report for CI Build 24179852747Warning No base build found for commit Coverage: 92.845%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
| 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]) |
There was a problem hiding this comment.
@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.
| 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}" |
There was a problem hiding this comment.
@julian-risch this is what throws an error if the set_input_type is done in the init method.
| # 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__() |
There was a problem hiding this comment.
@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.
Related Issues
Proposed Changes:
How did you test it?
Notes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.