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
feat(cron): record the origin of scheduled jobs
Steven Enamakele40140867635
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rsindex 302a55df45..216203d26d 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs@@ -420,7 +420,7 @@ pub(crate) use super::operation_context::tool_context_with_approval;pub use super::operation_context::OpenHumanRunExt;pub(crate) use super::operation_context::{approval_for_tool, dispatch_ctx_for_tool, memory_identity_for_tool, parent_agent_id_for_tool,- sandbox_mode_for_tool, task_recency_window_for_tool, HostOperationContext,+ sandbox_mode_for_tool, task_recency_window_for_tool, turn_origin_for_tool, HostOperationContext,};impl Default for OpenHumanRunContext {diff --git a/crates/openhuman-core/src/cron/origin.rs b/crates/openhuman-core/src/cron/origin.rsindex 9c3e6c1c2a..25f8210ef6 100644--- a/crates/openhuman-core/src/cron/origin.rs+++ b/crates/openhuman-core/src/cron/origin.rs@@ -47,12 +47,11 @@ pub(crate) fn job_origin_from_turn(origin: &AgentTurnOrigin) -> Option<JobOrigin}}-/// The origin a job created by the current turn would record, read from the-/// task-local [`AgentTurnOrigin`]. `None` outside a turn or in a turn with no-/// conversation behind it.-pub fn current_job_origin() -> Option<JobOrigin> {- let origin = turn_origin::current()?;- let job_origin = job_origin_from_turn(&origin);+/// The origin a job created by the turn running under `origin` would record.+/// `None` outside a turn or in a turn with no conversation behind it.+pub fn current_job_origin(origin: Option<&AgentTurnOrigin>) -> Option<JobOrigin> {+ let origin = origin?;+ let job_origin = job_origin_from_turn(origin);tracing::debug!(turn_origin = %origin.class(),captured = job_origin.as_ref().map(JobOrigin::kind_str).unwrap_or("none"),@@ -163,11 +162,10 @@ pub(crate) fn is_self_scoped_agent_job(args: &Value, turn: Option<&AgentTurnOrig}}-/// [`is_self_scoped_agent_job`] against the live turn, with a log line for the-/// decision so an exempted creation is traceable.-pub(crate) fn current_turn_may_skip_approval(args: &Value) -> bool {- let turn = turn_origin::current();- let exempt = is_self_scoped_agent_job(args, turn.as_ref());+/// [`is_self_scoped_agent_job`] against the turn running under `turn`, with a+/// log line for the decision so an exempted creation is traceable.+pub(crate) fn current_turn_may_skip_approval(args: &Value, turn: Option<&AgentTurnOrigin>) -> bool {+ let exempt = is_self_scoped_agent_job(args, turn);if exempt {tracing::debug!("[cron] self-scoped agent job from channel turn; skipping approval gate");}diff --git a/crates/openhuman-core/src/cron/tools/add.rs b/crates/openhuman-core/src/cron/tools/add.rsindex 4ddee53483..5ebcf062cc 100644--- a/crates/openhuman-core/src/cron/tools/add.rs+++ b/crates/openhuman-core/src/cron/tools/add.rs@@ -80,7 +80,14 @@ impl Tool for CronAddTool {// asked for it needs no approval: the asker is the sole recipient and// its runs stay gated as that channel's turns. Everything else keeps// the unconditional gate above.- !current_turn_may_skip_approval(args)+ // The trait predicate carries no run context, so it reads the calling+ // task's turn scope.+ !current_turn_may_skip_approval(+ args,+ crate::core::runtime::DispatchCtx::ambient_turn()+ .turn_origin()+ .as_ref(),+ )}async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {@@ -93,6 +100,16 @@ impl Tool for CronAddTool {args: serde_json::Value,options: ToolCallOptions,) -> anyhow::Result<ToolResult> {+ self.execute_with_context(args, options, None).await+ }++ async fn execute_with_context(+ &self,+ args: serde_json::Value,+ options: ToolCallOptions,+ tool_context: Option<&dyn tinytools::ToolRunContext>,+ ) -> anyhow::Result<ToolResult> {+ let origin = crate::agent::tinyagents::host::run_context::turn_origin_for_tool(tool_context);if !self.config.cron.enabled {return Ok(ToolResult::error("cron is disabled by config (cron.enabled=false)".to_string(),@@ -228,7 +245,7 @@ impl Tool for CronAddTool {delivery,delete_after_run,},- current_job_origin(),+ current_job_origin(origin.as_ref()),).map_err(anyhow::Error::msg)}diff --git a/crates/openhuman-core/src/tools/impl/system/schedule.rs b/crates/openhuman-core/src/tools/impl/system/schedule.rsindex 33d4b2c8c9..5332e23232 100644--- a/crates/openhuman-core/src/tools/impl/system/schedule.rs+++ b/crates/openhuman-core/src/tools/impl/system/schedule.rs@@ -65,7 +65,14 @@ impl Tool for ScheduleTool {match args.get("action").and_then(|v| v.as_str()) {Some("list") | Some("get") => false,Some("create") | Some("add") | Some("once") => {- !current_turn_may_skip_approval(&schedule_args_as_cron_add(args))+ // The trait predicate carries no run context, so it reads the+ // calling task's turn scope.+ !current_turn_may_skip_approval(+ &schedule_args_as_cron_add(args),+ crate::core::runtime::DispatchCtx::ambient_turn()+ .turn_origin()+ .as_ref(),+ )}_ => true,}