fix(cron): add optional name parameter to separate job label from message (#2680)

This commit is contained in:
04cb
2026-04-07 13:22:20 +08:00
committed by Xubin Ren
parent 44c7992095
commit f4904c4bdf
2 changed files with 12 additions and 6 deletions
+8 -2
View File
@@ -13,6 +13,10 @@ from nanobot.cron.types import CronJob, CronJobState, CronSchedule
@tool_parameters(
tool_parameters_schema(
action=StringSchema("Action to perform", enum=["add", "list", "remove"]),
name=StringSchema(
"Optional short human-readable label for the job "
"(e.g., 'weather-monitor', 'daily-standup'). Defaults to first 30 chars of message."
),
message=StringSchema(
"Instruction for the agent to execute when the job triggers "
"(e.g., 'Send a reminder to WeChat: xxx' or 'Check system status and report')"
@@ -93,6 +97,7 @@ class CronTool(Tool):
async def execute(
self,
action: str,
name: str | None = None,
message: str = "",
every_seconds: int | None = None,
cron_expr: str | None = None,
@@ -105,7 +110,7 @@ class CronTool(Tool):
if action == "add":
if self._in_cron_context.get():
return "Error: cannot schedule new jobs from within a cron job execution"
return self._add_job(message, every_seconds, cron_expr, tz, at, deliver)
return self._add_job(name, message, every_seconds, cron_expr, tz, at, deliver)
elif action == "list":
return self._list_jobs()
elif action == "remove":
@@ -114,6 +119,7 @@ class CronTool(Tool):
def _add_job(
self,
name: str | None,
message: str,
every_seconds: int | None,
cron_expr: str | None,
@@ -158,7 +164,7 @@ class CronTool(Tool):
return "Error: either every_seconds, cron_expr, or at is required"
job = self._cron.add_job(
name=message[:30],
name=name or message[:30],
schedule=schedule,
message=message,
deliver=deliver,