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(agent): add subagent host for autonomous task execution
Steven Enamakelfa34c77e81dc
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rsindex 2e1a087e16..0e95c2207e 100644--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs@@ -441,6 +441,7 @@ impl SessionHostBuilder {event_session_id,event_channel,task_recency_window: None,+ autonomous_iter_cap: None,thread_id: None,agent_definition_name: agent_definition_name.clone(),// Canonical registry id — captured here at build timediff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rsindex 263b4d2913..702a8e7396 100644--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs@@ -255,6 +255,12 @@ impl OpenHumanSessionHost {self.task_recency_window = window;}+ /// Runs this agent as an unattended autonomous tree: sub-agent iteration+ /// caps are lifted to `cap` on every later turn; `None` clears the lift.+ pub fn set_autonomous_iter_cap(&mut self, cap: Option<usize>) {+ self.autonomous_iter_cap = cap;+ }+pub fn set_event_context(&mut self, session_id: impl Into<String>, channel: impl Into<String>) {self.event_session_id = session_id.into();self.event_channel = channel.into();diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rsindex 94a2727e12..bba3d933b6 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs@@ -20,6 +20,7 @@ impl OpenHumanSessionHost {context.progress = self.on_progress.clone();context.thread_id = self.thread_id.clone();context.task_recency_window = self.task_recency_window;+ context.autonomous_iter_cap = self.autonomous_iter_cap;context.workspace = self.workspace_descriptor.clone();// The web backstop's deadline, when this turn runs under one: the// harness winds down before it instead of being dropped by it.diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rsindex 780c0f5e77..da088df2ec 100644--- a/crates/openhuman-core/src/agent/session_host/types.rs+++ b/crates/openhuman-core/src/agent/session_host/types.rs@@ -289,6 +289,9 @@ pub struct OpenHumanSessionHost {/// task-fetch tools only see recently touched tasks (cron morning/// briefing). `None` leaves them unbounded.pub(super) task_recency_window: Option<std::time::Duration>,+ /// Autonomous skill-run iteration cap handed to every turn's run context+ /// (lifts sub-agent iteration caps); `None` for ordinary agents.+ pub(super) autonomous_iter_cap: Option<usize>,/// Backend/session thread explicitly owned by this agent run. It is kept/// separate from event identity: CLI and worker event sessions are not/// necessarily user conversation threads.diff --git a/crates/openhuman-core/src/agent/subagent_host/autonomous.rs b/crates/openhuman-core/src/agent/subagent_host/autonomous.rsindex 587dc3d23d..baa2d115d8 100644--- a/crates/openhuman-core/src/agent/subagent_host/autonomous.rs+++ b/crates/openhuman-core/src/agent/subagent_host/autonomous.rs@@ -5,44 +5,25 @@//! no `APPROVAL_CHAT_CONTEXT`), and the per-agent iteration cap is lifted so the//! run continues until it's done or the repeated-failure circuit breaker trips.//!-//! The lifted cap rides a `tokio` task-local set around the orchestrator's-//! `run_single`. Sub-agent inner loops are awaited *inline* within that scope-//! (`run_subagent` does not detach), so the task-local reaches them too — one-//! switch covers the whole tree.--use std::future::Future;--tokio::task_local! {- static AUTONOMOUS_ITER_CAP: usize;-}--/// The active autonomous iteration cap, if a skill run scoped one.-pub fn autonomous_iter_cap() -> Option<usize> {- AUTONOMOUS_ITER_CAP.try_with(|c| *c).ok()-}--/// Run `fut` with an autonomous iteration cap in scope. The cap propagates to-/// every agentic loop awaited within — the orchestrator turn and the inline-/// sub-agent loops.-pub async fn with_autonomous_iter_cap<F: Future>(cap: usize, fut: F) -> F::Output {- AUTONOMOUS_ITER_CAP.scope(cap, fut).await-}+//! The lifted cap rides `OpenHumanRunContext::autonomous_iter_cap`, set by+//! `Agent::set_autonomous_iter_cap` and inherited by every child run context,+//! so one switch covers the whole tree./// Lift a sub-agent's per-agent iteration `base` to the active autonomous cap/// when one is in scope (issue #4463).////// Autonomous skill runs scope an-/// [`with_autonomous_iter_cap`] of `TASK_RUN_MAX_ITERATIONS` /+/// `Agent::set_autonomous_iter_cap` of `TASK_RUN_MAX_ITERATIONS` //// `WORKFLOW_RUN_MAX_ITERATIONS` around the whole tree so an unattended run/// continues until it's done or a circuit breaker trips, rather than stopping at/// a specialist sub-agent's normal cap (e.g. 10). The migration to the tinyagents-/// harness dropped every reader of [`autonomous_iter_cap`], so those setters+/// harness dropped every reader of `autonomous_iter_cap`, so those setters/// became dead knobs and sub-agents silently reverted to the normal cap. This is/// the restored reader: sub-agent iteration computations run their/// `effective_max_iterations()` through it so the lift takes effect again. The/// cost budget + repeated-failure breakers remain the primary runaway guards.-pub fn subagent_iter_cap_with_autonomous_lift(base: usize) -> usize {- match autonomous_iter_cap() {+pub fn subagent_iter_cap_with_autonomous_lift(autonomous_cap: Option<usize>, base: usize) -> usize {+ match autonomous_cap {Some(cap) if cap > base => {tracing::debug!(base,diff --git a/crates/openhuman-core/src/agent/subagent_host/mod.rs b/crates/openhuman-core/src/agent/subagent_host/mod.rsindex 10dac40de7..94a6affe16 100644--- a/crates/openhuman-core/src/agent/subagent_host/mod.rs+++ b/crates/openhuman-core/src/agent/subagent_host/mod.rs@@ -55,7 +55,7 @@ mod persisted_compat_tests;// Public API — the entry point and the shapes it returns.pub use autonomous::{- autonomous_iter_cap, subagent_iter_cap_with_autonomous_lift, with_autonomous_iter_cap,+ subagent_iter_cap_with_autonomous_lift,};pub(crate) use lifecycle::load_subagent_checkpoint;pub use lifecycle::{diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex cd919a466a..b6fd8b00e9 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -711,7 +711,10 @@ async fn run_typed_mode(agent_id = %definition.id,model = %model,tool_count = allowed_names.len(),- max_iterations = subagent_iter_cap_with_autonomous_lift(definition.effective_max_iterations()),+ max_iterations = subagent_iter_cap_with_autonomous_lift(+ options.run_context.autonomous_iter_cap,+ definition.effective_max_iterations(),+ ),iteration_policy = ?definition.iteration_policy,"[subagent_host:typed] resolved configuration");@@ -923,7 +926,10 @@ async fn run_typed_mode(Vec::new(),filtered_specs.clone(),allowed_names,- subagent_iter_cap_with_autonomous_lift(definition.effective_max_iterations()),+ subagent_iter_cap_with_autonomous_lift(+ options.run_context.autonomous_iter_cap,+ definition.effective_max_iterations(),+ ),options.run_queue.clone(),parent.on_progress.clone(),&definition.id,diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rsindex 160e23b066..de9c1f17d0 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs@@ -302,6 +302,9 @@ pub struct OpenHumanRunContext {pub dispatch: Option<Arc<TurnDispatchState>>,/// Optional task recency restriction for integration tools.pub task_recency_window: Option<Duration>,+ /// Autonomous skill-run iteration cap lifted onto every sub-agent in the+ /// tree (inherited by `child()` through the clone); `None` for ordinary turns.+ pub autonomous_iter_cap: Option<usize>,/// Sandbox mode of the agent definition executing this turn.pub sandbox_mode: Option<SandboxMode>,/// Zero-based OpenHuman subagent depth (the root is zero).@@ -455,6 +458,7 @@ impl OpenHumanRunContext {attachment_placeholders: Arc::new(Vec::new()),dispatch: None,task_recency_window: None,+ autonomous_iter_cap: None,sandbox_mode: None,spawn_depth: 0,subagent_usage: Arc::new(Mutex::new(Vec::new())),diff --git a/crates/openhuman-core/src/skills/runtime/run_machinery.rs b/crates/openhuman-core/src/skills/runtime/run_machinery.rsindex a9bdd97acd..c282d8a31b 100644--- a/crates/openhuman-core/src/skills/runtime/run_machinery.rs+++ b/crates/openhuman-core/src/skills/runtime/run_machinery.rs@@ -8,7 +8,6 @@use serde_json::Value;use crate::agent::session_host::OpenHumanSessionHost;-use crate::agent::subagent_host::with_autonomous_iter_cap;use crate::config::Config;use crate::skills::{preflight, registry, run_log};@@ -203,6 +202,7 @@ pub async fn spawn_workflow_run_background(// a post-construction override rather than a pre-set on `config`// (which the builder would otherwise clobber).agent.set_max_tool_iterations(WORKFLOW_RUN_MAX_ITERATIONS);+ agent.set_autonomous_iter_cap(Some(WORKFLOW_RUN_MAX_ITERATIONS));tracing::debug!(run_id = %run_id,max_tool_iterations = WORKFLOW_RUN_MAX_ITERATIONS,@@ -238,10 +238,7 @@ pub async fn spawn_workflow_run_background(_ = cancel_token.cancelled() => None,r = crate::agent::turn_origin::with_origin(inherited_origin,- with_autonomous_iter_cap(- WORKFLOW_RUN_MAX_ITERATIONS,- agent.run_single(&task_prompt),- ),+ agent.run_single(&task_prompt),) => Some(r),};agent.set_on_progress(None);