fix: skip empty tool entries in agent_chat config validation

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
This commit is contained in:
Yufeng He 2026-06-23 04:07:52 +08:00
parent 0cc27dd401
commit 005871d71d
2 changed files with 20 additions and 0 deletions

View File

@ -200,6 +200,11 @@ class AgentChatAppConfigManager(BaseAppConfigManager):
raise ValueError("tools in agent_mode must be a list of objects")
for tool in agent_mode["tools"]:
if not tool:
# Skip malformed empty tool entries; list(tool.keys())[0]
# would otherwise raise IndexError (same guard as the sibling
# dataset/manager.py and variables/manager.py).
continue
key = list(tool.keys())[0]
if key in OLD_TOOLS:
# old style, use tool name as key

View File

@ -301,3 +301,18 @@ class TestValidateAgentModeAndSetDefaults:
updated, _ = AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", config)
assert updated["agent_mode"]["tools"][0]["dataset"]["enabled"] is False
assert updated["agent_mode"]["tools"][1]["enabled"] is False
def test_empty_tool_entry_is_skipped(self):
# A malformed empty `{}` tool entry must be skipped, not crash with
# IndexError on list(tool.keys())[0] — same guard as the sibling
# dataset/manager.py (#37669) and variables/manager.py (#37671).
config = {
"agent_mode": {
"enabled": True,
"strategy": PlanningStrategy.ROUTER.value,
"tools": [{}],
}
}
updated, keys = AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", config)
assert keys == ["agent_mode"]
assert updated["agent_mode"]["tools"] == [{}]