Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
revert: restore message.py to tanishra baseline (out of scope)
Alexander Minges36d650e47560
diff --git a/nanobot/agent/tools/message.py b/nanobot/agent/tools/message.pyindex 7cac933b2..385372587 100644--- a/nanobot/agent/tools/message.py+++ b/nanobot/agent/tools/message.py@@ -1,6 +1,6 @@"""Message tool for sending messages to users."""-from typing import Any, Awaitable, Callable+from typing import Any, Callable, Awaitablefrom nanobot.agent.tools.base import Toolfrom nanobot.bus.events import OutboundMessage@@ -8,91 +8,87 @@ from nanobot.bus.events import OutboundMessageclass MessageTool(Tool):"""Tool to send messages to users on chat channels."""-+def __init__(- self,+ self,send_callback: Callable[[OutboundMessage], Awaitable[None]] | None = None,default_channel: str = "",- default_chat_id: str = "",+ default_chat_id: str = ""):self._send_callback = send_callbackself._default_channel = default_channelself._default_chat_id = default_chat_id-+def set_context(self, channel: str, chat_id: str) -> None:"""Set the current message context."""self._default_channel = channelself._default_chat_id = chat_id-+def set_send_callback(self, callback: Callable[[OutboundMessage], Awaitable[None]]) -> None:"""Set the callback for sending messages."""self._send_callback = callback-+@propertydef name(self) -> str:return "message"-+@propertydef description(self) -> str:- return (- "Send a message to the user. Supports optional media/attachment "- "paths for channels that can send files."- )-+ return "Send a message to the user. Use this when you want to communicate something."+@propertydef parameters(self) -> dict[str, Any]:return {"type": "object","properties": {- "content": {"type": "string", "description": "The message content to send"},+ "content": {+ "type": "string",+ "description": "The message content to send"+ },"channel": {"type": "string",- "description": "Optional: target channel (telegram, discord, etc.)",+ "description": "Optional: target channel (telegram, discord, etc.)"},- "chat_id": {"type": "string", "description": "Optional: target chat/user ID"},- "media": {- "type": "array",- "description": "Optional: local file paths to send as attachments",- "items": {"type": "string"},+ "chat_id": {+ "type": "string",+ "description": "Optional: target chat/user ID"},- "chat_id": {"type": "string", "description": "Optional: target chat/user ID"},"media": {"type": "array","items": {"type": "string"},- "description": "Optional: list of file paths to attach (images, audio, documents)",- },+ "description": "Optional: list of file paths to attach (images, audio, documents)"+ }},- "required": ["content"],+ "required": ["content"]}-+async def execute(- self,- content: str,- channel: str | None = None,+ self,+ content: str,+ channel: str | None = None,chat_id: str | None = None,media: list[str] | None = None,- **kwargs: Any,+ **kwargs: Any) -> str:channel = channel or self._default_channelchat_id = chat_id or self._default_chat_id-+if not channel or not chat_id:return "Error: No target channel/chat specified"-+if not self._send_callback:return "Error: Message sending not configured"-- media_paths: list[str] = []- for item in media or []:- if isinstance(item, str):- candidate = item.strip()- if candidate:- media_paths.append(candidate)-- msg = OutboundMessage(channel=channel, chat_id=chat_id, content=content, media=media_paths)-++ msg = OutboundMessage(+ channel=channel,+ chat_id=chat_id,+ content=content,+ media=media or []+ )+try:await self._send_callback(msg)- return f"Message sent to {channel}:{chat_id}"+ media_info = f" with {len(media)} attachments" if media else ""+ return f"Message sent to {channel}:{chat_id}{media_info}"except Exception as e:return f"Error sending message: {str(e)}"