Skip to content

Agent Zero AI framework

refactor: remove _read_fw helper, add ChatSummary TypedDict to dispatcher

linuztx489a8634f137
diff --git a/plugins/_email_integration/extensions/python/process_chain_end/_55_email_reply.py b/plugins/_email_integration/extensions/python/process_chain_end/_55_email_reply.py
index ac54812d1..e9b279694 100644
--- a/plugins/_email_integration/extensions/python/process_chain_end/_55_email_reply.py
+++ b/plugins/_email_integration/extensions/python/process_chain_end/_55_email_reply.py
@@ -70,8 +70,7 @@ def _extract_last_response(context: AgentContext) -> str:
def _notify_agent_of_failure(
context: AgentContext, error: str, attempt: int,
):
- from plugins._email_integration.helpers.handler import _read_fw
- msg = _read_fw(
+ msg = context.agent0.read_prompt(
"fw.email.send_failed.md", error=error, attempt=str(attempt),
max_retries=str(MAX_SEND_RETRIES),
)
diff --git a/plugins/_email_integration/helpers/dispatcher.py b/plugins/_email_integration/helpers/dispatcher.py
index 06d7aa9b7..e590da51b 100644
--- a/plugins/_email_integration/helpers/dispatcher.py
+++ b/plugins/_email_integration/helpers/dispatcher.py
@@ -6,7 +6,7 @@ No agent deps in pure helpers.
import re
from dataclasses import dataclass
-from typing import Literal
+from typing import Literal, TypedDict
# Pattern for extracting chat thread ID from email subject
# Matches: [a0-xxxxxxxx] at end of subject
@@ -46,13 +46,23 @@ def build_reply_subject(original_subject: str, thread_id: str) -> str:
return f"{clean} [a0-{thread_id}]"
-def build_chat_summary(context_id: str, data: dict) -> dict:
+class ChatSummary(TypedDict):
+ context_id: str
+ thread_id: str
+ sender: str
+ subject: str
+ handler: str
+ history_preview: str
+
+
+def build_chat_summary(context_id: str, data: dict) -> ChatSummary:
return {
"context_id": context_id,
"thread_id": data.get(CTX_EMAIL_THREAD_ID, ""),
"sender": data.get(CTX_EMAIL_SENDER, ""),
"subject": data.get(CTX_EMAIL_SUBJECT, ""),
"handler": data.get(CTX_EMAIL_HANDLER, ""),
+ "history_preview": "",
}
@@ -66,7 +76,7 @@ def truncate_body(body: str) -> str:
return body[:BODY_PREVIEW_MAX_CHARS] + "... (truncated)"
-def format_chats_list(existing_chats: list[dict]) -> str:
+def format_chats_list(existing_chats: list[ChatSummary]) -> str:
if not existing_chats:
return "No existing chats for this handler."
sections = []
diff --git a/plugins/_email_integration/helpers/handler.py b/plugins/_email_integration/helpers/handler.py
index aee723092..86a020a61 100644
--- a/plugins/_email_integration/helpers/handler.py
+++ b/plugins/_email_integration/helpers/handler.py
@@ -36,12 +36,6 @@ PLUGIN_NAME = "_email_integration"
DOWNLOAD_FOLDER = "usr/email/attachments"
STATE_FILE = "usr/email/state.json"
-_PROMPTS_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "prompts")
-
-
-def _read_fw(filename: str, **kwargs: str) -> str:
- return files.read_prompt_file(filename, _directories=[_PROMPTS_DIR], **kwargs)
-
# ------------------------------------------------------------------
# UID state persistence
@@ -217,7 +211,7 @@ async def _call_dispatcher(
agent: Agent,
handler_cfg: dict,
msg: InboundMessage,
- existing_chats: list[dict],
+ existing_chats: list[disp.ChatSummary],
) -> disp.DispatchDecision:
body_preview = disp.truncate_body(msg.body)
chats_text = disp.format_chats_list(existing_chats)
@@ -318,7 +312,7 @@ async def _route_to_chat(
HISTORY_PREVIEW_MAX_CHARS: int = 500
-def _find_handler_chats(handler_name: str, sender: str) -> list[dict]:
+def _find_handler_chats(handler_name: str, sender: str) -> list[disp.ChatSummary]:
results = []
for ctx_id, ctx in AgentContext._contexts.items():
if not isinstance(ctx, AgentContext):