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(macos): remove trailing brace in test file
Steven Enamakelf01fefc22a20
diff --git a/crates/openhuman-app/src/native_notifications/macos/native_notifications_tests.rs b/crates/openhuman-app/src/native_notifications/macos/native_notifications_tests.rsindex c7c5492a4e..52c0caac3e 100644--- a/crates/openhuman-app/src/native_notifications/macos/native_notifications_tests.rs+++ b/crates/openhuman-app/src/native_notifications/macos/native_notifications_tests.rs@@ -43,4 +43,3 @@ fn unbundled_executable_is_rejected() {"/tmp/openhuman/target/debug/OpenHuman")));}-}diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rsnew file mode 100644index 0000000000..6ce078a2ad--- /dev/null+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/phase_exec.rs@@ -0,0 +1,377 @@+//! `run_phase` step: fan a phase's agents out on the intra-phase tinyagents+//! graph, aggregate outcomes, and persist the new phase state.++use std::sync::atomic::{AtomicBool, Ordering};+use std::sync::Arc;++use anyhow::{anyhow, Result};+use serde_json::{json, Value};+use tinyagents_graph::parallel::{map_reduce, FailurePolicy, ParallelOptions};+use tinyagents_harness::TinyAgentsError;++use tinyagents_session::run_ledger::{get_workflow_run, WorkflowRunStatus};++use super::cancel::lookup_cancel_token;+use super::state::{persist, phase_prompt, set_phase_reason, set_phase_status, upstream_outputs};+use super::state::{PHASE_COMPLETED, PHASE_FAILED, PHASE_RUNNING};+use super::LOG_TARGET;+use super::super::types::{WorkflowDefinition, WorkflowPhase};+use crate::config::Config;++/// One worker's outcome from the intra-phase graph fan-out (see+/// [`execute_phase`]). Rides in the fan-out graph's typed state, so it is `Clone`.+#[derive(Clone)]+struct PhaseWorkerOutcome {+ /// The spawned child's orchestration id, recorded in `child_run_ids`.+ /// `None` when the child was never spawned (cancelled / spawn error).+ orchestration_id: Option<String>,+ /// Completed child's output row appended to the phase outputs.+ output: Option<Value>,+ /// Failure reason when the worker did not complete successfully.+ error: Option<String>,+}++/// Outcome of executing one phase in the `run_phase` step.+pub(crate) enum PhaseExecOutcome {+ /// The phase completed; `spawned` children were launched (added to the+ /// run-wide `max_children` tally). Route back to `dispatch`.+ Continue { spawned: u32 },+ /// The run reached a terminal status (already persisted) — route to `done`.+ Terminated,+}++/// `run_phase` step: mark the phase running, fan its agents out on the+/// intra-phase tinyagents graph (bounded by `default_concurrency`, capped by the+/// run-wide `max_children` budget), aggregate outcomes, and persist the new+/// phase state. Returns [`PhaseExecOutcome::Continue`] with the number of+/// children spawned, or [`PhaseExecOutcome::Terminated`] when the phase failed or+/// cancellation landed mid-phase (the terminal status is persisted first).+#[allow(clippy::too_many_arguments)]+pub(crate) async fn execute_phase(+ config: &Config,+ run_id: &str,+ definition: &WorkflowDefinition,+ session: &crate::agent::orchestration::AgentOrchestrationSession,+ cancel: &Arc<AtomicBool>,+ model_override: Option<String>,+ phase: &WorkflowPhase,+ total_spawned: u32,+) -> Result<PhaseExecOutcome> {+ use crate::agent::orchestration::{+ OrchestrationTaskStatus, SpawnAgentRequest, WaitAgentOptions,+ };++ // Reload so the phase state we mutate + persist is the latest projection.+ let run = get_workflow_run(&config.workspace_dir, run_id)?+ .ok_or_else(|| anyhow!("workflow run {run_id} vanished mid-phase"))?;+ let mut phase_states = run.phase_states.clone();+ let mut child_run_ids = run.child_run_ids.clone();+ // Children launched *this* phase (the reducer delta added to `total_spawned`).+ let mut spawned_this_phase: u32 = 0;++ log::debug!(+ target: LOG_TARGET,+ "[workflow_run_engine] phase.start run={run_id} phase={} agents={} spawned_so_far={}",+ phase.name,+ phase.agent_ids.len(),+ total_spawned+ );+ set_phase_status(&mut phase_states, &phase.name, PHASE_RUNNING, None);+ persist(+ config,+ &run,+ phase_states.clone(),+ child_run_ids.clone(),+ WorkflowRunStatus::Running,+ None,+ false,+ )?;++ // Thread prior phases' outputs into this phase's prompt context.+ let upstream_context = upstream_outputs(definition, phase, &phase_states);++ // Run the phase's agents on a tinyagents graph fan-out (dispatch ->+ // parallel worker nodes bounded by `default_concurrency` -> collect+ // barrier), never exceeding the run-wide `max_children` cap. Each worker+ // spawns one child and waits for its terminal status; outcomes return in+ // phase order.+ let mut phase_outputs: Vec<Value> = Vec::new();+ let mut phase_failed: Option<String> = None;++ let concurrency = definition.default_concurrency.max(1) as usize;+ let budget_left = definition.max_children.saturating_sub(total_spawned);++ if budget_left == 0 {+ phase_failed = Some(format!(+ "max_children cap ({}) reached before phase '{}' completed",+ definition.max_children, phase.name+ ));+ } else {+ // Cap this phase to the run-wide `max_children` budget; if the phase+ // needs more workers than the budget allows we run as many as fit+ // and then fail with the cap message (matching the legacy loop).+ let capacity = budget_left as usize;+ let phase_agents = phase.agent_ids.to_vec();+ let capped = phase_agents.len() > capacity;+ let to_run: Vec<(usize, String)> = phase_agents+ .into_iter()+ .take(capacity)+ .enumerate()+ .collect();++ // Clones moved into the (`'static`) worker closure.+ let session_for_workers = session.clone();+ let cancel_for_workers = cancel.clone();+ let run_input = run.input.clone();+ let phase_owned = phase.clone();+ let upstream_owned = upstream_context.clone();+ let model_for_workers = model_override.clone();++ tracing::debug!(+ target: "orchestration",+ workers = to_run.len(),+ max_concurrency = concurrency,+ "[orchestration] running parallel fan-out on tinyagents map_reduce (workflow:{run_id}:{})",+ phase_owned.name+ );+ let expected_outcomes = to_run.len();+ let mut options = ParallelOptions::default()+ .with_max_concurrency(concurrency)+ .with_failure_policy(FailurePolicy::CollectAll);+ if let Some(token) = lookup_cancel_token(run_id) {+ options = options.with_cancellation(token);+ }+ let outcome = match map_reduce(to_run, options, move |_node, (agent_index, agent_id)| {+ let session = session_for_workers.clone();+ let cancel = cancel_for_workers.clone();+ let run_input = run_input.clone();+ let phase = phase_owned.clone();+ let upstream = upstream_owned.clone();+ let model = model_for_workers.clone();+ async move {+ // Don't launch new children once cancellation has landed.+ if cancel.load(Ordering::SeqCst) {+ return Ok(PhaseWorkerOutcome {+ orchestration_id: None,+ output: None,+ error: Some("cancelled before spawn".to_string()),+ });+ }+ let prompt = phase_prompt(&run_input, &phase, agent_index, &upstream);+ let resp = match session+ .spawn_agent(SpawnAgentRequest {+ agent_id: agent_id.clone(),+ prompt,+ model,+ ..Default::default()+ })+ .await+ {+ Ok(resp) => resp,+ Err(err) => {+ return Ok(PhaseWorkerOutcome {+ orchestration_id: None,+ output: None,+ error: Some(format!("spawn failed for agent '{agent_id}': {err}")),+ });+ }+ };+ let oid = resp.orchestration_id.clone();+ let wait = match session+ .wait_agents(WaitAgentOptions {+ orchestration_ids: vec![oid.clone()],+ timeout_ms: None,+ })+ .await+ {+ Ok(w) => w,+ Err(err) => {+ return Ok(PhaseWorkerOutcome {+ orchestration_id: Some(oid),+ output: None,+ error: Some(format!("wait_agents failed: {err}")),+ });+ }+ };+ Ok(match wait.agents.into_iter().next() {+ Some(s) => match s.status {+ OrchestrationTaskStatus::Completed => PhaseWorkerOutcome {+ orchestration_id: Some(oid),+ output: Some(json!({+ "orchestrationId": s.orchestration_id,+ "agentId": s.agent_id,+ "output": s.result_summary.clone().unwrap_or_default(),+ })),+ error: None,+ },+ OrchestrationTaskStatus::Failed+ | OrchestrationTaskStatus::Cancelled+ | OrchestrationTaskStatus::CancelRequested+ | OrchestrationTaskStatus::TimedOut+ | OrchestrationTaskStatus::Abandoned => PhaseWorkerOutcome {+ orchestration_id: Some(oid),+ output: None,+ error: Some(format!(+ "child '{}' (agent '{}') ended {}: {}",+ s.orchestration_id,+ s.agent_id,+ serde_json::to_value(s.status)+ .ok()+ .and_then(|v| v.as_str().map(str::to_string))+ .unwrap_or_else(|| "non-completed".to_string()),+ s.error.clone().unwrap_or_default()+ )),+ },+ OrchestrationTaskStatus::Pending+ | OrchestrationTaskStatus::Running+ | OrchestrationTaskStatus::Awaiting => PhaseWorkerOutcome {+ orchestration_id: Some(oid),+ output: None,+ error: Some(format!(+ "child '{}' returned non-terminal status",+ s.orchestration_id+ )),+ },+ },+ None => PhaseWorkerOutcome {+ orchestration_id: Some(oid),+ output: None,+ error: Some("child returned no snapshot".to_string()),+ },+ })+ }+ })+ .await+ {+ Ok(outcome) => outcome,+ Err(TinyAgentsError::Cancelled) => {+ log::debug!(+ target: LOG_TARGET,+ "[workflow_run_engine] phase.cancelled_by_sdk run={run_id} phase={}",+ phase.name+ );+ session.abort_all().await;+ persist(+ config,+ &run,+ phase_states,+ child_run_ids,+ WorkflowRunStatus::Interrupted,+ None,+ false,+ )?;+ return Ok(PhaseExecOutcome::Terminated);+ }+ Err(err) => return Err(anyhow!("workflow fan-out failed: {err}")),+ };++ let mut outcomes = Vec::with_capacity(expected_outcomes);+ for item in outcome.outcomes {+ match item.result {+ Ok(value) => outcomes.push(value),+ Err(err) => {+ return Err(anyhow!(+ "workflow fan-out: worker {} failed: {err}",+ item.index+ ));+ }+ }+ }+ if outcomes.len() != expected_outcomes {+ return Err(anyhow!(+ "workflow fan-out: expected {expected_outcomes} result(s), got {}",+ outcomes.len()+ ));+ }++ // Aggregate worker outcomes in phase order: record every spawned+ // child id, collect completed outputs, and surface the first failure.+ for outcome in outcomes {+ if let Some(oid) = outcome.orchestration_id {+ spawned_this_phase += 1;+ child_run_ids.push(oid);+ }+ match outcome.output {+ Some(out) => phase_outputs.push(out),+ None => {+ if phase_failed.is_none() {+ phase_failed = outcome.error;+ }+ }+ }+ }++ // Cancellation landed mid-phase: abort stragglers and interrupt.+ if cancel.load(Ordering::SeqCst) {+ session.abort_all().await;+ persist(+ config,+ &run,+ phase_states,+ child_run_ids,+ WorkflowRunStatus::Interrupted,+ None,+ false,+ )?;+ return Ok(PhaseExecOutcome::Terminated);+ }++ if capped && phase_failed.is_none() {+ phase_failed = Some(format!(+ "max_children cap ({}) reached before phase '{}' completed",+ definition.max_children, phase.name+ ));+ }+ }++ if let Some(reason) = phase_failed {+ log::warn!(+ target: LOG_TARGET,+ "[workflow_run_engine] phase.failed run={run_id} phase={} reason={reason}",+ phase.name+ );+ set_phase_status(+ &mut phase_states,+ &phase.name,+ PHASE_FAILED,+ Some(json!([])),+ );+ set_phase_reason(&mut phase_states, &phase.name, &reason);+ persist(+ config,+ &run,+ phase_states,+ child_run_ids,+ WorkflowRunStatus::Failed,+ Some(reason),+ true,+ )?;+ return Ok(PhaseExecOutcome::Terminated);+ }++ log::debug!(+ target: LOG_TARGET,+ "[workflow_run_engine] phase.done run={run_id} phase={} outputs={}",+ phase.name,+ phase_outputs.len()+ );+ set_phase_status(+ &mut phase_states,+ &phase.name,+ PHASE_COMPLETED,+ Some(Value::Array(phase_outputs)),+ );+ persist(+ config,+ &run,+ phase_states,+ child_run_ids,+ WorkflowRunStatus::Running,+ None,+ false,+ )?;++ Ok(PhaseExecOutcome::Continue {+ spawned: spawned_this_phase,+ })+}diff --git a/crates/openhuman-core/src/integrations/composio/schemas/registry.rs b/crates/openhuman-core/src/integrations/composio/schemas/registry.rsnew file mode 100644index 0000000000..2705423fe4--- /dev/null+++ b/crates/openhuman-core/src/integrations/composio/schemas/registry.rs@@ -0,0 +1,149 @@+//! [`all_controller_schemas`] and [`all_registered_controllers`]: the two+//! flat lists — one method name per line — that wire every `composio.*`+//! [`super::definitions::schemas`] entry to its handler and register it+//! with the shared controller registry.++use crate::core::ControllerSchema;+use crate::core::all::RegisteredController;++use super::definitions::schemas;+use super::handlers_connections::{+ handle_authorize, handle_clear_api_key, handle_delete_connection, handle_get_mode,+ handle_list_agent_ready_toolkits, handle_list_capabilities, handle_list_connections,+ handle_list_toolkits, handle_set_api_key,+};+use super::handlers_identity::{+ handle_get_user_profile, handle_get_user_scopes, handle_refresh_all_identities, handle_sync,+ handle_set_user_scopes,+};+use super::handlers_tools::{handle_execute, handle_list_tools};+use super::handlers_triggers::{+ handle_create_trigger, handle_disable_trigger, handle_enable_trigger,+ handle_list_available_triggers, handle_list_github_repos, handle_list_trigger_history,+ handle_list_triggers,+};++pub fn all_controller_schemas() -> Vec<ControllerSchema> {+ vec![+ schemas("list_toolkits"),+ schemas("list_capabilities"),+ schemas("list_agent_ready_toolkits"),+ schemas("list_connections"),+ schemas("authorize"),+ schemas("delete_connection"),+ schemas("list_tools"),+ schemas("execute"),+ schemas("list_github_repos"),+ schemas("create_trigger"),+ schemas("get_user_profile"),+ schemas("refresh_all_identities"),+ schemas("sync"),+ schemas("list_trigger_history"),+ schemas("get_user_scopes"),+ schemas("set_user_scopes"),+ schemas("list_available_triggers"),+ schemas("list_triggers"),+ schemas("enable_trigger"),+ schemas("disable_trigger"),+ schemas("get_mode"),+ schemas("set_api_key"),+ schemas("clear_api_key"),+ ]+}++pub fn all_registered_controllers() -> Vec<RegisteredController> {+ vec![+ RegisteredController {+ schema: schemas("list_toolkits"),+ handler: handle_list_toolkits,+ },+ RegisteredController {+ schema: schemas("list_capabilities"),+ handler: handle_list_capabilities,+ },+ RegisteredController {+ schema: schemas("list_agent_ready_toolkits"),+ handler: handle_list_agent_ready_toolkits,+ },+ RegisteredController {+ schema: schemas("list_connections"),+ handler: handle_list_connections,+ },+ RegisteredController {+ schema: schemas("authorize"),+ handler: handle_authorize,+ },+ RegisteredController {+ schema: schemas("delete_connection"),+ handler: handle_delete_connection,+ },+ RegisteredController {+ schema: schemas("list_tools"),+ handler: handle_list_tools,+ },+ RegisteredController {+ schema: schemas("execute"),+ handler: handle_execute,+ },+ RegisteredController {+ schema: schemas("list_github_repos"),+ handler: handle_list_github_repos,+ },+ RegisteredController {+ schema: schemas("create_trigger"),+ handler: handle_create_trigger,+ },+ RegisteredController {+ schema: schemas("get_user_profile"),+ handler: handle_get_user_profile,+ },+ RegisteredController {+ schema: schemas("refresh_all_identities"),+ handler: handle_refresh_all_identities,+ },+ RegisteredController {+ schema: schemas("sync"),+ handler: handle_sync,+ },+ RegisteredController {+ schema: schemas("list_trigger_history"),+ handler: handle_list_trigger_history,+ },+ RegisteredController {+ schema: schemas("get_user_scopes"),+ handler: handle_get_user_scopes,+ },+ RegisteredController {+ schema: schemas("set_user_scopes"),+ handler: handle_set_user_scopes,+ },+ RegisteredController {+ schema: schemas("list_available_triggers"),+ handler: handle_list_available_triggers,+ },+ RegisteredController {+ schema: schemas("list_triggers"),+ handler: handle_list_triggers,+ },+ RegisteredController {+ schema: schemas("enable_trigger"),+ handler: handle_enable_trigger,+ },+ RegisteredController {+ schema: schemas("disable_trigger"),+ handler: handle_disable_trigger,+ },+ RegisteredController {+ schema: schemas("get_mode"),+ handler: handle_get_mode,+ },+ RegisteredController {+ schema: schemas("set_api_key"),+ handler: handle_set_api_key,+ },+ RegisteredController {+ schema: schemas("clear_api_key"),+ handler: handle_clear_api_key,+ },+ ]+}