Skip to content

Agent Zero AI framework

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

linuztx2d2e82ea2560
diff --git a/plugins/_email_integration/default_config.yaml b/plugins/_email_integration/default_config.yaml
index 121555b24..e6f4e20ad 100644
--- a/plugins/_email_integration/default_config.yaml
+++ b/plugins/_email_integration/default_config.yaml
@@ -15,5 +15,6 @@ handlers: []
# process_unread_days: 0
# sender_whitelist: []
# project: ""
+# dispatcher_model: utility
# dispatcher_instructions: ""
# agent_instructions: ""
diff --git a/plugins/_email_integration/helpers/handler.py b/plugins/_email_integration/helpers/handler.py
index a2a9265b3..aee723092 100644
--- a/plugins/_email_integration/helpers/handler.py
+++ b/plugins/_email_integration/helpers/handler.py
@@ -202,6 +202,17 @@ async def _dispatch_message(agent: Agent, handler_cfg: dict, msg: InboundMessage
_send_notification(msg, "new_chat", reason=reason)
+async def _call_model(
+ agent: Agent, handler_cfg: dict, system: str, prompt: str,
+):
+ if handler_cfg.get("dispatcher_model", "utility") == "chat":
+ from langchain_core.messages import SystemMessage, HumanMessage
+ messages = [SystemMessage(content=system), HumanMessage(content=prompt)]
+ response, _ = await agent.call_chat_model(messages)
+ return response
+ return await agent.call_utility_model(system=system, message=prompt)
+
+
async def _call_dispatcher(
agent: Agent,
handler_cfg: dict,
@@ -228,8 +239,9 @@ async def _call_dispatcher(
system = agent.read_prompt("fw.email.dispatcher_system.md")
try:
- response = await agent.call_utility_model(system=system, message=prompt)
+ response = await _call_model(agent, handler_cfg, system, prompt)
return disp.parse_dispatcher_response(str(response))
+
except Exception as e:
PrintStyle.error(f"Dispatcher error: {format_error(e)}")
return disp.DispatchDecision(action="new_chat", reason="dispatcher error")
diff --git a/plugins/_email_integration/webui/config.html b/plugins/_email_integration/webui/config.html
index 1967a25ae..eb9cacf0a 100644
--- a/plugins/_email_integration/webui/config.html
+++ b/plugins/_email_integration/webui/config.html
@@ -27,6 +27,7 @@
process_unread_days: 0,
sender_whitelist: [],
project: '',
+ dispatcher_model: 'utility',
dispatcher_instructions: '',
agent_instructions: ''
});
@@ -234,6 +235,19 @@
</div>
</div>
+ <div class="field">
+ <div class="field-label">
+ <div class="field-title">Dispatcher Model</div>
+ <div class="field-description">LLM model used to route incoming emails to chats. Utility is faster, chat is more capable</div>
+ </div>
+ <div class="field-control">
+ <select x-model="handler.dispatcher_model">
+ <option value="utility">Utility</option>
+ <option value="chat">Chat</option>
+ </select>
+ </div>
+ </div>
+
<div class="field">
<div class="field-label">
<div class="field-title">Dispatcher Instructions</div>