The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-mode): a renamed primary signs with its friendly name; docs the message_agent target forms
teknium158c6f6fa201c
diff --git a/tests/tools/test_bot_mode_dm.py b/tests/tools/test_bot_mode_dm.pyindex 04504852148..bec852b6897 100644--- a/tests/tools/test_bot_mode_dm.py+++ b/tests/tools/test_bot_mode_dm.py@@ -467,6 +467,36 @@ def test_peer_delivery_author_carries_the_sender_hostname_and_local_stays_bare(tassert _runner_author(calls[1]["command"]) == {"id": "bot:coder", "name": "coder", "is_bot": True}+def test_renamed_primary_signs_with_its_friendly_name_and_is_reachable_by_it(tmp_path, monkeypatch):+ """#89720: `hermes profile rename default Maia` writes profile.yaml ``display_name`` (no Bot Mode+ title). The primary must then sign `Maia (@hermes)`, not `hermes (@hermes)`, and a teammate must+ reach it as `maia` / `@maia` — the tag the Desktop roster inserts — while `@hermes` keeps resolving.+ A Bot Mode title outranks the display_name in the signature, as in the Desktop's botFriendlyNames."""+ calls = _capture_spawn(monkeypatch)+ monkeypatch.setattr(bot_relay, "_hermes_cli", lambda: "hermes")+ home = _managed_home(tmp_path, teammates=("coder",))+ (home / "profile.yaml").write_text("display_name: Maia\n", encoding="utf-8")++ result = json.loads(bot_mode_dm.message_agent_tool(target="coder", message="hi", agent=_FakeAgent(home)))+ assert result["status"] == "sent"+ _mode, dm_file, _argv = _runner_parts(calls[0]["command"])+ assert Path(dm_file).read_text(encoding="utf-8").startswith("Message from 🤖 Maia (@hermes): ")++ coder = _FakeAgent(home / "profiles" / "coder")+ for target in ("maia", "@maia", "@hermes"):+ result = json.loads(bot_mode_dm.message_agent_tool(target=target, message="pong", agent=coder))+ assert result["status"] == "sent", (target, result)+ _mode, _dm_file, argv = _runner_parts(calls[-1]["command"])+ assert argv[1:3] == ["-p", "default"], (target, argv)++ (home / "profile.yaml").write_text(+ "display_name: Maia\nui_meta:\n hermes-bots:\n title: Maia Prime\n", encoding="utf-8"+ )+ json.loads(bot_mode_dm.message_agent_tool(target="coder", message="hi", agent=_FakeAgent(home)))+ _mode, dm_file, _argv = _runner_parts(calls[-1]["command"])+ assert Path(dm_file).read_text(encoding="utf-8").startswith("Message from 🤖 Maia Prime (@hermes): ")++def test_named_profile_sender_prefix(tmp_path, monkeypatch):"""A named-profile bot signs with its own handle, not @hermes."""calls = _capture_spawn(monkeypatch)diff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.pyindex 7a9dedb9042..e274064409c 100644--- a/tools/bot_mode_dm.py+++ b/tools/bot_mode_dm.py@@ -195,8 +195,8 @@ def message_agent_tool(target: str = "", message: str = "", task_id: Optional[sthome = _agent_home(agent)try:from tools.bot_mode_probe import (- BOT_CHAT_TITLE, _handle, _hermes_root, _peers, _profile_name as _self_profile_name, _roster,- is_bot_mode_managed,+ BOT_CHAT_TITLE, _display_name, _handle, _hermes_root, _peers, _profile_name as _self_profile_name,+ _roster, is_bot_mode_managed,)from tools.bot_relay import BOT_CHAT_TURN_ARGS, _hermes_cli@@ -228,7 +228,8 @@ def message_agent_tool(target: str = "", message: str = "", task_id: Optional[straw_target = str(target or "").strip().lstrip("@")if not raw_target:return _roster_err("target is required.")- content = f"Message from 🤖 {_handle(me)} (@{_handle(me)}): " + body+ # Sender signature: the friendly name when the bot has one (#89720); the @handle stays the routing alias.+ content = f"Message from 🤖 {_display_name(me, roster_homes.get(me, Path(home)))} (@{_handle(me)}): " + bodydelivery = dict(task_id=task_id, agent=agent)# Attribution for the recipient's memory hooks; the text prefix above stays the human-facing signature.author = {"id": f"bot:{me}", "name": _handle(me), "is_bot": True}diff --git a/tools/bot_mode_probe.py b/tools/bot_mode_probe.pyindex 07bdfd58c7e..b0070f1fbcd 100644--- a/tools/bot_mode_probe.py+++ b/tools/bot_mode_probe.py@@ -85,6 +85,7 @@ def _roster(root: Path) -> list[tuple[str, Path]]:if profiles.is_dir()else [],[],+ )return [("default", root), *named]@@ -155,6 +156,23 @@ def _profile_role(profile_dir: Path) -> str:return _swallow(_role, "")+def _friendly_names(profile_dir: Path) -> tuple[str, str]:+ """(Bot Mode title, profile.yaml ``display_name``) for a profile, "" when unset. Never raises."""+ def _read() -> tuple[str, str]:+ data = _read_yaml_dict(profile_dir / "profile.yaml") or {}+ return (str((_bots_meta(data) or {}).get("title") or "").strip(),+ str(data.get("display_name") or "").strip())++ return _swallow(_read, ("", ""))+++def _display_name(name: str, profile_dir: Path) -> str:+ """Human-facing sender name, in the Desktop's ``botFriendlyNames`` order: Bot Mode title,+ then profile.yaml ``display_name`` (``hermes profile rename``), else the @handle — the+ renamed primary signs as ``Maia (@hermes)``, not ``hermes (@hermes)`` (#89720)."""+ return next((n for n in _friendly_names(profile_dir) if n), None) or _handle(name)++# Tokens the Desktop mention parser reserves; a bot titled "Hermes" never hijacks @hermes._RESERVED_ALIASES = frozenset({"all", "everyone", "user", "default", "hermes"})@@ -172,15 +190,14 @@ def alias_forms(value: str) -> set[str]:def local_alias_map(root: Path) -> dict[str, set[str]]:"""``alias form → {folder ids}`` for every local profile's friendly names (profile.yaml- ``display_name`` and the Bot Mode title). Folder ids themselves are not aliases — the- caller matches those first — so a friendly name equal to ANOTHER folder id is visibly- ambiguous instead of silently winning. Never raises."""+ ``display_name`` and the Bot Mode title). Folder ids themselves are not aliases: the+ caller matches those first, so a target that is an exact folder id always addresses that+ folder — a friendly name colliding with ANOTHER folder id never steals it. Ambiguity+ (one alias form shared by several profiles) surfaces as a multi-id set. Never raises."""def _build() -> dict[str, set[str]]:aliases: dict[str, set[str]] = {}for name, profile_dir in _roster(root):- data = _read_yaml_dict(profile_dir / "profile.yaml") or {}- friendly = (str(data.get("display_name") or ""), str((_bots_meta(data) or {}).get("title") or ""))- for form in set().union(*(alias_forms(f) for f in friendly)):+ for form in set().union(*(alias_forms(f) for f in _friendly_names(profile_dir))):aliases.setdefault(form, set()).add(name)return aliasesdiff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.mdindex 281e6e30296..30ab3cbdb5a 100644--- a/website/docs/user-guide/bot-mode.md+++ b/website/docs/user-guide/bot-mode.md@@ -153,7 +153,7 @@ Bots message each other with attribution, and you can hand work off from any cha- **@mentions** — type `@researcher have a look at this` in any chat and the composer's `@` autocomplete helps you pick the right Bot; on send, the mention is resolved against the live roster and the active Bot is told exactly who you mean (profile, friendly name, and device for cross-connection Bots). The Bot then composes its own message and sends it with `message_agent` — your text is never forwarded verbatim, and the reply comes back attributed to that agent. An email address or an unknown `@` passes through untouched. Bots on other connected machines are reachable the same way: the Desktop relays the message over that connection's own socket (see *Bots across machines* below).- **Renamed Bots keep their tags in sync** — give a Bot a friendly name (the pencil in its chat header, or `hermes profile rename`) and it becomes taggable by that name: a Bot titled *Research Buddy* answers to `@research-buddy` (and `@researchbuddy`), in regular chats and in group rooms alike. The composer's `@` autocomplete offers the renamed tag and also matches when you type the old profile name, which keeps resolving too. This includes the primary Bot: rename it *Maia* and group-turn prompts introduce it as `@maia`, its inter-agent messages sign as `Message from 🤖 Maia (@hermes)`, and teammates can `message_agent(target="maia")` it — `@hermes` stays a working alias.-- **Direct messages** — every Bot Chat carries the `message_agent` tool: a Bot messages a teammate by calling `message_agent(target="researcher", message="…")`. The tool validates the target against the live roster, prefixes the sender's `Message from 🤖 <sender> (@<sender>):` attribution automatically, and delivers into the teammate's canonical Bot Chat. Delivery is **fire-and-forget**: the sender gets an acknowledgement, finishes its turn, and the reply arrives later as a background completion notification. The message travels as a real parameter (nothing shell-interpreted — quotes, `$(...)`, and backticks arrive verbatim), and the Bot composes its own message rather than forwarding your words. The teammate roster — names **and roles** from each profile's title/description — is part of every Bot Chat's system prompt, so Bots know who does what before choosing a recipient. The tool exists **only** in canonical Bot Chat sessions on Bot-Mode-managed installs; regular chats, group-room member sessions, and CLI sessions never see it.+- **Direct messages** — every Bot Chat carries the `message_agent` tool: a Bot messages a teammate by calling `message_agent(target="researcher", message="…")`. The target is the teammate's profile name, its friendly name (`hermes profile rename` or the Bot Mode title — `Scribe`, `Dr. Foo`) or the `@`-tag the Desktop inserts for it (`@scribe`, `@dr-foo`, `@drfoo`); `@hermes` always means the primary Bot. A profile name is matched first, so it can never be hijacked by another Bot's friendly name, and a friendly name shared by two Bots is refused with the roster instead of guessing. The tool validates the target against the live roster, prefixes the sender's `Message from 🤖 <friendly name> (@<handle>):` attribution automatically, and delivers into the teammate's canonical Bot Chat. Delivery is **fire-and-forget**: the sender gets an acknowledgement, finishes its turn, and the reply arrives later as a background completion notification. The message travels as a real parameter (nothing shell-interpreted — quotes, `$(...)`, and backticks arrive verbatim), and the Bot composes its own message rather than forwarding your words. The teammate roster — names **and roles** from each profile's title/description — is part of every Bot Chat's system prompt, so Bots know who does what before choosing a recipient. The tool exists **only** in canonical Bot Chat sessions on Bot-Mode-managed installs; regular chats, group-room member sessions, and CLI sessions never see it.Local messages also reach a Bot Chat that stays open in Desktop or the TUI. The receiving backend keeps ownership: it reads durable ingress on its existing notification poller, admits immediately when idle, or waits until the running turn and already queued human prompts finish. A `queued` acknowledgement confirms durable admission, **not** a completed reply. The target profile retains the delivery ID and receipt under `runtime/bot_live_delivery/`; `settled` confirms completion. A crashed or cancelled imported turn is not automatically replayed, and pending work pinned to a departed owner remains inspectable rather than being silently rerun. Do not resend a delivery whose outcome is unknown. Older backends without live-delivery capability retain the existing ownership refusal; restart that backend after upgrading.