Skip to content

Agent Zero AI framework

Refresh chat names as topics change by default

Alessandroef42aec9439d
diff --git a/plugins/_chat_naming/AGENTS.md b/plugins/_chat_naming/AGENTS.md
index 8046ae97c..cb13762ae 100644
--- a/plugins/_chat_naming/AGENTS.md
+++ b/plugins/_chat_naming/AGENTS.md
@@ -16,10 +16,10 @@
## Local Contracts
- Automatic naming reads scoped plugin config through the active chat agent.
-- Automatic naming runs after the monologue completes, so it cannot delay the Main Model.
+- Automatic naming is scheduled from `monologue_end` as a background task; never await its Utility Model request in the main inference path.
- Utility Model input contains the current name and user messages only; assistant work and tool results are excluded.
- The complete naming prompt must remain within 70% of the effective Utility Model context window, preserving the newest user context when trimming is required.
-- `once` names only unnamed user chats from their first user message; `always` considers the latest user message plus recent user context.
+- `always` is the default and considers the latest user message plus recent user context; `once` names only unnamed user chats from their first user message. Preserve explicitly saved modes.
- Generated names are concise and normalized before persistence.
- Renaming a parallel child updates both its context name and sidebar label.
- Manual task renames update both scheduler metadata and the task context name.
diff --git a/plugins/_chat_naming/README.md b/plugins/_chat_naming/README.md
index 06f27cfde..80b367f58 100644
--- a/plugins/_chat_naming/README.md
+++ b/plugins/_chat_naming/README.md
@@ -2,6 +2,6 @@
Chat Naming adds a standard sidebar action for manually renaming chats and tasks. Its modal can ask the chat's configured Utility Model to suggest a concise name from recent user messages.
-Automatic naming is configured per project and agent profile. It runs after the response, so its Utility Model call never delays the Main Model. It can name an unnamed chat once from its first user message, or refresh the name after every user message using recent user-only context.
+Automatic naming is configured per project and agent profile. By default, it reviews the name after every user message using recent user-only context, changing it when the topic changes. It runs after the response, so its Utility Model call never delays the Main Model. Select **Only once** to name an unnamed chat from its first user message instead. Previously saved settings are preserved; switch existing **Only once** configurations to **After every user message** to enable topic updates.
Use `/rename New Chat Name` to rename the current chat directly, or `/rename auto` to generate and save a name with its configured Utility Model.
diff --git a/plugins/_chat_naming/default_config.yaml b/plugins/_chat_naming/default_config.yaml
index 87f5c7150..420c6be25 100644
--- a/plugins/_chat_naming/default_config.yaml
+++ b/plugins/_chat_naming/default_config.yaml
@@ -1,2 +1,2 @@
automatic_naming: true
-automatic_naming_mode: once
+automatic_naming_mode: always
diff --git a/plugins/_chat_naming/helpers/naming.py b/plugins/_chat_naming/helpers/naming.py
index 2b1fe0f7e..2ffba4b33 100644
--- a/plugins/_chat_naming/helpers/naming.py
+++ b/plugins/_chat_naming/helpers/naming.py
@@ -18,9 +18,9 @@ UTILITY_CONTEXT_INPUT_RATIO = 0.7
def get_config(agent: Agent) -> dict[str, Any]:
config = plugins.get_plugin_config(PLUGIN_NAME, agent=agent) or {}
- mode = str(config.get("automatic_naming_mode", MODE_ONCE) or MODE_ONCE)
+ mode = str(config.get("automatic_naming_mode", MODE_ALWAYS) or MODE_ALWAYS)
if mode not in {MODE_ONCE, MODE_ALWAYS}:
- mode = MODE_ONCE
+ mode = MODE_ALWAYS
return {
"automatic_naming": bool(config.get("automatic_naming", True)),
"automatic_naming_mode": mode,
diff --git a/plugins/_chat_naming/tests/test_chat_naming.py b/plugins/_chat_naming/tests/test_chat_naming.py
index 61b0c60e9..bd4afea10 100644
--- a/plugins/_chat_naming/tests/test_chat_naming.py
+++ b/plugins/_chat_naming/tests/test_chat_naming.py
@@ -1,8 +1,11 @@
+import asyncio
+from pathlib import Path
from types import SimpleNamespace
import pytest
from agent import AgentContextType
+from helpers import yaml
from plugins._chat_naming.commands import rename_command
from plugins._chat_naming.extensions.python.monologue_end import _60_rename_chat as rename_chat
from plugins._chat_naming.helpers import naming
@@ -103,17 +106,23 @@ async def test_once_mode_uses_first_message_and_does_not_override_a_name(monkeyp
assert scheduled == []
-async def test_always_mode_passes_recent_user_context(monkeypatch):
[email protected]("config", ["default", {}, {"automatic_naming_mode": "always"}])
+async def test_default_and_always_modes_update_a_greeting_from_recent_context(monkeypatch, config):
messages = [
_Message({"user_message": f"Message {number}"}, sequence=number)
- for number in range(1, 7)
+ for number in range(1, 6)
]
- agent = _Agent(messages, name="Existing Name")
+ messages.append(_Message({"user_message": "Explain Docker"}, sequence=6))
+ agent = _Agent(messages, name="Greeting")
+ if config == "default":
+ config = yaml.loads(
+ (Path(naming.__file__).parents[1] / "default_config.yaml").read_text()
+ )
scheduled = []
monkeypatch.setattr(
- rename_chat.naming,
- "get_config",
- lambda _agent: {"automatic_naming": True, "automatic_naming_mode": "always"},
+ naming.plugins,
+ "get_plugin_config",
+ lambda *_args, **_kwargs: config,
)
monkeypatch.setattr(rename_chat.asyncio, "create_task", lambda coro: scheduled.append(coro))
@@ -125,7 +134,8 @@ async def test_always_mode_passes_recent_user_context(monkeypatch):
return "Current Topic"
monkeypatch.setattr(rename_chat.naming, "generate_name", generate)
- monkeypatch.setattr(rename_chat.naming, "save_context_name", lambda *_args: None)
+ saved = []
+ monkeypatch.setattr(rename_chat.naming, "save_context_name", lambda _agent, name: saved.append(name))
monkeypatch.setattr(rename_chat.AgentContext, "get", lambda _id: agent.context)
await scheduled.pop()
@@ -133,9 +143,45 @@ async def test_always_mode_passes_recent_user_context(monkeypatch):
"Message 3",
"Message 4",
"Message 5",
- "Message 6",
+ "Explain Docker",
]
- assert captured["current_name"] == "Existing Name"
+ assert captured["current_name"] == "Greeting"
+ assert saved == ["Current Topic"]
+
+
+async def test_naming_hook_returns_while_utility_inference_is_pending(monkeypatch):
+ agent = _Agent([_Message({"user_message": "Explain Docker"}, sequence=1)], name="Greeting")
+ started = asyncio.Event()
+ release = asyncio.Event()
+ running = []
+ saved = []
+
+ async def slow_utility(**kwargs):
+ assert kwargs["background"] is True
+ running.append(asyncio.current_task())
+ started.set()
+ await release.wait()
+ return "Docker Explanation"
+
+ monkeypatch.setattr(agent, "call_utility_model", slow_utility)
+ monkeypatch.setattr(naming.plugins, "get_plugin_config", lambda *_args, **_kwargs: {})
+ monkeypatch.setattr(
+ "plugins._model_config.helpers.model_config.get_utility_model_config",
+ lambda _agent: {"ctx_length": 1000},
+ )
+ monkeypatch.setattr(rename_chat.AgentContext, "get", lambda _id: agent.context)
+ monkeypatch.setattr(naming, "save_context_name", lambda _agent, name: saved.append(name))
+
+ try:
+ await asyncio.wait_for(rename_chat.RenameChat(agent=agent).execute(), timeout=1)
+ await asyncio.wait_for(started.wait(), timeout=1)
+ assert not running[0].done()
+ assert saved == []
+ finally:
+ release.set()
+ await asyncio.gather(*running, return_exceptions=True)
+
+ assert saved == ["Docker Explanation"]
async def test_rename_failure_sends_scoped_utility_model_notification(monkeypatch):
diff --git a/plugins/_chat_naming/webui/config.html b/plugins/_chat_naming/webui/config.html
index 30cdd977d..2cd6023fa 100644
--- a/plugins/_chat_naming/webui/config.html
+++ b/plugins/_chat_naming/webui/config.html
@@ -38,7 +38,7 @@
<div class="field-control">
<select x-model="config.automatic_naming_mode"
x-init="if (!['once', 'always'].includes(config.automatic_naming_mode))
- config.automatic_naming_mode = 'once'">
+ config.automatic_naming_mode = 'always'">
<option value="once">Only once</option>
<option value="always">After every user message</option>
</select>