The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(cron): continuity=true/false flag as the user-facing surface for self-context
Teknium2e7a46cc2774
diff --git a/tests/cron/test_cron_context_from.py b/tests/cron/test_cron_context_from.pyindex fcc5046ab0c..46c5ccff8fd 100644--- a/tests/cron/test_cron_context_from.py+++ b/tests/cron/test_cron_context_from.py@@ -317,3 +317,126 @@ class TestSelfContext:assert get_job(job["id"])["context_from"] == ["self"]+class TestContinuityFlag:+ """continuity=true/false is the user-facing surface for self-context.++ It translates to the reserved 'self' entry in context_from internally.+ """++ def test_create_with_continuity_true(self, cron_env):+ from tools.cronjob_tools import cronjob+ from cron.jobs import get_job+ import json++ result = json.loads(cronjob(+ action="create",+ prompt="Scan for news",+ schedule="every 1h",+ continuity=True,+ ))+ assert result["success"] is True+ assert get_job(result["job_id"])["context_from"] == ["self"]++ def test_create_continuity_false_is_noop(self, cron_env):+ from tools.cronjob_tools import cronjob+ from cron.jobs import get_job+ import json++ result = json.loads(cronjob(+ action="create",+ prompt="Scan",+ schedule="every 1h",+ continuity=False,+ ))+ assert result["success"] is True+ assert get_job(result["job_id"]).get("context_from") is None++ def test_create_continuity_combines_with_context_from(self, cron_env):+ from cron.jobs import create_job, get_job+ from tools.cronjob_tools import cronjob+ import json++ upstream = create_job(prompt="Collect", schedule="every 1h")+ result = json.loads(cronjob(+ action="create",+ prompt="Digest",+ schedule="every 2h",+ context_from=upstream["id"],+ continuity=True,+ ))+ assert result["success"] is True+ stored = get_job(result["job_id"])["context_from"]+ assert upstream["id"] in stored+ assert "self" in stored++ def test_update_continuity_true_adds_self(self, cron_env):+ from cron.jobs import create_job, get_job+ from tools.cronjob_tools import cronjob+ import json++ job = create_job(prompt="Scan", schedule="every 1h")+ result = json.loads(cronjob(+ action="update",+ job_id=job["id"],+ continuity=True,+ ))+ assert result["success"] is True+ assert get_job(job["id"])["context_from"] == ["self"]++ def test_update_continuity_false_removes_self_preserves_others(self, cron_env):+ from cron.jobs import create_job, get_job+ from tools.cronjob_tools import cronjob+ import json++ upstream = create_job(prompt="Collect", schedule="every 1h")+ job = create_job(+ prompt="Digest",+ schedule="every 2h",+ context_from=["self", upstream["id"]],+ )+ result = json.loads(cronjob(+ action="update",+ job_id=job["id"],+ continuity=False,+ ))+ assert result["success"] is True+ assert get_job(job["id"])["context_from"] == [upstream["id"]]++ def test_update_continuity_true_idempotent(self, cron_env):+ from cron.jobs import create_job, get_job+ from tools.cronjob_tools import cronjob+ import json++ job = create_job(prompt="Scan", schedule="every 1h", context_from="self")+ result = json.loads(cronjob(+ action="update",+ job_id=job["id"],+ continuity=True,+ ))+ assert result["success"] is True+ assert get_job(job["id"])["context_from"] == ["self"]++ def test_continuity_job_gets_previous_output(self, cron_env):+ """End-to-end: a continuity-created job injects its own prior output."""+ from tools.cronjob_tools import cronjob+ from cron.jobs import get_job, OUTPUT_DIR+ from cron.scheduler import _build_job_prompt+ import json++ result = json.loads(cronjob(+ action="create",+ prompt="Scan for news",+ schedule="every 1h",+ continuity=True,+ ))+ job = get_job(result["job_id"])+ out_dir = OUTPUT_DIR / job["id"]+ out_dir.mkdir(parents=True, exist_ok=True)+ (out_dir / "2026-08-01_10-00-00.md").write_text(+ "Reported: story A", encoding="utf-8"+ )+ prompt = _build_job_prompt(job)+ assert "Reported: story A" in prompt+ assert "previous run" in prompt.lower()++diff --git a/tools/cronjob_tools.py b/tools/cronjob_tools.pyindex cf8a8340306..97be43c4d05 100644--- a/tools/cronjob_tools.py+++ b/tools/cronjob_tools.py@@ -1141,6 +1141,30 @@ def _try_dispatch_background_run(return result+def _apply_continuity(+ context_from: Optional[Union[str, List[str]]],+ continuity: bool,+) -> Optional[List[str]]:+ """Translate the ``continuity`` flag into the ``context_from`` list.++ ``continuity=True`` ensures ``"self"`` is present (the job's own previous+ output is injected each run); ``continuity=False`` removes any+ ``"self"``/own-id entry. Other entries are preserved untouched.+ """+ if isinstance(context_from, str):+ refs = [context_from.strip()] if context_from.strip() else []+ elif context_from:+ refs = [str(j).strip() for j in context_from if str(j).strip()]+ else:+ refs = []+ has_self = any(r.lower() == "self" for r in refs)+ if continuity and not has_self:+ refs.append("self")+ elif not continuity and has_self:+ refs = [r for r in refs if r.lower() != "self"]+ return refs or None++def cronjob(action: str,job_id: Optional[str] = None,@@ -1158,6 +1182,7 @@ def cronjob(reason: Optional[str] = None,script: Optional[str] = None,context_from: Optional[Union[str, List[str]]] = None,+ continuity: Optional[bool] = None,enabled_toolsets: Optional[List[str]] = None,workdir: Optional[str] = None,no_agent: Optional[bool] = None,@@ -1232,6 +1257,11 @@ def cronjob(success=False,)+ # continuity=True is sugar for context_from including "self":+ # the job wakes up with its own previous run's output injected.+ if continuity is not None:+ context_from = _apply_continuity(context_from, continuity)+from cron.scheduler import (CronSchedulerRegistrationError,create_job_with_scheduler_registration,@@ -1494,14 +1524,20 @@ def cronjob("clear one before setting the other.",success=False,)- if context_from is not None:+ if context_from is not None or continuity is not None:# Empty string / empty list clears the field; otherwise validate# each referenced job exists before storing. Normalized to a list# (or None) to match the shape stored by create_job().- if isinstance(context_from, str):+ if context_from is None:+ # continuity-only update: start from the job's stored refs.+ existing = job.get("context_from") or []+ refs = [str(j).strip() for j in existing if str(j).strip()]+ elif isinstance(context_from, str):refs = [context_from.strip()] if context_from.strip() else []else:refs = [str(j).strip() for j in context_from if str(j).strip()]+ if continuity is not None:+ refs = _apply_continuity(refs, continuity) or []if refs:from cron.jobs import get_job as _get_jobfor ref_id in refs:@@ -1657,15 +1693,25 @@ Scheduling from cron-run sessions is disabled by default and enabled via cron.al"Optional job ID or list of job IDs whose most recent completed output is ""injected into the prompt as context before each run. ""Use this to chain cron jobs: job A collects data, job B processes it. "- "The special value 'self' injects this job's OWN previous output, giving "- "recurring jobs continuity across runs (dedupe against what was already "- "reported, continue where the last run left off). "- "Each other entry must be a valid job ID (from cronjob action='list'). "+ "Each entry must be a valid job ID (from cronjob action='list'); "+ "for a job's OWN previous output, prefer the `continuity` flag. ""Note: injects the most recent completed output — does not wait for ""upstream jobs running in the same tick. ""On update, pass an empty array to clear."),},+ "continuity": {+ "type": "boolean",+ "description": (+ "When true, this recurring job carries continuity across runs: each run "+ "wakes up with the job's own most recent output injected into its prompt, "+ "so it can dedupe against what was already reported and continue where the "+ "last run left off (scouts, monitors, incremental digests). "+ "First run has no previous output and runs unchanged. "+ "On update, pass false to turn continuity off (other context_from entries "+ "are preserved). Default: false."+ ),+ },"enabled_toolsets": {"type": "array","items": {"type": "string"},@@ -1733,6 +1779,7 @@ registry.register(reason=args.get("reason"),script=args.get("script"),context_from=args.get("context_from"),+ continuity=args.get("continuity"),enabled_toolsets=args.get("enabled_toolsets"),workdir=args.get("workdir"),no_agent=args.get("no_agent"),diff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.mdindex 30efca02ddc..53ae7d92431 100644--- a/website/docs/user-guide/features/cron.md+++ b/website/docs/user-guide/features/cron.md@@ -629,32 +629,31 @@ cronjob(|--------|---------|| Single job ID (string) | `context_from="a1b2c3d4"` || Multiple job IDs (list) | `context_from=["job_a", "job_b"]` |-| The special value `self` | `context_from="self"` |Outputs are concatenated in the order listed.-**Self-context: continuity across runs**+**Continuity: carry the previous run's output**-`context_from="self"` injects the job's *own* most recent output into each run. Recurring jobs normally start every run with amnesia — a news scout re-reports the same stories, a monitor re-alerts on the same condition. With self-context, the job wakes up seeing what it reported last time and can dedupe and continue where it left off:+Set `continuity=true` and the job injects its *own* most recent output into each run. Recurring jobs normally start every run with amnesia — a news scout re-reports the same stories, a monitor re-alerts on the same condition. With continuity on, the job wakes up seeing what it reported last time and can dedupe and continue where it left off:```pythoncronjob(action="create",prompt="Scan HN and arXiv for new agent-tooling papers. Report only items NOT already covered in your previous run's output.",schedule="every 6h",- context_from="self",+ continuity=True,name="Agent Tooling Scout",)```-The first run has no previous output, so the prompt runs as-is. On later runs the previous output is prepended with continuity framing ("avoid repeating what was already reported"). You can combine it with upstream jobs: `context_from=["self", "<other_job_id>"]`.+The first run has no previous output, so the prompt runs as-is. On later runs the previous output is prepended with continuity framing ("avoid repeating what was already reported"). It combines freely with upstream jobs (`context_from=["<other_job_id>"]` plus `continuity=true`), and `continuity=false` on update turns it off while preserving other `context_from` entries. Internally the flag is stored as the reserved `self` entry in `context_from`.**When to use it:**- Multi-stage pipelines (collect → filter → format → deliver)- Dependent tasks where step N's work depends on step N−1's output- Fan-out/fan-in patterns where one job aggregates results from several others-- Recurring scouts/monitors that should dedupe against their own previous report (`context_from="self"`)+- Recurring scouts/monitors that should dedupe against their own previous report (`continuity=true`)## Provider recovery