Skip to content

Conversation

@wingding12
Copy link

Summary

Fixes #1849

When deserializing an agent with managed agents via from_dict(), the parent agent's **kwargs were being incorrectly passed to child agents. This caused child agent configurations (especially additional_authorized_imports) to be overwritten by the parent's configuration.

Root Cause

In MultiStepAgent.from_dict(), line 1043:

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

The **kwargs contains the parent agent's code_agent_kwargs (including additional_authorized_imports), which then overrides the child agent's own serialized configuration in CodeAgent.from_dict().

Fix

Remove **kwargs from the managed agent deserialization call:

managed_agent = agent_class.from_dict(managed_agent_dict)

Each managed agent should use only its own serialized configuration, not inherit the parent's kwargs.

Test Plan

  • Added test_from_dict_preserves_managed_agent_authorized_imports that:
    • Creates a managed agent with custom additional_authorized_imports=["sympy"]
    • Creates a parent agent WITHOUT sympy
    • Serializes and deserializes via to_dict()/from_dict()
    • Verifies the managed agent retains sympy in its authorized_imports
  • Test fails without the fix (NOP check verified)
  • All existing serialization tests pass

Fixes huggingface#1849

When deserializing an agent with managed agents, the parent kwargs
were being passed to child agents, causing their configuration
(especially additional_authorized_imports) to be overwritten.

The fix removes kwargs from the managed agent deserialization call,
ensuring each agent uses only its own serialized configuration.

Added test that verifies managed agents retain their authorized_imports
after a to_dict/from_dict round-trip.
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