fix: stop forwarding from_dict kwargs into managed agents#2534
Open
nolanchic wants to merge 1 commit into
Open
fix: stop forwarding from_dict kwargs into managed agents#2534nolanchic wants to merge 1 commit into
nolanchic wants to merge 1 commit into
Conversation
MultiStepAgent.from_dict passed the caller's **kwargs to every managed agent it deserialized, so a parent's overrides (e.g. additional_authorized_imports) replaced each child's own configuration after a to_dict/from_dict round-trip. Managed agents are now rebuilt from their own serialized dict only. Closes huggingface#1849
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.
What does this PR do?
Closes #1849.
MultiStepAgent.from_dictforwarded the caller's**kwargsto each managed agent while deserializing it. BecauseCodeAgent.from_dictpacksadditional_authorized_imports(and a couple of other fields) into those kwargs, the parent's imports replaced every child's own imports after ato_dict/from_dictround-trip — the child ended up with the parent's imports instead of the ones it was serialized with, which then breaks code that relied on those imports at runtime.How
Managed agents are now rebuilt from their own serialized dict, without the parent's kwargs. The kwargs still apply to the top-level agent being deserialized, which matches the existing docstring ("Additional keyword arguments that will override agent_dict values").
Test
Added
test_from_dict_does_not_leak_kwargs_into_managed_agents: a parentCodeAgent(imports["requests"]) with a managedCodeAgent(imports["rich"]) is serialized and rebuilt, then the child is asserted to keeprichand not gainrequests. It fails onmainand passes with this change.