Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(chats): no join line from an agent arriving in a Switch Console chat

raullopez-sandboxcbb8db5905af
diff --git a/core/switch_core/clients/room_meta.py b/core/switch_core/clients/room_meta.py
index f4b19da00..105762c76 100644
--- a/core/switch_core/clients/room_meta.py
+++ b/core/switch_core/clients/room_meta.py
@@ -19,3 +19,6 @@ class RoomMeta(BaseModel):
# `{agent_id, body}`: what that agent says as it joins, in place of its
# usual greeting (a Switch Console chat's opening message).
agent_greeting: dict[str, str] | None = None
+ # A chat started in Switch Console, where an agent arrives without its
+ # join line: the console shows who joined.
+ console_chat: bool = False
diff --git a/core/switch_core/delivery/recipient.py b/core/switch_core/delivery/recipient.py
index 1d29c8b7d..57c2a2ca1 100644
--- a/core/switch_core/delivery/recipient.py
+++ b/core/switch_core/delivery/recipient.py
@@ -982,7 +982,8 @@ class AgentRecipient:
async def greet(self) -> None:
"""Say hello in a room the agent has just arrived in: in the words the
room was given for it when there are some (a Switch Console chat's
- opening message), else its usual line.
+ opening message), else its usual line, except in a Switch Console
+ chat, which says nothing more.
The per-agent greeting can be switched off per bridge: on Mattermost,
for one, whose native "X joined the channel" notice makes it
@@ -1001,6 +1002,8 @@ class AgentRecipient:
opening = opening_message_for(meta, self.agent.id)
if opening is not None:
greeting = opening
+ elif meta.console_chat:
+ return
elif meta.channel_type == "direct":
greeting = f"Hi! I'm {name} — how can I help?"
else:
diff --git a/core/switch_core/delivery/router.py b/core/switch_core/delivery/router.py
index 72109c137..031fb991c 100644
--- a/core/switch_core/delivery/router.py
+++ b/core/switch_core/delivery/router.py
@@ -294,6 +294,7 @@ class RoomReads:
follow_ups_enabled=follow_ups_enabled_in(room.metadata_),
main_agent_id=main_agent_in(room.metadata_),
agent_greeting=(room.metadata_ or {}).get("agent_greeting"),
+ console_chat="chat_operation_id" in (room.metadata_ or {}),
),
group_id=room.group_id,
members=sorted(members, key=lambda member: member.agent.id),
diff --git a/core/tests/switch_core/delivery/test_join_greeting_suppression.py b/core/tests/switch_core/delivery/test_join_greeting_suppression.py
index 34a0f45a7..4631c22fe 100644
--- a/core/tests/switch_core/delivery/test_join_greeting_suppression.py
+++ b/core/tests/switch_core/delivery/test_join_greeting_suppression.py
@@ -24,6 +24,7 @@ def _fake_self(
is_direct: bool = False,
agent_greetings_enabled: bool = True,
agent_greeting: dict[str, str] | None = None,
+ console_chat: bool = False,
) -> SimpleNamespace:
"""The agent arriving in a room, as the router hands it its arrival."""
return SimpleNamespace(
@@ -35,6 +36,7 @@ def _fake_self(
agent_greetings_enabled=agent_greetings_enabled,
channel_type="direct" if is_direct else "channel_private",
agent_greeting=agent_greeting,
+ console_chat=console_chat,
),
_room=_ROOM,
actor=SimpleNamespace(send_message=send_message),
@@ -112,6 +114,30 @@ async def test_a_greeting_written_for_another_agent_is_not_said() -> None:
assert send_message.calls[0]["body"].startswith("Hi! I'm cc-bug-fixing")
+async def test_a_console_chat_gets_no_join_line() -> None:
+ for is_direct in (True, False):
+ send_message = _Recorder()
+ await AgentRecipient.greet(
+ _fake_self(send_message, is_direct=is_direct, console_chat=True) # type: ignore[arg-type]
+ )
+ assert send_message.calls == []
+
+
+async def test_a_console_chat_still_opens_with_its_written_greeting() -> None:
+ send_message = _Recorder()
+ await AgentRecipient.greet(
+ _fake_self( # type: ignore[arg-type]
+ send_message,
+ is_direct=True,
+ console_chat=True,
+ agent_greeting={"agent_id": "agent-1", "body": "Welcome!"},
+ )
+ )
+ assert [call["body"] for call in send_message.calls] == ["Welcome!"]
+
+
def test_the_opening_message_is_told_only_to_the_agent_it_was_written_for() -> None:
meta = SimpleNamespace(agent_greeting={"agent_id": "agent-1", "body": "Welcome!"})
assert opening_message_for(meta, "agent-1") == "Welcome!" # type: ignore[arg-type]