Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(cron): corrective turn asks only for the message, with tools off (#8212)

oxoxDeveb0fd2023426
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index 9c3d94d57a..83fc36ccdc 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -217,10 +217,9 @@ pub(super) async fn run_agent_job_for_run(
}
}
-/// The line a corrective turn adds when a job that must deliver answered
-/// `NO_REPLY`.
-pub(super) const NO_REPLY_CORRECTION: &str =
- "NO_REPLY is not allowed for this task; write the message to send now.";
+/// The whole prompt of a corrective turn: a delivery request only, never the
+/// job prompt, so an action the first turn took is not asked for again.
+pub(super) const NO_REPLY_CORRECTION: &str = "Your last reply was NO_REPLY, which is not allowed for this task. Write the message to send to the user now. Do not call tools or repeat any action.";
/// Run the scheduled turn. A job that must deliver and answers `NO_REPLY`
/// (or nothing) gets one corrective turn; if that still yields no message the
@@ -241,8 +240,18 @@ async fn run_with_corrective_turn(
run_id = %run_id,
"[cron] run answered NO_REPLY but the job must deliver; running a corrective turn"
);
- let corrective = format!("{prompt}\n\n{NO_REPLY_CORRECTION}");
- let response = Box::pin(run_cron_turn(agent, context, job, run_id, &corrective)).await?;
+ agent.set_next_turn_overrides(crate::agent::session_host::TurnOverrides {
+ suppress_tools: true,
+ ..Default::default()
+ });
+ let response = Box::pin(run_cron_turn(
+ agent,
+ context,
+ job,
+ run_id,
+ NO_REPLY_CORRECTION,
+ ))
+ .await?;
if !needs_correction(&response) {
return Ok(response);
}
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run_tests.rs b/crates/openhuman-core/src/cron/scheduler/agent_run_tests.rs
index d18b2103ef..899a41d132 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run_tests.rs
@@ -145,6 +145,18 @@ mod corrective_turn {
.collect()
}
+ fn last_user_message(body: &str) -> String {
+ let body: serde_json::Value = serde_json::from_str(body).unwrap();
+ body["messages"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .rev()
+ .find(|m| m["role"] == "user")
+ .map(|m| m["content"].as_str().unwrap_or_default().to_string())
+ .unwrap_or_default()
+ }
+
async fn run(
job: CronJob,
first: &'static str,
@@ -180,7 +192,8 @@ mod corrective_turn {
assert_eq!(outcome, (true, "Time to drink water!".to_string()));
assert_eq!(chats.len(), 2, "{chats:#?}");
assert!(!chats[0].contains(NO_REPLY_CORRECTION));
- assert!(chats[1].contains(NO_REPLY_CORRECTION), "{}", chats[1]);
+ assert_eq!(last_user_message(&chats[1]), NO_REPLY_CORRECTION);
+ assert!(last_user_message(&chats[0]).contains("drink water"));
});
}