From 4e5d7e85f4385322680b840585270a37587cd00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=97=A6?= Date: Thu, 12 Feb 2026 14:47:19 +0800 Subject: [PATCH] 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. --- veadk/agent_builder.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/veadk/agent_builder.py b/veadk/agent_builder.py index 352d84e9..84bf57c2 100644 --- a/veadk/agent_builder.py +++ b/veadk/agent_builder.py @@ -47,7 +47,6 @@ def _build(self, agent_config: dict) -> BaseAgent: for sub_agent_config in agent_config["sub_agents"]: agent = self._build(sub_agent_config) sub_agents.append(agent) - agent_config.pop("sub_agents") tools = [] if agent_config.get("tools", []): @@ -58,10 +57,16 @@ def _build(self, agent_config: dict) -> BaseAgent: func = getattr(module, func_name) tools.append(func) - agent_config.pop("tools") + + # Filter out special fields that will be passed explicitly + # to avoid modifying the original config and parameter conflicts + config_for_init = { + k: v for k, v in agent_config.items() + if k not in ["sub_agents", "tools"] + } agent_cls = AGENT_TYPES[agent_config["type"]] - agent = agent_cls(**agent_config, sub_agents=sub_agents, tools=tools) + agent = agent_cls(**config_for_init, sub_agents=sub_agents, tools=tools) logger.debug("Build agent done.")