refactor: simplify message tool suppress — bool check instead of target tracking
This commit is contained in:
@@ -444,18 +444,7 @@ class AgentLoop:
|
||||
self._save_turn(session, all_msgs, 1 + len(history))
|
||||
self.sessions.save(session)
|
||||
|
||||
suppress_final_reply = False
|
||||
if message_tool := self.tools.get("message"):
|
||||
if isinstance(message_tool, MessageTool):
|
||||
sent_targets = set(message_tool.get_turn_sends())
|
||||
suppress_final_reply = (msg.channel, msg.chat_id) in sent_targets
|
||||
|
||||
if suppress_final_reply:
|
||||
logger.info(
|
||||
"Skipping final auto-reply because message tool already sent to {}:{} in this turn",
|
||||
msg.channel,
|
||||
msg.chat_id,
|
||||
)
|
||||
if (mt := self.tools.get("message")) and isinstance(mt, MessageTool) and mt._sent_in_turn:
|
||||
return None
|
||||
|
||||
preview = final_content[:120] + "..." if len(final_content) > 120 else final_content
|
||||
|
||||
@@ -20,7 +20,7 @@ class MessageTool(Tool):
|
||||
self._default_channel = default_channel
|
||||
self._default_chat_id = default_chat_id
|
||||
self._default_message_id = default_message_id
|
||||
self._turn_sends: list[tuple[str, str]] = []
|
||||
self._sent_in_turn: bool = False
|
||||
|
||||
def set_context(self, channel: str, chat_id: str, message_id: str | None = None) -> None:
|
||||
"""Set the current message context."""
|
||||
@@ -34,11 +34,7 @@ class MessageTool(Tool):
|
||||
|
||||
def start_turn(self) -> None:
|
||||
"""Reset per-turn send tracking."""
|
||||
self._turn_sends.clear()
|
||||
|
||||
def get_turn_sends(self) -> list[tuple[str, str]]:
|
||||
"""Get (channel, chat_id) targets sent in the current turn."""
|
||||
return list(self._turn_sends)
|
||||
self._sent_in_turn = False
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -105,7 +101,8 @@ class MessageTool(Tool):
|
||||
|
||||
try:
|
||||
await self._send_callback(msg)
|
||||
self._turn_sends.append((channel, chat_id))
|
||||
if channel == self._default_channel and chat_id == self._default_chat_id:
|
||||
self._sent_in_turn = True
|
||||
media_info = f" with {len(media)} attachments" if media else ""
|
||||
return f"Message sent to {channel}:{chat_id}{media_info}"
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user