Skip to content

fix(optimization): preserve shared agents across levels, planner thinking fields, and reject duplicate names - #8423

Open
xuilen wants to merge 1 commit into
google:mainfrom
xuilen:fix/cloner-shared-agents-planner-dupes
Open

xuilen wants to merge 1 commit into
google:mainfrom
xuilen:fix/cloner-shared-agents-planner-dupes

Conversation

@xuilen

@xuilen xuilen commented Nov 28, 2026

Copy link
Copy Markdown

Closes #8418

Summary

Fixes three parameter-override issues in clone_agent_with_params:

  1. Cross-level shared agents (AgentTool on a different agent): When an agent in sub_agents was also wrapped by an AgentTool on another sibling agent, the cloner created two separate clones and only applied sub_agents.<name>.<field> to one of them.
  2. Dotted thinking_config override with BuiltInPlanner: When an agent configured thinking_config on both generate_content_config and BuiltInPlanner, dotted overrides merged against generate_content_config.thinking_config and overwrote the planner's config, dropping planner-only fields such as include_thoughts=True.
  3. Ambiguous duplicate names: Targeting sub_agents.<name>.<field> or tools.<name>.<field> when multiple distinct child agents share <name> silently modified all of them instead of raising ValueError.

Changes

  • src/google/adk/optimization/_agent_tree_cloner.py:
    • Pre-collect and validate direct overrides per original agent id() via _collect_agent_params, then clone through a shared tree-wide memo in _clone_agent_with_memo so every reference to the same original agent maps to one clone regardless of traversal order.
    • Prefer planner.thinking_config as the merge base for dotted thinking_config overrides whenever a BuiltInPlanner is present.
    • Detect duplicate distinct sub-agent / AgentTool agent names in _partition_agent_params and raise ValueError when a parameter targets an ambiguous name.
  • tests/unittests/optimization/agent_tree_cloner_test.py:
    • Add regression tests covering cross-level shared agents (in both sibling orders), planner include_thoughts preservation, and duplicate sub-agent / AgentTool name rejection.

Testing

  • pytest tests/unittests/optimization/agent_tree_cloner_test.py: 42 passed, 0 failed.
  • ruff check: passed.

@google-cla

google-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

optimization: clone_agent_with_params misses an agent shared across levels, drops planner thinking fields, and ignores duplicate names

1 participant