feat: add cron scheduled task service with tool_use integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
crispyberry
2026-02-09 01:02:33 +08:00
committed by Bo
parent 680f41133a
commit dbab65bd47
10 changed files with 744 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
#include "tools/tool_web_search.h"
#include "tools/tool_get_time.h"
#include "tools/tool_files.h"
#include "tools/tool_cron.h"
#include <string.h>
#include "esp_log.h"
@@ -9,7 +10,7 @@
static const char *TAG = "tools";
#define MAX_TOOLS 8
#define MAX_TOOLS 12
static mimi_tool_t s_tools[MAX_TOOLS];
static int s_tool_count = 0;
@@ -130,6 +131,50 @@ esp_err_t tool_registry_init(void)
};
register_tool(&ld);
/* Register cron_add */
mimi_tool_t ca = {
.name = "cron_add",
.description = "Schedule a recurring or one-shot task. The message will trigger an agent turn when the job fires.",
.input_schema_json =
"{\"type\":\"object\","
"\"properties\":{"
"\"name\":{\"type\":\"string\",\"description\":\"Short name for the job\"},"
"\"schedule_type\":{\"type\":\"string\",\"description\":\"'every' for recurring interval or 'at' for one-shot at a unix timestamp\"},"
"\"interval_s\":{\"type\":\"integer\",\"description\":\"Interval in seconds (required for 'every')\"},"
"\"at_epoch\":{\"type\":\"integer\",\"description\":\"Unix timestamp to fire at (required for 'at')\"},"
"\"message\":{\"type\":\"string\",\"description\":\"Message to inject when the job fires, triggering an agent turn\"},"
"\"channel\":{\"type\":\"string\",\"description\":\"Optional reply channel (e.g. 'telegram'). Defaults to 'system'\"},"
"\"chat_id\":{\"type\":\"string\",\"description\":\"Optional reply chat_id. Defaults to 'cron'\"}"
"},"
"\"required\":[\"name\",\"schedule_type\",\"message\"]}",
.execute = tool_cron_add_execute,
};
register_tool(&ca);
/* Register cron_list */
mimi_tool_t cl = {
.name = "cron_list",
.description = "List all scheduled cron jobs with their status, schedule, and IDs.",
.input_schema_json =
"{\"type\":\"object\","
"\"properties\":{},"
"\"required\":[]}",
.execute = tool_cron_list_execute,
};
register_tool(&cl);
/* Register cron_remove */
mimi_tool_t cr = {
.name = "cron_remove",
.description = "Remove a scheduled cron job by its ID.",
.input_schema_json =
"{\"type\":\"object\","
"\"properties\":{\"job_id\":{\"type\":\"string\",\"description\":\"The 8-character job ID to remove\"}},"
"\"required\":[\"job_id\"]}",
.execute = tool_cron_remove_execute,
};
register_tool(&cr);
build_tools_json();
ESP_LOGI(TAG, "Tool registry initialized");