From bb24a444f425bb5ac8df1ad6ee4d7e2b0ba01a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Tue, 30 Jun 2026 21:51:32 -0400 Subject: [PATCH] Wake thread participants when a human replies without @mentions When a human or board member posts in a thread where agents have previously participated, those agents are now woken even without explicit @mentions. This matches the old version's behavior where any message in a conversation could wake the recipient, enabling natural back-and-forth between humans and agents. --- .../src/main/services/chat-service.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/AgentCompany-New/src/main/services/chat-service.ts b/AgentCompany-New/src/main/services/chat-service.ts index a410795a..d10aba17 100644 --- a/AgentCompany-New/src/main/services/chat-service.ts +++ b/AgentCompany-New/src/main/services/chat-service.ts @@ -141,6 +141,9 @@ export class ChatService { if (!slash || slash.command !== "agent") { this.wakeAgentMentions(input, mentions, id, threadId, now); } + if (input.senderType === "employee" || input.senderType === "board") { + this.wakeThreadParticipants(input, mentions, id, threadId, now); + } this.handoffs.record({ orgId: input.orgId, spaceId: input.spaceId, @@ -224,6 +227,26 @@ export class ChatService { } } + private wakeThreadParticipants(input: SendMessageInput, alreadyMentioned: ResolvedMention[], messageId: string, threadId: string, now: string): void { + if (!input.threadId) return; + const mentionedAgentIds = new Set( + alreadyMentioned.filter((m) => m.target.type === "agent").map((m) => m.target.id), + ); + const participants = this.db.prepare(` + select distinct m.sender_id as agent_id + from chat_messages m + where m.thread_id = ? and m.org_id = ? and m.sender_type = 'agent' and m.deleted_at is null + `).all(input.threadId, input.orgId) as Array<{ agent_id: string }>; + for (const row of participants) { + if (mentionedAgentIds.has(row.agent_id)) continue; + try { + this.agentWake.wakeFromMention(input, row.agent_id, messageId, threadId, now); + } catch { + // Agent may not have an enabled provider. + } + } + } + /** * True once a thread holds MAX_AUTONOMOUS_THREAD_AGENT_TURNS agent messages * since the last human or board message — the point past which agent↔agent