improve: consistent notification titles, & include dispatcher decision reason
linuztx committed
Mar 16, 2026 at 10:46 UTC
1277c257aa3540cb019e7291d05f455eaebf5c91
1 file changed
+16
-5
plugins/_email_integration/helpers/handler.py
+16
-5
@@ -155,21 +155,27 @@ async def _dispatch_message(agent: Agent, handler_cfg: dict, msg: InboundMessage
155
await _route_to_chat(
156
agent, handler_cfg, msg, chat["context_id"],
157
)
158
+ _send_notification(msg, "continue_chat", chat["context_id"],
159
+ reason="thread ID match")
160
return
161
162
# Dispatcher AI decides
163
decision = await _call_dispatcher(agent, handler_cfg, msg, existing)
164
+ reason = decision.reason or ""
165
166
if decision.action == "continue_chat" and decision.context_id:
167
ctx = AgentContext.get(decision.context_id)
168
if ctx:
169
await _route_to_chat(agent, handler_cfg, msg, decision.context_id)
170
+ _send_notification(msg, "continue_chat", decision.context_id,
171
+ reason=reason)
172
return
173
PrintStyle.warning(
174
f"Dispatcher referenced unknown context {decision.context_id}, starting new chat"
175
)
176
177
await _start_new_chat(agent, handler_cfg, msg)
178
+ _send_notification(msg, "new_chat", reason=reason)
179
180
181
async def _call_dispatcher(
@@ -242,7 +248,6 @@ async def _start_new_chat(agent: Agent, handler_cfg: dict, msg: InboundMessage):
248
))
249
250
PrintStyle.success(f"Email: new chat {context.id} for '{msg.subject}' from {msg.sender}")
245
- _send_notification(msg, "new_chat", context.id)
251
252
253
async def _route_to_chat(
@@ -268,7 +273,6 @@ async def _route_to_chat(
273
274
save_tmp_chat(context)
275
PrintStyle.info(f"Email: continuing chat {context_id}")
271
- _send_notification(msg, "continue_chat", context_id)
276
277
278
# ------------------------------------------------------------------
@@ -413,14 +417,21 @@ def _get_handler_config(handler_name: str) -> dict | None:
417
# Notifications
418
# ------------------------------------------------------------------
419
416
-def _send_notification(msg: InboundMessage, action: str, context_id: str):
420
+def _send_notification(
421
+ msg: InboundMessage,
422
+ action: str,
423
+ context_id: str = "",
424
+ reason: str = "",
425
+):
426
subject = msg.subject[:80] if msg.subject else "(no subject)"
427
if action == "new_chat":
419
- title = "New email session"
428
+ title = "Email: new chat"
429
message = f"From {msg.sender}: {subject}"
430
else:
422
- title = "Email follow-up"
431
+ title = "Email: continuing chat"
432
message = f"From {msg.sender}: {subject} → {context_id}"
433
+ if reason:
434
+ message += f" ({reason})"
435
NotificationManager.send_notification(
436
type=NotificationType.INFO,
437
priority=NotificationPriority.HIGH,