Repository navigation
Description
Describe the bug
clone_agent_with_params (added in d723cb8 and used by GridSearchAgentOptimizer to build each candidate) has three cases where an override doesn't do what the path says. In each one the grid search scores candidates without any error or warning.
1. An agent wrapped by an AgentTool on a different agent is cloned twice.
The cloner already keeps sharing intact when an agent is in sub_agents and in an AgentTool on the same agent (cloned_subs, _agent_tree_cloner.py:426-457). When the AgentTool is on another agent, the tool gets its own separate clone, so a sub_agents.<name>.<field> override reaches only one of the two copies:
from google.adk.agents import LlmAgent
from google.adk.optimization._agent_tree_cloner import clone_agent_with_params
from google.adk.tools.agent_tool import AgentTool
a = LlmAgent(name="A", model="old")
b = LlmAgent(name="B", model="m", tools=[AgentTool(a)])
root = LlmAgent(name="root", model="m", sub_agents=[a, b])
c = clone_agent_with_params(root, {"sub_agents.A.model": "new"})
print(c.sub_agents[0].model) # new
print(c.sub_agents[1].tools[0].agent.model) # old
print(c.sub_agents[0] is c.sub_agents[1].tools[0].agent) # False (True in the original tree)The same tree with the AgentTool on root instead of B gives new for both.
2. A dotted thinking override drops the planner's other thinking settings.
When an agent sets thinking_config both in generate_content_config and in a BuiltInPlanner (LlmAgent warns that the planner's config wins), a dotted override is merged onto the generate_content_config copy and the result then replaces the planner's config (_agent_tree_cloner.py:355-358, _sync_builtin_planner). Planner-only fields that were in effect are lost:
root = LlmAgent(
name="root", model="gemini-2.5-flash",
generate_content_config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget=64)),
planner=BuiltInPlanner(thinking_config=types.ThinkingConfig(
include_thoughts=True, thinking_budget=128)),
)
c = clone_agent_with_params(
root, {"generate_content_config.thinking_config.thinking_budget": 1024})
print(c.planner.thinking_config)
# include_thoughts=None thinking_budget=1024So sweeping thinking_budget also turns off include_thoughts. agent_tree_cloner_test.py:328 describes dotted updates as merging with the planner's thinking_config.
3. An ambiguous name changes every match.
Paths are resolved through dicts keyed by agent name, and ADK only warns about duplicate names. With two sub-agents (or two AgentTools) named helper, sub_agents.helper.model changes both instead of raising like an unknown name does:
root = SequentialAgent(name="root", sub_agents=[
LlmAgent(name="helper", model="m1"), LlmAgent(name="helper", model="m2")])
c = clone_agent_with_params(root, {"sub_agents.helper.model": "X"})
print([s.model for s in c.sub_agents]) # ['X', 'X']Expected behavior
- Every reference to one original agent maps to one clone, so the override applies everywhere that agent is used.
- The override starts from the config that is in effect (the planner's), so
include_thoughts=Trueis kept. - An ambiguous name raises
ValueError.
Environment
main at 03725e8, Python 3.12.
I'm happy to send a PR with regression tests for all three, if this approach sounds right.
Activity
tushar-2320 commentedon Nov 28, 2026
I would like work on this