fix(agent): message tool incorrectly replies to original chat when targeting different chat_id

When the message tool is used to send a message to a different chat_id

than the current conversation, it was incorrectly including the default

message_id from the original context. This caused channels like Feishu

to send the message as a reply to the original chat instead of creating

a new message in the target chat.

Changes:

- Only use default message_id when chat_id matches the default context

- When targeting a different chat, set message_id to None to avoid

  unintended reply behavior
This commit is contained in:
WormW 2026-03-25 17:37:56 +08:00 committed by Xubin Ren
parent 7e719f41cc
commit 6973bfff24

View File

@ -86,7 +86,13 @@ class MessageTool(Tool):
) -> str:
channel = channel or self._default_channel
chat_id = chat_id or self._default_chat_id
message_id = message_id or self._default_message_id
# Only use default message_id if chat_id matches the default context.
# If targeting a different chat, don't reply to the original message.
if chat_id == self._default_chat_id:
message_id = message_id or self._default_message_id
else:
# Targeting a different chat - don't use default message_id
message_id = None
if not channel or not chat_id:
return "Error: No target channel/chat specified"
@ -101,7 +107,7 @@ class MessageTool(Tool):
media=media or [],
metadata={
"message_id": message_id,
},
} if message_id else {},
)
try: