Skip to content

The agent that grows with you

feat(kanban): add in-process schedule tool

fangliquanflq8e00bfdf06d6
diff --git a/tests/tools/test_kanban_tools.py b/tests/tools/test_kanban_tools.py
index 195fbae4eb8..9fb0f172ee1 100644
--- a/tests/tools/test_kanban_tools.py
+++ b/tests/tools/test_kanban_tools.py
@@ -370,6 +370,55 @@ def test_block_happy_path(worker_env):
conn.close()
+def test_schedule_parks_current_worker_with_reason(worker_env):
+ from hermes_cli import kanban_db as kb
+ from hermes_cli import kanban_db_connect as kbc
+ from tools import kanban_tools # noqa: F401 β€” ensure registration
+ from tools.registry import registry
+
+ reason = "SCHEDULED_UNTIL=2026-09-13T00:00:00Z waiting for reconnect"
+ entry = registry.get_entry("kanban_schedule")
+ assert entry is not None and entry.toolset == "kanban"
+ out = json.loads(entry.handler({"reason": reason}))
+
+ assert out == {
+ "ok": True, "task_id": worker_env, "run_id": out["run_id"],
+ "status": "scheduled", "reason": reason,
+ }
+ with kbc.connect() as conn:
+ assert kb.get_task(conn, worker_env).status == "scheduled"
+ run = kb.latest_run(conn, worker_env)
+ assert (run.outcome, run.summary) == ("scheduled", reason)
+ assert any(
+ event.kind == "scheduled" and event.payload == {"reason": reason}
+ for event in kb.list_events(conn, worker_env)
+ )
+
+
+def test_schedule_rejects_invalid_reason_and_unowned_contexts(monkeypatch, worker_env):
+ from hermes_cli import kanban_db as kb
+ from hermes_cli import kanban_db_connect as kbc
+ from tools import kanban_tools as kt
+
+ with kbc.connect() as conn:
+ other = kb.create_task(conn, title="sibling", assignee="peer")
+
+ invalid = json.loads(kt._handle_schedule({"reason": {"until": "tomorrow"}}))
+ foreign = json.loads(kt._handle_schedule({"task_id": other, "reason": "wait"}))
+ monkeypatch.setattr(
+ kt, "_delegation_ctx",
+ lambda predicate, default: predicate == "is_delegated_child_process_context",
+ )
+ delegated = json.loads(kt._handle_schedule({"task_id": worker_env, "reason": "wait"}))
+
+ assert "reason must be a string" in invalid["error"]
+ assert "refusing to mutate" in foreign["error"]
+ assert "delegate_task child agents are not Kanban run owners" in delegated["error"]
+ with kbc.connect() as conn:
+ assert kb.get_task(conn, worker_env).status == "running"
+ assert kb.get_task(conn, other).status == "ready"
+
+
def _make_goal_mode_worker_env(monkeypatch, tmp_path):
"""Set up an isolated HERMES_HOME with one claimed goal_mode task,
matching the pattern used by the kanban_complete judge gate tests."""
diff --git a/tools/kanban_tools.py b/tools/kanban_tools.py
index e0d4a20bda7..4b04e12b209 100644
--- a/tools/kanban_tools.py
+++ b/tools/kanban_tools.py
@@ -24,7 +24,7 @@ from tools.kanban_tools_schemas import (
KANBAN_ATTACH_URL_SCHEMA, KANBAN_ATTACHMENTS_SCHEMA, KANBAN_BLOCK_SCHEMA, KANBAN_COMMENT_SCHEMA,
KANBAN_COMPLETE_SCHEMA, KANBAN_CREATE_SCHEMA, KANBAN_HEARTBEAT_SCHEMA, KANBAN_LINK_SCHEMA,
KANBAN_LIST_SCHEMA, KANBAN_REQUEST_CHANGES_SCHEMA, KANBAN_REQUEST_REVIEW_SCHEMA,
- KANBAN_SHOW_SCHEMA, KANBAN_UNBLOCK_SCHEMA)
+ KANBAN_SCHEDULE_SCHEMA, KANBAN_SHOW_SCHEMA, KANBAN_UNBLOCK_SCHEMA)
logger = logging.getLogger(__name__)
@@ -813,6 +813,20 @@ def _handle_block(args: dict, **kw) -> str:
return _ok_landed(kb, conn, tid, "blocked", **extra)
+@_kanban_handler("kanban_schedule")
+def _handle_schedule(args: dict, **kw) -> str:
+ """Park the current task until an orchestrator re-gates it."""
+ tid = _worker_guard("kanban_schedule", args)
+ raw_reason = args.get("reason")
+ _check(raw_reason is None or isinstance(raw_reason, str), "reason must be a string")
+ reason = _redact(raw_reason.strip()) if raw_reason and raw_reason.strip() else None
+ with _board(args.get("board")) as (kb, conn):
+ ok = kb.schedule_task(
+ conn, tid, reason=reason, expected_run_id=_worker_run_id(tid))
+ _check(ok, f"could not schedule {tid} (unknown id or not in todo/ready/running/blocked)")
+ return _ok_landed(kb, conn, tid, "scheduled", reason=reason)
+
+
@_kanban_handler("kanban_request_review")
def _handle_request_review(args: dict, **kw) -> str:
"""Move implementation into the first-class review phase."""
@@ -1205,6 +1219,7 @@ _TOOLS = (
("kanban_list", KANBAN_LIST_SCHEMA, _handle_list, "πŸ“‹"),
("kanban_complete", KANBAN_COMPLETE_SCHEMA, _handle_complete, "βœ”"),
("kanban_block", KANBAN_BLOCK_SCHEMA, _handle_block, "⏸"),
+ ("kanban_schedule", KANBAN_SCHEDULE_SCHEMA, _handle_schedule, "⏰"),
("kanban_request_review", KANBAN_REQUEST_REVIEW_SCHEMA, _handle_request_review, "πŸ‘€"),
("kanban_request_changes", KANBAN_REQUEST_CHANGES_SCHEMA, _handle_request_changes, "↩"),
("kanban_heartbeat", KANBAN_HEARTBEAT_SCHEMA, _handle_heartbeat, "πŸ’“"),
diff --git a/tools/kanban_tools_schemas.py b/tools/kanban_tools_schemas.py
index f4134e92c67..090c752a019 100644
--- a/tools/kanban_tools_schemas.py
+++ b/tools/kanban_tools_schemas.py
@@ -199,6 +199,26 @@ KANBAN_BLOCK_SCHEMA = _schema(
["reason"],
)
+KANBAN_SCHEDULE_SCHEMA = _schema(
+ "kanban_schedule",
+ (
+ "Park your current task in the 'scheduled' state while it waits for "
+ "time or an external event. This ends the current run and makes the "
+ "task non-dispatchable until an orchestrator unblocks it; it does not "
+ "create a timer. Put any wake-up marker such as "
+ "``SCHEDULED_UNTIL=<ISO8601>`` in ``reason``."
+ ),
+ {
+ "task_id": _prop("string", _DESC_TASK_ID_DEFAULT),
+ "reason": _prop("string", (
+ "Optional reason or machine-readable wake-up marker recorded on "
+ "the completed run and scheduled event."
+ )),
+ },
+ [],
+)
+
+
KANBAN_REQUEST_REVIEW_SCHEMA = _schema(
"kanban_request_review",
(