From a73e388927ee45b225dbd14b4ad02522da262054 Mon Sep 17 00:00:00 2001 From: qingyun Date: Tue, 31 Mar 2026 17:08:42 +0800 Subject: [PATCH] fix(agent): improve send_message_to_user tool description to prevent misuse (#6424) * fix(agent): improve send_message_to_user tool description to prevent misuse Fixes #6402 The AI was inappropriately using send_message_to_user tool in normal conversations for text replies, causing duplicate messages (once via tool, once via normal response). Root cause: Tool description was not clear enough about when to use it. Changes: - Restructure description with clear sections using markdown - Emphasize two valid use cases: 1. Sending media files (image, record, video, file) in any conversation 2. Proactive messaging scenarios (cron jobs, background tasks) - Add explicit warning: Do NOT use for normal text replies - Explain consequence: Using for text causes duplicate messages This approach (better documentation) is safer than restricting tool registration, which would break media file sending in normal conversations. Alternative to PR #6413 which was closed due to breaking media delivery. * fix: correct syntax error and use triple-quoted string for description Address review feedback: - P0: Add missing closing parenthesis (was causing SyntaxError on import) - Use triple-quoted string for better readability (suggested by gemini-code-assist) - Remove explicit newline characters, let Python handle line breaks --------- Co-authored-by: ccsang --- astrbot/core/astr_main_agent_resources.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/astrbot/core/astr_main_agent_resources.py b/astrbot/core/astr_main_agent_resources.py index f89184bbc..1b2d52f7a 100644 --- a/astrbot/core/astr_main_agent_resources.py +++ b/astrbot/core/astr_main_agent_resources.py @@ -83,12 +83,13 @@ class KnowledgeBaseQueryTool(FunctionTool[AstrAgentContext]): @dataclass class SendMessageToUserTool(FunctionTool[AstrAgentContext]): name: str = "send_message_to_user" - description: str = ( - "Send message to the user. " - "Supports various message types including `plain`, `image`, `record`, `video`, `file`, and `mention_user`. " - "Use this tool to send media files (`image`, `record`, `video`, `file`), " - "or when you need to proactively message the user(such as cron job). For normal text replies, you can output directly." - ) + description: str = """Send message to the user. Supports various message types including `plain`, `image`, `record`, `video`, `file`, and `mention_user`. + +**IMPORTANT**: This tool is designed for: +1. Sending media files (`image`, `record`, `video`, `file`) in any conversation +2. Proactive messaging scenarios (e.g., cron jobs, background task notifications) + +**Do NOT use this tool for normal text replies in regular conversations** - just output your text directly instead. Using this tool for text in normal conversations will cause duplicate messages (once via tool, once via normal response).""" parameters: dict = Field( default_factory=lambda: {