diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 25fa8e1..2662e9f 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -296,18 +296,30 @@ def gateway( # Set cron callback (needs agent) async def on_cron_job(job: CronJob) -> str | None: """Execute a cron job through the agent.""" + from nanobot.agent.tools.message import MessageTool + reminder_note = ( + "[Scheduled Task] Timer finished.\n\n" + f"Task '{job.name}' has been triggered.\n" + f"Scheduled instruction: {job.payload.message}" + ) + response = await agent.process_direct( - job.payload.message, + reminder_note, session_key=f"cron:{job.id}", channel=job.payload.channel or "cli", chat_id=job.payload.to or "direct", ) - if job.payload.deliver and job.payload.to: + + message_tool = agent.tools.get("message") + if isinstance(message_tool, MessageTool) and message_tool._sent_in_turn: + return response + + if job.payload.deliver and job.payload.to and response: from nanobot.bus.events import OutboundMessage await bus.publish_outbound(OutboundMessage( channel=job.payload.channel or "cli", chat_id=job.payload.to, - content=response or "" + content=response )) return response cron.on_job = on_cron_job