feat: add dispatcher_model setting to choose utility or chat model for email routing

linuztx committed Mar 17, 2026 at 00:46 UTC 2d2e82ea25605d64dde8e9ea9d42932b450cb4fe
3 files changed +28 -1
plugins/_email_integration/default_config.yaml
+1
@@ -15,5 +15,6 @@ handlers: []
15 # process_unread_days: 0
16 # sender_whitelist: []
17 # project: ""
18 +# dispatcher_model: utility
19 # dispatcher_instructions: ""
20 # agent_instructions: ""
plugins/_email_integration/helpers/handler.py
+13 -1
@@ -202,6 +202,17 @@ async def _dispatch_message(agent: Agent, handler_cfg: dict, msg: InboundMessage
202 _send_notification(msg, "new_chat", reason=reason)
203
204
205 +async def _call_model(
206 + agent: Agent, handler_cfg: dict, system: str, prompt: str,
207 +):
208 + if handler_cfg.get("dispatcher_model", "utility") == "chat":
209 + from langchain_core.messages import SystemMessage, HumanMessage
210 + messages = [SystemMessage(content=system), HumanMessage(content=prompt)]
211 + response, _ = await agent.call_chat_model(messages)
212 + return response
213 + return await agent.call_utility_model(system=system, message=prompt)
214 +
215 +
216 async def _call_dispatcher(
217 agent: Agent,
218 handler_cfg: dict,
@@ -228,8 +239,9 @@ async def _call_dispatcher(
239 system = agent.read_prompt("fw.email.dispatcher_system.md")
240
241 try:
231 - response = await agent.call_utility_model(system=system, message=prompt)
242 + response = await _call_model(agent, handler_cfg, system, prompt)
243 return disp.parse_dispatcher_response(str(response))
244 +
245 except Exception as e:
246 PrintStyle.error(f"Dispatcher error: {format_error(e)}")
247 return disp.DispatchDecision(action="new_chat", reason="dispatcher error")
plugins/_email_integration/webui/config.html
+14
@@ -27,6 +27,7 @@
27 process_unread_days: 0,
28 sender_whitelist: [],
29 project: '',
30 + dispatcher_model: 'utility',
31 dispatcher_instructions: '',
32 agent_instructions: ''
33 });
@@ -234,6 +235,19 @@
235 </div>
236 </div>
237
238 + <div class="field">
239 + <div class="field-label">
240 + <div class="field-title">Dispatcher Model</div>
241 + <div class="field-description">LLM model used to route incoming emails to chats. Utility is faster, chat is more capable</div>
242 + </div>
243 + <div class="field-control">
244 + <select x-model="handler.dispatcher_model">
245 + <option value="utility">Utility</option>
246 + <option value="chat">Chat</option>
247 + </select>
248 + </div>
249 + </div>
250 +
251 <div class="field">
252 <div class="field-label">
253 <div class="field-title">Dispatcher Instructions</div>