Wake agents on @mention in chat messages

Agents were deaf to @mentions — only /agent slash commands triggered a
task_run. Now ChatService.sendMessage auto-wakes every mentioned agent
(skipping self-mentions and /agent which already handles it) by creating
a queued task_run through ChatAgentWakeService.wakeFromMention.
This commit is contained in:
ZacharyZhang-NY committed 2026-06-07 17:20:58 -04:00
1 parent abe578b1a0
commit 44f31b49fb
2 files changed
+48

No files matched your search

@@ -138,6 +138,9 @@ export class ChatService {
recordChatMentions(this.db, id, mentions);
const slashResultRef = slash ? this.executeSlashCommand(input, space, sender, mentions, attachments, slash, id, threadId, now) : null;
if (slash) this.recordSlashInvocation(id, slash, slashResultRef, now);
if (!slash || slash.command !== "agent") {
this.wakeAgentMentions(input, mentions, id, threadId, now);
}
this.handoffs.record({
orgId: input.orgId,
spaceId: input.spaceId,
@@ -358,6 +361,19 @@ export class ChatService {
`).run(createId("slash"), messageId, slash.command, JSON.stringify({ raw: slash.args }), resultRef, now);
}
private wakeAgentMentions(input: SendMessageInput, mentions: ResolvedMention[], messageId: string, threadId: string, now: string): void {
const agentMentions = mentions.filter(
(m) => m.target.type === "agent" && !(input.senderType === "agent" && input.senderId === m.target.id),
);
for (const mention of agentMentions) {
try {
this.agentWake.wakeFromMention(input, mention.target.id, messageId, threadId, now);
} catch {
// Agent may lack an enabled provider or service identity; skip silently.
}
}
}
private requireSpace(orgId: string, spaceId: string): SpaceRow {
const space = this.db.prepare("select id, org_id, visibility, space_type from chat_spaces where id = ? and org_id = ?")
.get(spaceId, orgId) as SpaceRow | undefined;