Skip to content

Commit 4e5d7e8

Browse files
author
路旦
committed
fix: Avoid modifying original config in AgentBuilder._build()
- Replace pop() operations with dictionary comprehension - Create filtered config dict to avoid side effects - Improve code clarity and maintainability The previous implementation used pop() which modified the original config dict passed to _build(). This could cause issues if the caller retained a reference to the config or wanted to reuse it. The new implementation uses dictionary comprehension to create a new dict excluding 'sub_agents' and 'tools', which are passed explicitly as parameters to avoid conflicts.
1 parent c5e7293 commit 4e5d7e8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

veadk/agent_builder.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def _build(self, agent_config: dict) -> BaseAgent:
4747
for sub_agent_config in agent_config["sub_agents"]:
4848
agent = self._build(sub_agent_config)
4949
sub_agents.append(agent)
50-
agent_config.pop("sub_agents")
5150

5251
tools = []
5352
if agent_config.get("tools", []):
@@ -58,10 +57,16 @@ def _build(self, agent_config: dict) -> BaseAgent:
5857
func = getattr(module, func_name)
5958

6059
tools.append(func)
61-
agent_config.pop("tools")
60+
61+
# Filter out special fields that will be passed explicitly
62+
# to avoid modifying the original config and parameter conflicts
63+
config_for_init = {
64+
k: v for k, v in agent_config.items()
65+
if k not in ["sub_agents", "tools"]
66+
}
6267

6368
agent_cls = AGENT_TYPES[agent_config["type"]]
64-
agent = agent_cls(**agent_config, sub_agents=sub_agents, tools=tools)
69+
agent = agent_cls(**config_for_init, sub_agents=sub_agents, tools=tools)
6570

6671
logger.debug("Build agent done.")
6772

0 commit comments

Comments
 (0)