Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Decide the next untagged message again after a routed answer
agent-runner3530ac06f183091
diff --git a/core/switch_core/delivery/conversation.py b/core/switch_core/delivery/conversation.pyindex 2ad9e161e..1eb193c14 100644--- a/core/switch_core/delivery/conversation.py+++ b/core/switch_core/delivery/conversation.py@@ -10,11 +10,11 @@ three rules extend it, each decided from the room's history:person tagged most recently (all of them, when one message tagged several,until one answers).- **Channel follow-up.** A top-level message reaches the agent the sender is- in an unbroken exchange with: the sender addressed the agent (or, in a room- routing by decision, the decision service gave the agent the sender's- message), the agent has answered since, nobody else has posted in between,- the agent's last answer is within the window, and no gap between messages- is longer than it.+ in an unbroken exchange with: the sender addressed the agent, the agent has+ answered since, nobody else has posted in between, the agent's last answer+ is within the window, and no gap between messages is longer than it. A+ message the decision service gave an agent doesn't count as addressing it,+ so the next untagged message in a room routing by decision is decided again.- **Main agent.** In a room whose main agent is set (`!assign-agent`), everymessage reaches it.@@ -50,8 +50,6 @@ from datetime import datetimefrom enum import StrEnumfrom typing import TYPE_CHECKING-from sqlalchemy import select-from switch_core.clients.admin_messages import (ADMIN_MARKER,AUTO_REPLY_FLAG,@@ -59,7 +57,6 @@ from switch_core.clients.admin_messages import (SENDER_IS_APP_MARKER,)from switch_core.clients.mentions import NAME_CHAR-from switch_core.db.models import AgentEventRowfrom switch_core.delivery.addressing import IncomingMessageif TYPE_CHECKING:@@ -309,7 +306,6 @@ class RoomConversation:self._thread_rows: list[Message] | None = Noneself._channel_rows: list[Message] | None = Noneself._agent_names: set[str] | None = None- self._routed: dict[str, set[str | None]] = {}async def decide(self, session: AsyncSession, *, agent: Agent, agent_user_id: str@@ -438,31 +434,6 @@ class RoomConversation:message=_as_incoming(row),)- async def _routed_to(- self, session: AsyncSession, *, agent: Agent, row: Message- ) -> bool:- """Whether the decision service gave `row` to `agent`, which in a room- routing by decision counts as the sender addressing it: the agent was- given the person's message as if it had been tagged. Read once per- agent, for the channel messages the walk reads."""- if not self._auto_route_on:- return False- if agent.id not in self._routed:- rows = await self._channel(session)- self._routed[agent.id] = set(- (- await session.scalars(- select(AgentEventRow.message_key).where(- AgentEventRow.agent_id == agent.id,- AgentEventRow.room_id == self._room_id,- AgentEventRow.room_seq.in_([r.seq for r in rows]),- AgentEventRow.payload["payload"]["routed"].as_boolean(),- )- )- ).all()- )- return row.transport_event_id in self._routed[agent.id]-async def _thread_follow_up(self,session: AsyncSession,@@ -569,7 +540,7 @@ class RoomConversation:return ConversationDecision(None, "no recent exchange with this agent")if await self._addressed_agent(session, agent=agent, agent_user_id=agent_user_id, row=row- ) or await self._routed_to(session, agent=agent, row=row):+ ):if agent_answered:return ConversationDecision(ConversationRoute.CHANNEL_FOLLOW_UP,diff --git a/core/switch_core/delivery/decision.py b/core/switch_core/delivery/decision.pyindex 440299eb5..8fba859e2 100644--- a/core/switch_core/delivery/decision.py+++ b/core/switch_core/delivery/decision.py@@ -23,8 +23,8 @@ order of its messages:call: still in the room, its policy and budget still letting the senderthrough. Then the person's own message is stored as the agent's own event,addressed and marked `routed`, under the message's key and place in the- room, as if the agent had been tagged; so the channel follow-up carries on- after the agent answers.+ room. It doesn't count as the person addressing the agent, so the person's+ next untagged message is decided again rather than followed up.Nobody receives the message when the service names nobody, when it cannot beasked (a timeout, a connection error, an error response or a malformed one:diff --git a/core/tests/switch_core/delivery/test_decision_routing.py b/core/tests/switch_core/delivery/test_decision_routing.pyindex e55694d03..3109abce8 100644--- a/core/tests/switch_core/delivery/test_decision_routing.py+++ b/core/tests/switch_core/delivery/test_decision_routing.py@@ -551,7 +551,7 @@ class TestWhatTheAgentIsGiven:]assert await room.reached(reply) == {"helper"}- async def test_the_channel_follow_up_carries_on_after_a_routed_answer(+ async def test_the_next_channel_message_after_a_routed_answer_is_asked_again(self, room: Journey, service: DecisionService) -> None:service.pick = "helper"@@ -559,11 +559,11 @@ class TestWhatTheAgentIsGiven:await room.post("helper", "It failed on the migration", at=20)service.pick = None- follow_up = await room.say("alice", "can you rerun it?", at=30)+ aside = await room.say("alice", "sara, are you joining standup today?", at=30)assert await room.reached(question) == {"helper"}- assert await room.reached(follow_up) == {"helper"}- assert len(service.requests) == 1+ assert await room.reached(aside) == set()+ assert len(service.requests) == 2class TestTheRoutedPayload: