Skip to content

fix: don't pass parent kwargs to managed agents in from_dict()#2063

Open
MaxwellCalkin wants to merge 1 commit intohuggingface:mainfrom
MaxwellCalkin:fix/from-dict-kwargs-leak
Open

fix: don't pass parent kwargs to managed agents in from_dict()#2063
MaxwellCalkin wants to merge 1 commit intohuggingface:mainfrom
MaxwellCalkin:fix/from-dict-kwargs-leak

Conversation

@MaxwellCalkin
Copy link

Summary

Fixes #1849

When deserializing agents with from_dict(), the parent agent's **kwargs (including additional_authorized_imports) were passed to child managed agents via:

managed_agent = agent_class.from_dict(managed_agent_dict, **kwargs)

This caused child agents to lose their custom configurations after deserialization. For example, a child agent with additional_authorized_imports=["sympy"] would lose that import because the parent's kwargs (without sympy) overwrote it via code_agent_kwargs.update(kwargs) in CodeAgent.from_dict().

Fix

Remove **kwargs from the managed agent from_dict() call in MultiStepAgent.from_dict():

# Before (buggy)
managed_agent = agent_class.from_dict(managed_agent_dict, **kwargs)

# After (fixed)
managed_agent = agent_class.from_dict(managed_agent_dict)

Each managed agent's serialized dict already contains all the information needed for its own deserialization — there is no reason to propagate the parent's kwargs down to children.

Test plan

  • Create a CodeAgent with a managed sub-agent that has custom additional_authorized_imports (e.g., ["sympy"])
  • Serialize with .to_dict() and deserialize with .from_dict()
  • Verify the sub-agent retains its custom authorized_imports after round-trip

🤖 Generated with Claude Code

When deserializing agents with from_dict(), the parent agent's **kwargs
(including additional_authorized_imports) were passed to child managed
agents, overriding their custom configurations.

This caused child agents to lose their custom authorized_imports after
deserialization, leading to runtime errors when executing code that
depends on those imports.

The fix removes **kwargs from the managed agent from_dict() call since
each managed agent's serialized dict already contains all the
information needed for its own deserialization.

Fixes huggingface#1849
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

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