The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(cron): offer NO_REPLY only to conditional scheduled runs
oxoxDev484208601a31
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_context.rs b/crates/openhuman-core/src/cron/scheduler/origin_context.rsindex 6159244b21..71496dca52 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_context.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_context.rs@@ -1,7 +1,9 @@//! The prompt of a `session_target: current` run: a fresh session that is shown//! a bounded tail of the conversation that created the job, plus a fixed-//! preamble saying the run is unattended.+//! preamble saying the run is unattended. Only a job whose prompt opts into+//! silence ([`job_allows_no_reply`]) is offered `NO_REPLY`.+use super::origin_delivery::job_allows_no_reply;use crate::config::Config;use crate::core::runtime::DispatchCtx;use {@@ -14,8 +16,12 @@ pub(crate) const CONTEXT_MAX_MESSAGES: usize = 10;/// At most this many characters across the whole tail; the newest are kept.pub(crate) const CONTEXT_MAX_CHARS: usize = 1400;-/// Fixed preamble for an unattended scheduled run.-pub(crate) const UNATTENDED_PREAMBLE: &str = "This is a scheduled run, not a live chat. Your final reply is delivered to the user as-is. If there is nothing worth sending, reply exactly NO_REPLY.";+/// Preamble for an unattended run that must deliver: the user asked to+/// receive this message.+pub(crate) const DELIVERING_PREAMBLE: &str = "This is a scheduled run, not a live chat. The user asked to receive this message, and your final reply is delivered to them as-is. Always reply with the message itself.";++/// Preamble for an unattended run whose task allows sending nothing.+pub(crate) const CONDITIONAL_PREAMBLE: &str = "This is a scheduled run, not a live chat. Your final reply is delivered to the user as-is. When the task's condition is not met, reply exactly NO_REPLY.";/// Render the newest messages that fit within `max_messages` / `max_chars` as/// `role: text` lines, oldest first. A message that does not fit whole is cut@@ -89,10 +95,22 @@ async fn origin_messages(}}-/// Prompt for a `current` run: tagged task, unattended preamble, the bounded-/// context tail (when there is one), then the task itself.-pub(crate) fn compose_current_prompt(job_id: &str, name: &str, prompt: &str, tail: &str) -> String {- let mut out = format!("[cron:{job_id} {name}] {UNATTENDED_PREAMBLE}\n\n");+/// Prompt for a `current` run: tagged task, unattended preamble (the+/// conditional one when `allows_no_reply`), the bounded context tail (when+/// there is one), then the task itself.+pub(crate) fn compose_current_prompt(+ job_id: &str,+ name: &str,+ prompt: &str,+ tail: &str,+ allows_no_reply: bool,+) -> String {+ let preamble = if allows_no_reply {+ CONDITIONAL_PREAMBLE+ } else {+ DELIVERING_PREAMBLE+ };+ let mut out = format!("[cron:{job_id} {name}] {preamble}\n\n");if !tail.is_empty() {out.push_str("Recent conversation this task was created in (context only):\n");out.push_str(tail);@@ -129,12 +147,14 @@ pub(crate) async fn build_run_prompt(}None => String::new(),};+ let allows_no_reply = job_allows_no_reply(job);tracing::debug!(job_id = %job.id,tail_chars = tail.chars().count(),+ allows_no_reply,"[cron] composed current-session prompt");- compose_current_prompt(&job.id, name, &prompt, &tail)+ compose_current_prompt(&job.id, name, &prompt, &tail, allows_no_reply)}}}diff --git a/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rsindex a75d50acd0..d77f4d7961 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_context_tests.rs@@ -45,12 +45,82 @@ fn tail_skips_empty_and_non_chat_roles() {#[test]fn current_prompt_has_preamble_context_and_task() {- let p = compose_current_prompt("j1", "water", "drink water", "user: hi");+ let p = compose_current_prompt("j1", "water", "drink water", "user: hi", false);assert!(p.starts_with("[cron:j1 water] "));- assert!(p.contains(UNATTENDED_PREAMBLE));- assert!(p.contains("NO_REPLY"));+ assert!(p.contains(DELIVERING_PREAMBLE));assert!(p.contains("user: hi"));assert!(p.ends_with("Scheduled task: drink water"));- let bare = compose_current_prompt("j1", "water", "drink water", "");+ let bare = compose_current_prompt("j1", "water", "drink water", "", false);assert!(!bare.contains("Recent conversation"));}++#[test]+fn only_the_conditional_preamble_offers_no_reply() {+ assert!(!DELIVERING_PREAMBLE.contains("NO_REPLY"));+ assert!(CONDITIONAL_PREAMBLE.contains("NO_REPLY"));+ let delivering = compose_current_prompt("j1", "water", "drink water", "", false);+ assert!(!delivering.contains("NO_REPLY"));+ let conditional =+ compose_current_prompt("j1", "inbox", "reply NO_REPLY if nothing changed", "", true);+ assert!(conditional.contains(CONDITIONAL_PREAMBLE));+}++fn current_job(prompt: &str) -> CronJob {+ use tinyflows_bus::schedule::types::{DeliveryConfig, JobType, Schedule, SessionTarget};+ CronJob {+ claim_generation: 0,+ policy: Default::default(),+ id: "job-1".into(),+ expression: "*/5 * * * *".into(),+ schedule: Schedule::Every { every_ms: 300_000 },+ command: String::new(),+ prompt: Some(prompt.into()),+ name: Some("task".into()),+ job_type: JobType::Agent,+ session_target: SessionTarget::Current,+ model: None,+ agent_id: None,+ enabled: true,+ delivery: DeliveryConfig {+ mode: "origin".into(),+ channel: None,+ to: None,+ best_effort: true,+ },+ delete_after_run: false,+ created_at: chrono::Utc::now(),+ next_run: chrono::Utc::now(),+ last_run: None,+ last_status: None,+ last_output: None,+ origin: None,+ }+}++#[tokio::test]+async fn a_reminder_runs_with_the_delivering_preamble() {+ let tmp = tempfile::TempDir::new().unwrap();+ let config = Config {+ workspace_dir: tmp.path().to_path_buf(),+ ..Config::default()+ };+ let ctx = DispatchCtx::ambient();+ let reminder = build_run_prompt(+ &ctx,+ &config,+ ¤t_job("Remind the user to drink water"),+ "task",+ )+ .await;+ assert!(reminder.contains(DELIVERING_PREAMBLE), "{reminder}");+ assert!(!reminder.contains("NO_REPLY"), "{reminder}");++ let check = build_run_prompt(+ &ctx,+ &config,+ ¤t_job("Check the inbox; reply NO_REPLY if nothing changed"),+ "task",+ )+ .await;+ assert!(check.contains(CONDITIONAL_PREAMBLE), "{check}");+}