Skip to content

Agent Zero AI framework

fix(chat-naming): validate names before marking them manual

Alessandrocab075307e3c
diff --git a/plugins/_chat_naming/commands/rename_command.py b/plugins/_chat_naming/commands/rename_command.py
index 2c1d09da5..828b79fef 100644
--- a/plugins/_chat_naming/commands/rename_command.py
+++ b/plugins/_chat_naming/commands/rename_command.py
@@ -19,6 +19,7 @@ async def run(payload: dict[str, Any]) -> dict[str, Any]:
raw_name = await naming.generate_name(agent)
agent.context.set_data(naming.MANUAL_NAME_KEY, False)
else:
+ raw_name = naming.normalize_manual_name(raw_name)
agent.context.set_data(naming.MANUAL_NAME_KEY, True)
name = naming.save_context_name(agent, raw_name)
diff --git a/plugins/_chat_naming/tests/test_chat_naming.py b/plugins/_chat_naming/tests/test_chat_naming.py
index 750ddb038..b25cac5ae 100644
--- a/plugins/_chat_naming/tests/test_chat_naming.py
+++ b/plugins/_chat_naming/tests/test_chat_naming.py
@@ -340,6 +340,21 @@ async def test_rename_command_saves_a_custom_name(monkeypatch):
}
+async def test_rejected_rename_does_not_disable_automatic_naming():
+ agent = _Agent([], name="Automatic Name")
+
+ with pytest.raises(ValueError, match="200 characters"):
+ await rename_command.run(
+ {
+ "invocation": {"raw_arguments": "x" * 201},
+ "context": {"agent": agent},
+ }
+ )
+
+ assert agent.context.name == "Automatic Name"
+ assert agent.context.get_data(naming.MANUAL_NAME_KEY) is None
+
+
async def test_rename_auto_generates_and_saves_a_name(monkeypatch):
agent = _Agent([_Message({"user_message": "Plan a launch"}, sequence=1)])
generated = []