fix(automations): unify chat replies and preserve explicit sends

This commit is contained in:
Xubin Ren committed 2026-10-07 01:12:23 +08:00
1 parent 5719ed6e16
commit ab614478a0
25 files changed
+474 -135

No files matched your search

+4 -1
View File
@@ -28,7 +28,10 @@ _CRON_PARAMETERS = tool_parameters_schema(
),
message=StringSchema(
"REQUIRED when action='add'. Instruction for the agent to execute when the job triggers "
"(e.g., 'Send a reminder to WeChat: xxx' or 'Check system status and report'). "
"(e.g., 'Remind me to drink water' or 'Check system status and report'). "
"The final reply goes to the task's saved chat automatically. "
"Do not copy the current channel/chat ID or require a message tool call for that reply. "
"Include other recipients only when the user requests separate sends. "
"Not used for action='list' or action='remove'."
),
every_seconds=IntegerSchema(
+4 -4
View File
@@ -120,10 +120,10 @@ class MessageTool(Tool):
def description(self) -> str:
return (
"Proactively send a message to a user/channel, optionally with file attachments. "
"Use this for reminders, cross-channel delivery, or explicit proactive sends. "
"Do not use this for the normal reply in the current chat: answer naturally instead. "
"If channel/chat_id would target the current runtime conversation, do not call this tool "
"unless the user explicitly asked you to proactively send an existing file attachment. "
"Use this for separate sends requested by the user or task, including sends to multiple chats. "
"For a normal reply, including a scheduled reminder or report, answer naturally instead: "
"nanobot delivers the final reply to the current chat. "
"Follow explicit task instructions that require this tool or name other recipients. "
"When generate_image creates images in the current chat, use the message tool "
"with the artifact paths in the media parameter to deliver the images to the user. "
"For proactive attachment delivery, use the 'media' parameter with file paths. "
+8 -4
View File
@@ -5,14 +5,18 @@ description: Schedule reminders and recurring tasks.
# Cron
Use the `cron` tool to schedule reminders or recurring tasks that should report back to the originating chat/session when they run.
Use the `cron` tool to schedule reminders or recurring tasks. New tasks run in the current chat. nanobot sends the agent's final reply to that chat. The user can change the task's chat in WebUI.
Write what to do in `message`. For a normal reminder or report, do not copy the current channel, chat ID, or instructions to call the `message` tool into the task. For example, use "Remind me to drink water", not "Call message to send to this chat".
If the user asks to send to other chats, preserve those recipients in the task instructions. Use the `message` tool for those sends and for file attachments. Existing tasks that explicitly request a `message` call still use it; changing the task's chat does not change explicit recipients in its instructions.
Do not use `cron` for periodic background checks that should stay quiet when there is nothing useful to report. For those, update `HEARTBEAT.md`; the protected heartbeat job runs those checks and only delivers results that pass the notification gate.
## Three Modes
## Task Types
1. **Reminder** - message is sent directly to user
2. **Task** - message is a task description, agent executes and sends result
1. **Reminder** - the agent replies with the reminder when the task runs
2. **Task** - the agent follows the instructions and replies with the result
3. **One-time** - runs once at a specific time, then auto-deletes
## Examples
+2
View File
@@ -1,6 +1,8 @@
The scheduled time has arrived. Execute this scheduled cron job now and report the result to the user in the same session.
Rules:
- Return the result as a normal reply. nanobot delivers it to this task's saved chat.
- Use the message tool only for file attachments or sends explicitly required by the task. Keep any explicit recipients in the task instructions.
- Speak directly to the user in their language.
- Do not narrate internal progress.
- Do not include user IDs.
+6 -1
View File
@@ -12,6 +12,7 @@ from nanobot.session.manager import (
_metadata_title, # pyright: ignore[reportPrivateUsage]
)
from nanobot.session.session_handles import SessionHandleResolver
from nanobot.utils.helpers import truncate_text
from nanobot.webui.session_identity import is_webui_session_key
from nanobot.webui.workspaces import WebUIWorkspaceController
@@ -48,6 +49,7 @@ def automation_chats(
job.payload.origin_metadata,
)
result: list[AutomationChat] = []
previews = {row["key"]: row.get("preview", "") for row in sessions.list_sessions()}
for handle in SessionHandleResolver(sessions).list_all():
key = handle.session_key
data = sessions.read_session_metadata(key)
@@ -73,7 +75,10 @@ def automation_chats(
if source.metadata() != target.metadata():
continue
result.append(AutomationChat(
id=handle.id, title=_metadata_title(metadata) or f"@{handle.name}",
id=handle.id,
title=(_metadata_title(metadata)
or truncate_text(" ".join(previews.get(key, "").split()), 60)
or f"@{handle.name}"),
binding=CronBinding(key, channel, chat_id, route_metadata),
handle=handle.name,
available=available,