mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
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 <ccsang@users.noreply.github.com>
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user