Skip to content

fix: stop forwarding from_dict kwargs into managed agents#2534

Open
nolanchic wants to merge 1 commit into
huggingface:mainfrom
nolanchic:fix/from_dict-managed-agents-kwargs
Open

fix: stop forwarding from_dict kwargs into managed agents#2534
nolanchic wants to merge 1 commit into
huggingface:mainfrom
nolanchic:fix/from_dict-managed-agents-kwargs

Conversation

@nolanchic

Copy link
Copy Markdown

What does this PR do?

Closes #1849.

MultiStepAgent.from_dict forwarded the caller's **kwargs to each managed agent while deserializing it. Because CodeAgent.from_dict packs additional_authorized_imports (and a couple of other fields) into those kwargs, the parent's imports replaced every child's own imports after a to_dict / from_dict round-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 parent CodeAgent (imports ["requests"]) with a managed CodeAgent (imports ["rich"]) is serialized and rebuilt, then the child is asserted to keep rich and not gain requests. It fails on main and passes with this change.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: MultiStepAgent.from_dict() passes **kwargs to managed agents, causing child agent configurations to be overridden

1 participant