mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-10-18 23:20:10 +00:00
fix(chat-naming): validate names before marking them manual
Validate custom /rename names before setting the persisted manual-name flag. A rejected name must leave automatic naming enabled. Add a regression test for a name exceeding the 200-character limit.
This commit is contained in:
parent
229b671ace
commit
cab075307e
2 changed files with 16 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue