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
chore(orchestration): apply rustfmt formatting across subagent modules
Steven Enamakelfe9509a582d6
diff --git a/crates/openhuman-core/src/agent/orchestration/delegation.rs b/crates/openhuman-core/src/agent/orchestration/delegation.rsindex 124c9cd845..c4d75f6a40 100644--- a/crates/openhuman-core/src/agent/orchestration/delegation.rs+++ b/crates/openhuman-core/src/agent/orchestration/delegation.rs@@ -100,61 +100,61 @@ pub(crate) async fn run_subagent_delegation_with_parent_context(let workspace_descriptor = parent_workspace_descriptor.clone();let stage_parent = stage_parent.clone();async move {- let prompt = build_stage_prompt(stage, &task, &state);- let (stage_parent, stage_context) =- stage_run_contexts(&stage_parent, workspace_descriptor.clone())- .map_err(|error| format!("delegation stage context: {error}"))?;- match run_subagent_via_driver_tool(- &stage_parent,- definition,- prompt.clone(),- delegation_subagent_options(workspace_descriptor, stage_context),- )- .await- {- Ok((outcome, _public_job_id)) => {- let should_emit_lifecycle_effects = outcome.should_emit_lifecycle_effects();- match outcome.status {- SubagentRunStatus::Completed => {}- SubagentRunStatus::AwaitingUser {- question,- checkpoint,- ..- } => {- // A durable delegation graph cannot safely advance- // plan/review state while one of its stages is- // paused. Surface the exact durable child handle so- // the caller can continue that stage instead of- // silently stranding the checkpoint behind a generic- // graph error.- if should_emit_lifecycle_effects {- let parent_session = stage_parent- .data- .parent- .as_ref()- .map(|parent| parent.session_id.clone())- .unwrap_or_else(|| "standalone".to_string());- crate::agent::orchestration::subagent_events::publish_subagent_awaiting_user(+ let prompt = build_stage_prompt(stage, &task, &state);+ let (stage_parent, stage_context) =+ stage_run_contexts(&stage_parent, workspace_descriptor.clone())+ .map_err(|error| format!("delegation stage context: {error}"))?;+ match run_subagent_via_driver_tool(+ &stage_parent,+ definition,+ prompt.clone(),+ delegation_subagent_options(workspace_descriptor, stage_context),+ )+ .await+ {+ Ok((outcome, _public_job_id)) => {+ let should_emit_lifecycle_effects = outcome.should_emit_lifecycle_effects();+ match outcome.status {+ SubagentRunStatus::Completed => {}+ SubagentRunStatus::AwaitingUser {+ question,+ checkpoint,+ ..+ } => {+ // A durable delegation graph cannot safely advance+ // plan/review state while one of its stages is+ // paused. Surface the exact durable child handle so+ // the caller can continue that stage instead of+ // silently stranding the checkpoint behind a generic+ // graph error.+ if should_emit_lifecycle_effects {+ let parent_session = stage_parent+ .data+ .parent+ .as_ref()+ .map(|parent| parent.session_id.clone())+ .unwrap_or_else(|| "standalone".to_string());+ crate::agent::orchestration::subagent_events::publish_subagent_awaiting_user(parent_session,outcome.task_id.clone(),outcome.agent_id.clone(),question.clone(),);- if let Some(progress) = stage_parent.data.progress.clone() {- let _ = progress- .send(AgentProgress::SubagentAwaitingUser {- agent_id: outcome.agent_id.clone(),- task_id: outcome.task_id.clone(),- question: question.clone(),- worker_thread_id: None,- checkpoint_path: checkpoint- .as_ref()- .map(|path| path.to_string_lossy().to_string()),- })- .await;- }+ if let Some(progress) = stage_parent.data.progress.clone() {+ let _ = progress+ .send(AgentProgress::SubagentAwaitingUser {+ agent_id: outcome.agent_id.clone(),+ task_id: outcome.task_id.clone(),+ question: question.clone(),+ worker_thread_id: None,+ checkpoint_path: checkpoint+ .as_ref()+ .map(|path| path.to_string_lossy().to_string()),+ })+ .await;}- return Err(format!(+ }+ return Err(format!("[SUBAGENT_AWAITING_USER]\nagent_id: {}\ntask_id: {}\nquestion: {}\ncheckpointed: {}\n[/SUBAGENT_AWAITING_USER]\n\delegation stage {stage:?} is awaiting user input; relay the answer with continue_subagent using this task_id.",outcome.agent_id,@@ -164,106 +164,104 @@ pub(crate) async fn run_subagent_delegation_with_parent_context(}),checkpoint.is_some(),));- }- SubagentRunStatus::Incomplete { reason } => {- return Err(format!(- "delegation stage {stage:?} stopped incomplete: {reason}"- ));- }- SubagentRunStatus::Cancelled => {- return Err(format!("delegation stage {stage:?} was cancelled"));- }}- let approved = matches!(stage, DelegationStage::Review)- && review_approves(&outcome.output);- Ok(DelegationStageOutput {- text: outcome.output,- approved,- // Persist the exact prompt this stage sent so the- // execute step's `StepRecord` carries its provenance- // (read only for the execute stage; #3884).- prompt: Some(prompt),- })+ SubagentRunStatus::Incomplete { reason } => {+ return Err(format!(+ "delegation stage {stage:?} stopped incomplete: {reason}"+ ));+ }+ SubagentRunStatus::Cancelled => {+ return Err(format!("delegation stage {stage:?} was cancelled"));+ }}- Err(e) => Err(format!("delegation stage {stage:?} failed: {e}")),+ let approved = matches!(stage, DelegationStage::Review)+ && review_approves(&outcome.output);+ Ok(DelegationStageOutput {+ text: outcome.output,+ approved,+ // Persist the exact prompt this stage sent so the+ // execute step's `StepRecord` carries its provenance+ // (read only for the execute stage; #3884).+ prompt: Some(prompt),+ })}+ Err(e) => Err(format!("delegation stage {stage:?} failed: {e}")),+ }}};let config_checkpointer = Arc::clone(&checkpointer);let config_thread_id = thread_id.clone();- let config_factory = move |_state: &(), parent: &RunContext<OpenHumanRunContext>, _args: &serde_json::Value| {- let mut delegation_config = DelegationConfig {- max_revisions,- checkpointer: Some(Arc::clone(&config_checkpointer)),- thread_id: Some(config_thread_id.clone()),- cancel: parent.cancellation.clone(),- // Automated delegation: preserve the host's existing worker-output- // review policy while the generic tool owns graph lifecycle mechanics.- ..DelegationConfig::default()+ let config_factory =+ move |_state: &(), parent: &RunContext<OpenHumanRunContext>, _args: &serde_json::Value| {+ let mut delegation_config = DelegationConfig {+ max_revisions,+ checkpointer: Some(Arc::clone(&config_checkpointer)),+ thread_id: Some(config_thread_id.clone()),+ cancel: parent.cancellation.clone(),+ // Automated delegation: preserve the host's existing worker-output+ // review policy while the generic tool owns graph lifecycle mechanics.+ ..DelegationConfig::default()+ };+ delegation_config.event_sink = Some(Arc::new(tinyagents_graph::GraphTracingSink::new(+ "delegation:graph",+ )));+ delegation_config};- delegation_config.event_sink = Some(Arc::new(- tinyagents_graph::GraphTracingSink::new("delegation:graph"),- ));- delegation_config- };let result_agent_id = invocation_agent_id.clone();- let tool = tinyagents_orchestration::subagent::DelegationTool::new(- config_factory,- run_stage,- )- .with_tool_name("delegate_graph")- .with_description("Durable plan, execute, review, and finalize delegation.")- .with_parameters(serde_json::json!({- "type": "object",- "required": ["task"],- "properties": {"task": {"type": "string"}}- }))- .with_resumable_execution()- .with_review_approval_policy(- tinyagents_orchestration::subagent::ReviewApprovalPolicy::WorkerOutput,- )- .with_metadata(- PermissionLevel::Execute,- ToolScope::All,- ToolCategory::System,- ToolTimeout::Unbounded,- )- .with_result_projection(move |result| match result {- Ok(outcome) if outcome.pending.is_some() => {- let pending = outcome.pending.expect("checked above");- ToolResult::json(serde_json::json!({- "status": "pending",- "state": outcome.state,- "pending": {- "interrupt_id": pending.interrupt_id,- "node": pending.node,- "payload": pending.payload,- "thread_id": pending.thread_id,- }- }))- }- Ok(outcome) if outcome.state.cancelled => ToolResult::error(format!(- "delegate_graph cancelled for '{result_agent_id}'."- )),- Ok(outcome) => {- let state = outcome.state;- let final_output = state- .final_output- .unwrap_or_else(|| "(delegation produced no final output)".to_string());- let note = if state.revisions > 0 {- " (after revision)"- } else {- ""- };- ToolResult::success(format!(- "[Delegated to {result_agent_id}{note}, {} review pass(es)]\n{final_output}",- state.reviews.len()- ))- }- Err(error) => ToolResult::error(format!(- "delegate_graph failed for '{result_agent_id}': {error}"- )),- });+ let tool = tinyagents_orchestration::subagent::DelegationTool::new(config_factory, run_stage)+ .with_tool_name("delegate_graph")+ .with_description("Durable plan, execute, review, and finalize delegation.")+ .with_parameters(serde_json::json!({+ "type": "object",+ "required": ["task"],+ "properties": {"task": {"type": "string"}}+ }))+ .with_resumable_execution()+ .with_review_approval_policy(+ tinyagents_orchestration::subagent::ReviewApprovalPolicy::WorkerOutput,+ )+ .with_metadata(+ PermissionLevel::Execute,+ ToolScope::All,+ ToolCategory::System,+ ToolTimeout::Unbounded,+ )+ .with_result_projection(move |result| match result {+ Ok(outcome) if outcome.pending.is_some() => {+ let pending = outcome.pending.expect("checked above");+ ToolResult::json(serde_json::json!({+ "status": "pending",+ "state": outcome.state,+ "pending": {+ "interrupt_id": pending.interrupt_id,+ "node": pending.node,+ "payload": pending.payload,+ "thread_id": pending.thread_id,+ }+ }))+ }+ Ok(outcome) if outcome.state.cancelled => {+ ToolResult::error(format!("delegate_graph cancelled for '{result_agent_id}'."))+ }+ Ok(outcome) => {+ let state = outcome.state;+ let final_output = state+ .final_output+ .unwrap_or_else(|| "(delegation produced no final output)".to_string());+ let note = if state.revisions > 0 {+ " (after revision)"+ } else {+ ""+ };+ ToolResult::success(format!(+ "[Delegated to {result_agent_id}{note}, {} review pass(es)]\n{final_output}",+ state.reviews.len()+ ))+ }+ Err(error) => ToolResult::error(format!(+ "delegate_graph failed for '{result_agent_id}': {error}"+ )),+ });tool.execute(&(),diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents.rsindex 526c6aaf5e..9be3d1b5e3 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs@@ -65,14 +65,14 @@ mod tests;#[cfg(test)]pub(crate) use cancel::prune;#[cfg(test)]-pub(crate) use cancel::{CallerWorkspace, caller_workspace_in};+pub(crate) use cancel::{caller_workspace_in, CallerWorkspace};pub(crate) use cancel::{- CancelledSubagent, cancel_all, cancel_by_session_in_workspace, cancel_by_task,- cancel_for_thread, stop_for_thread,+ cancel_all, cancel_by_session_in_workspace, cancel_by_task, cancel_for_thread, stop_for_thread,+ CancelledSubagent,};pub(crate) use registry::admit_spawn;#[cfg(test)]-pub(crate) use registry::{RegistrationError, register, status_channel};+pub(crate) use registry::{register, status_channel, RegistrationError};pub(crate) use resolve::{resume_ref_for_task_in_workspace, task_id_for_session_in_workspace};pub(crate) use roster::active_subagents_context_block;pub use steering::steer;diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rsindex c0d2a4c25f..edbb8e5326 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs@@ -28,14 +28,14 @@ use tokio::sync::watch;use tokio::task::AbortHandle;use crate::agent::tinyagents::host::steering::shared_steering_registry;-use tinyagents_harness::CancellationToken;use tinyagents_harness::ids::TaskId;use tinyagents_harness::run_queue::RunQueue;+use tinyagents_harness::CancellationToken;use tinyagents_tasks::DetachedTaskRegistry;use super::task_ledger::{record_spawned, task_store_for_workspace};use tinyagents_orchestration::subagent::{- DetachedSubagentStatus, SubagentIdentity, WaitError, spawn_status_watcher,+ spawn_status_watcher, DetachedSubagentStatus, SubagentIdentity, WaitError,};#[derive(Clone)]@@ -138,8 +138,8 @@ const REGISTRY_SOFT_CAP: usize = 256;static REGISTRY: OnceLock<DetachedTaskRegistry<RunningSubagentMetadata, DetachedSubagentStatus>> =OnceLock::new();-pub(crate) fn registry()--> &'static DetachedTaskRegistry<RunningSubagentMetadata, DetachedSubagentStatus> {+pub(crate) fn registry(+) -> &'static DetachedTaskRegistry<RunningSubagentMetadata, DetachedSubagentStatus> {REGISTRY.get_or_init(|| {DetachedTaskRegistry::new(shared_steering_registry().clone(),diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rsindex 04608bd842..6f9264bd0e 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs@@ -6,8 +6,9 @@use std::path::Path;use tinyagents_orchestration::subagent::{- SubagentResumeRef, WaitError, resume_ref_for_task as live_resume_ref, resume_ref_from_record,- task_id_for_session as live_task_id, task_id_for_session_in_records,+ resume_ref_for_task as live_resume_ref, resume_ref_from_record,+ task_id_for_session as live_task_id, task_id_for_session_in_records, SubagentResumeRef,+ WaitError,};use super::registry::{admit_workspace, owner_key, registry};diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rsindex 65a69b7f4f..6d3ad37e94 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs@@ -1,7 +1,7 @@//! Read-only rosters over the sub-agent registry: the durable+live merge used to render the//! `[active_subagents]` context block.-use tinyagents_orchestration::subagent::{SubagentSnapshot, snapshot_for_owner};+use tinyagents_orchestration::subagent::{snapshot_for_owner, SubagentSnapshot};use super::registry::{admit_workspace, owner_key, registry};use crate::agent::orchestration::fleet_tools::FleetToolSet;diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rsindex 83b615775d..a696ed18d8 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs@@ -2,7 +2,7 @@use tinyagents_harness::ids::TaskId;use tinyagents_harness::run_queue::QueueLane;-use tinyagents_orchestration::subagent::{SteerAccess, SteerError, steer_detached};+use tinyagents_orchestration::subagent::{steer_detached, SteerAccess, SteerError};use super::cancel::now_ms;use super::registry::{control_admits, owner_key, registry};diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rsindex 72446611f9..ffec82d723 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs@@ -11,13 +11,13 @@ use std::path::{Path, PathBuf};use std::sync::{Arc, OnceLock};use tinyagents_orchestration::subagent::{- SpawnedSubagent, WaitError, list_subagent_records, orphaned_subagent_reason, record_agent_id,+ list_subagent_records, orphaned_subagent_reason, record_agent_id,record_cancelled as ledger_cancelled, record_parent_session, record_spawned as ledger_spawned,- subagent_record_for_task, task_status_label,+ subagent_record_for_task, task_status_label, SpawnedSubagent, WaitError,};use tinyagents_tasks::{- DriverTaskStore, InMemoryTaskStore, OrchestrationTaskFilter, OrchestrationTaskRecord,- TaskStore, TaskStoreRegistry, reconcile_orphaned_tasks,+ reconcile_orphaned_tasks, DriverTaskStore, InMemoryTaskStore, OrchestrationTaskFilter,+ OrchestrationTaskRecord, TaskStore, TaskStoreRegistry,};#[cfg(test)]diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rsindex 15e8f92e3d..c1c4a74133 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs@@ -6,7 +6,7 @@ use std::path::Path;use std::time::Duration;use tinyagents_orchestration::subagent::{- WaitError, WaitOutcome, record_to_wait_outcome, task_status_label, wait_detached,+ record_to_wait_outcome, task_status_label, wait_detached, WaitError, WaitOutcome,};use super::registry::{admit_workspace, owner_key, registry};diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rsindex 2a6ca43fa8..40716203c6 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs@@ -584,11 +584,9 @@ async fn saas_controls_follow_the_explicit_context_not_the_tasks_scope() {Err(SteerError::NotOwned));assert_eq!(pair.a.queue.status().await.steers, 0);- assert!(- snapshot_for_parent(&bob, PARENT)- .iter()- .all(|worker| worker.task_id != a_task)- );+ assert!(snapshot_for_parent(&bob, PARENT)+ .iter()+ .all(|worker| worker.task_id != a_task));assert!(cancel_by_task(&alice, &b_task).is_none(),diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rsindex 443acd3940..3b3b14b550 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs@@ -21,7 +21,7 @@ use tinyagents_harness::run_queue::{QueueLane, RunQueue};use tinyagents_harness::steering::{SteeringCommand, SteeringHandle};use tinyagents_orchestration::subagent::FinishedOutcome;use tinyagents_orchestration::subagent::{- DETACHED_LEDGER_TIMEOUT_MS, DetachedSubagentStatus, WaitError, WaitOutcome,+ DetachedSubagentStatus, WaitError, WaitOutcome, DETACHED_LEDGER_TIMEOUT_MS,};use tinyagents_tasks::OrchestrationTaskStatus;use tokio::sync::watch;@@ -281,15 +281,13 @@ async fn snapshot_and_block_scope_to_parent_and_reflect_live_status() {assert!(block.ends_with("[/active_subagents]\n\n"));// A parent with no registered workers gets no block (no perturbation).- assert!(- active_subagents_context_block(- &cx(),- "nobody-here",- &test_workspace(),- &FleetToolSet::all()- )- .is_none()- );+ assert!(active_subagents_context_block(+ &cx(),+ "nobody-here",+ &test_workspace(),+ &FleetToolSet::all()+ )+ .is_none());// The shipped orchestrator has no wait/steer/close tools (#5701): the// guidance must not name them and must say results arrive on their own.@@ -371,15 +369,13 @@ async fn snapshot_and_block_scope_to_parent_and_reflect_live_status() {assert!(block.contains("status=idle"));assert!(block.contains("about: Daily X trending email workflow"));// Other parents' durable sessions must not leak in.- assert!(- active_subagents_context_block(- &cx(),- "unrelated-parent",- durable_ws.path(),- &FleetToolSet::all()- )- .is_none()- );+ assert!(active_subagents_context_block(+ &cx(),+ "unrelated-parent",+ durable_ws.path(),+ &FleetToolSet::all()+ )+ .is_none());}let _ = tx_a.send(DetachedSubagentStatus::Completed {@@ -528,17 +524,15 @@ async fn wait_times_out_and_leaves_entry_intact() {));// still steerable after a timed-out wait- assert!(- steer(- &cx(),- "task-slow",- "session-A",- "still here".into(),- QueueLane::Steer- )- .await- .is_ok()- );+ assert!(steer(+ &cx(),+ "task-slow",+ "session-A",+ "still here".into(),+ QueueLane::Steer+ )+ .await+ .is_ok());prune("task-slow");}@@ -586,17 +580,15 @@ async fn cancel_for_thread_aborts_only_matching_entries() {.await.is_ok());- assert!(- steer(- &cx(),- "task-headless",- "session-A",- "x".into(),- QueueLane::Steer- )- .await- .is_ok()- );+ assert!(steer(+ &cx(),+ "task-headless",+ "session-A",+ "x".into(),+ QueueLane::Steer+ )+ .await+ .is_ok());// Idempotent: a second pass cancels nothing.assert_eq!(cancel_for_thread(&cx(), "thread-X"), 0);diff --git a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rsindex e8d3497e6a..170e49a4f5 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs@@ -10,8 +10,8 @@use crate::agent::orchestration::tools::dispatch::{incomplete_stop, stopped_subagent_result};use crate::agent::subagent_host::{- continue_subagent, continue_subagent_via_driver_tool,- load_subagent_checkpoint, SubagentRunOptions, SubagentRunStatus,+ continue_subagent, continue_subagent_via_driver_tool, load_subagent_checkpoint,+ SubagentRunOptions, SubagentRunStatus,};use crate::agent_registry::host_definition::AgentDefinitionRegistry;use crate::progress::AgentProgress;@@ -366,16 +366,16 @@ impl ContinueSubagentTool {}// Look up the agent definition- let registry = match AgentDefinitionRegistry::for_core_context(- run_context.dispatch_ctx().into_core(),- ) {- Some(reg) => reg,- None => {- return Ok(ToolResult::error(- "continue_subagent: AgentDefinitionRegistry not initialised",- ));- }- };+ let registry =+ match AgentDefinitionRegistry::for_core_context(run_context.dispatch_ctx().into_core())+ {+ Some(reg) => reg,+ None => {+ return Ok(ToolResult::error(+ "continue_subagent: AgentDefinitionRegistry not initialised",+ ));+ }+ };let definition = match registry.get(&agent_id) {Some(def) => def,None => {diff --git a/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs b/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rsindex 0854fc62bc..695fceb138 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs@@ -224,16 +224,16 @@ impl DelegateGraphTool {// catalogue (or none at all) when callers execute the typed tool with// an explicit parent carrier. Keep the process registry as the legacy// fallback for contexts that do not carry an agent-local catalogue.- let registry = match AgentDefinitionRegistry::for_core_context(- run_context.dispatch_ctx().into_core(),- ) {- Some(reg) => reg,- None => {- return Ok(ToolResult::error(- "delegate_graph: agent definition registry not initialized.",- ));- }- };+ let registry =+ match AgentDefinitionRegistry::for_core_context(run_context.dispatch_ctx().into_core())+ {+ Some(reg) => reg,+ None => {+ return Ok(ToolResult::error(+ "delegate_graph: agent definition registry not initialized.",+ ));+ }+ };let definition = match registry.get(&agent_id) {Some(def) => def.clone(),None => {diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rsindex a126f5fa06..e0e13443ce 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs@@ -170,18 +170,17 @@ pub(crate) async fn dispatch_subagent_with_live_parent(let parent_workspace_descriptor = tool_context.and_then(|ctx| ctx.workspace().cloned()).or_else(|| run_context.workspace.clone());- let registry = match AgentDefinitionRegistry::for_core_context(- run_context.dispatch_ctx().into_core(),- ) {- Some(reg) => reg,- None => {- return Ok(ToolResult::error(- "Agent registry not initialised. This usually means the \+ let registry =+ match AgentDefinitionRegistry::for_core_context(run_context.dispatch_ctx().into_core()) {+ Some(reg) => reg,+ None => {+ return Ok(ToolResult::error(+ "Agent registry not initialised. This usually means the \core process started without calling \AgentDefinitionRegistry::init_global at startup.",- ));- }- };+ ));+ }+ };let definition = match registry.get(agent_id) {Some(def) => def,@@ -423,14 +422,10 @@ pub(crate) async fn dispatch_subagent_with_live_parent(message_run_queue: None,};- let run = run_subagent_via_driver_tool(- live_parent,- definition.clone(),- prompt.to_owned(),- options,- )- .await- .map(|(outcome, _job_id)| outcome);+ let run =+ run_subagent_via_driver_tool(live_parent, definition.clone(), prompt.to_owned(), options)+ .await+ .map(|(outcome, _job_id)| outcome);match run {Ok(outcome) => {let emit_lifecycle_effects = outcome.should_emit_lifecycle_effects();diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rsindex 84a523cdbd..991192fb1b 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs@@ -140,6 +140,9 @@ async fn config_delegate_dispatch_honours_the_parent_cancellation_token() {let parent = crate::agent::tinyagents::host::OpenHumanRunContext::new().with_cancellation(cancellation.clone()).into_tinyagents(RunConfig::new("config-delegate-parent").with_thread("thread-parent"));+ let jobs = crate::core::runtime::slot_for::<+ tinyagents_orchestration::subagent::SubAgentJobRegistry,+ >(&parent.data.dispatch_ctx());let execution = dispatch.execute(&(),tinyagents_harness::CallId::new("test-call"),@@ -149,7 +152,13 @@ async fn config_delegate_dispatch_honours_the_parent_cancellation_token() {);tokio::pin!(execution);tokio::select! {- _ = started_rx.recv() => cancellation.cancel(),+ _ = started_rx.recv() => {+ assert!(jobs.list().iter().any(|job| {+ job.agent == "configured"+ && job.status == tinyagents_orchestration::subagent::SubAgentJobStatus::Running+ }), "configured executor is registered in the shared Jobs lifecycle");+ cancellation.cancel();+ },result = &mut execution => panic!("blocking delegate returned before cancellation: {result:?}"),}let result = execution@@ -157,6 +166,12 @@ async fn config_delegate_dispatch_honours_the_parent_cancellation_token() {.expect("cancellation is reported as a tool result");assert!(result.is_error);assert!(result.output().contains("cancelled"), "{}", result.output());+ assert!(+ jobs.list()+ .iter()+ .any(|job| { job.agent == "configured" && job.status.is_terminal() }),+ "configured child cancellation settles the shared Jobs lifecycle"+ );}#[test]diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rsindex be9b76fb2d..2549eda279 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs@@ -130,10 +130,8 @@ async fn steer_reusable_session(thread_id.as_deref(),);let owner_scope: Arc<dyn Fn(u64) -> String + Send + Sync> = Arc::new(move |_| owner.clone());- let jobs = (*crate::core::runtime::slot_for::<SubAgentJobRegistry>(- &context.dispatch_ctx(),- ))- .clone();+ let jobs =+ (*crate::core::runtime::slot_for::<SubAgentJobRegistry>(&context.dispatch_ctx())).clone();let store: Arc<dyn tinyagents_orchestration::subagent::SubagentSessionStore> = Arc::new(crate::agent::orchestration::subagent_sessions::OpenHumanTinySubagentSessionStore::new(product_parent.workspace_dir.clone(),@@ -155,19 +153,19 @@ async fn steer_reusable_session(ToolTimeout::Inherit,);let result = ToolDispatch::execute(- &dispatch,- &(),- tinyagents_harness::CallId::new(format!("reuse-steer-{session_id}")),- json!({- "subagent_session_id": session_id,- "message": message,- "mode": "steer",- }),- ToolCallOptions::default(),- parent,- )- .await- .map_err(|error| error.to_string())?;+ &dispatch,+ &(),+ tinyagents_harness::CallId::new(format!("reuse-steer-{session_id}")),+ json!({+ "subagent_session_id": session_id,+ "message": message,+ "mode": "steer",+ }),+ ToolCallOptions::default(),+ parent,+ )+ .await+ .map_err(|error| error.to_string())?;if result.is_error {Err(result.output())} else {diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rsindex f3d8ef8e2a..0e6ee67fac 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs@@ -5,9 +5,9 @@ use crate::config::AgentConfig;use std::collections::HashSet;use std::path::Path;use std::sync::Arc;+use tinyagents_harness::run_queue::RunQueue;use tinytools::{ToolCallOptions, ToolRunContext};use tinytools_agent::dialect::ToolCallFormat;-use tinyagents_harness::run_queue::RunQueue;struct ThreadContext(&'static str);diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rsindex 2e79fecd5a..f6c39c55cb 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs@@ -432,15 +432,16 @@ async fn continue_subagent_resumes_paused_job_through_shared_driver() {calls: std::sync::atomic::AtomicUsize::new(0),seen: Mutex::new(Vec::new()),});- let ask_tool: Box<dyn tinytools::Tool> = Box::new(- tinyagents_harness::tools::AskClarificationTool::new(),- );+ let ask_tool: Box<dyn tinytools::Tool> =+ Box::new(tinyagents_harness::tools::AskClarificationTool::new());let ask_spec = Arc::new(ask_tool.spec());let mut parent = parent_context(workspace.path(), provider.clone(), vec![]);parent.all_tools = Arc::new(vec![ask_tool]);parent.all_tool_specs = Arc::new(vec![ask_spec.clone()]);parent.visible_tool_specs = Arc::new(vec![ask_spec]);- parent.visible_tool_names.insert("ask_user_clarification".into());+ parent+ .visible_tool_names+ .insert("ask_user_clarification".into());parent.subagent_tool_ceiling_names.insert("ask_user_clarification".into());@@ -545,14 +546,12 @@ async fn delegate_graph_runs_every_stage_through_shared_driver_jobs() {.expect("task manager definition").clone();test_definition.model = tinyagents_definition::ModelSpec::Exact("test-model".into());- let definitions = Arc::new(- AgentDefinitionRegistry::builtins_only().with_definitions([test_definition]),- );+ let definitions =+ Arc::new(AgentDefinitionRegistry::builtins_only().with_definitions([test_definition]));let mut config = crate::config::Config::default();config.workspace_dir = workspace.path().to_path_buf();let core = CoreContext::for_test_with_config(DomainSet::full(), config.clone()).derive_with(- ContextOverlay::new(config, DomainSet::full(), ToolGroups::none())- .definitions(definitions),+ ContextOverlay::new(config, DomainSet::full(), ToolGroups::none()).definitions(definitions),);// `OpenHumanRunContext::with_core` retains a weak handle; keep this strong// owner alive through the graph execution so the scoped definition@@ -597,7 +596,10 @@ async fn delegate_graph_runs_every_stage_through_shared_driver_jobs() {})}).count();- assert_eq!(completed_stages, 3, "each graph stage is registered in Jobs");+ assert_eq!(+ completed_stages, 3,+ "each graph stage is registered in Jobs"+ );}#[tokio::test]diff --git a/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rsindex ee22d657ab..6e9b8a24e6 100644--- a/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs+++ b/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs@@ -57,8 +57,10 @@ fn a_breaker_stopped_turn_closes_at_warning_with_stop_attributes() {(AgentProgress::TurnCompleted {iterations: 4,- stop: Some(crate::agent::session_host::stop_summary::breaker_stop(+ stop: Some(tinyagents_harness::TurnStop::breaker_with_cause(BREAKER_NOTE,+ tinyagents_harness::TurnFailureClass::new("uncertain_side_effect"),+ Some("web_answer_tool".to_owned()),)),},50,@@ -171,8 +173,10 @@ fn a_stopped_subagent_span_closes_at_warning_with_stop_attributes() {(subagent_completed("t-stop",- Some(crate::agent::session_host::stop_summary::breaker_stop(+ Some(tinyagents_harness::TurnStop::breaker_with_cause(BREAKER_NOTE,+ tinyagents_harness::TurnFailureClass::new("uncertain_side_effect"),+ Some("web_answer_tool".to_owned()),)),),40,diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rsindex 92fe33f4b3..3a696f9e81 100644--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs@@ -113,9 +113,10 @@ pub(crate) async fn run_subagent_via_driver_tool(options.task_id = Some(task_id.clone());let parent_thread_id = parent.thread_id().map(|id| id.as_str().to_owned());let task_key = SubagentTaskKey::from_context(parent, task_id.clone(), parent_thread_id);- let (tool_result, bundle) =- invoke_async_spawn_driver_tool(parent, definition, input, options, "inline", None, None, None)- .await?;+ let (tool_result, bundle) = invoke_async_spawn_driver_tool(+ parent, definition, input, options, "inline", None, None, None,+ )+ .await?;let public_job_id = decode_driver_job_result(tool_result, &bundle, &task_key)?;if let Some(outcome) = bundle.host_outcome@@ -166,16 +167,8 @@ pub(crate) async fn run_configured_delegate_via_driver_tool(},options,};- let (tool_result, bundle) = invoke_driver_tool_with_request(- parent,- request,- input,- "inline",- None,- None,- None,- )- .await?;+ let (tool_result, bundle) =+ invoke_driver_tool_with_request(parent, request, input, "inline", None, None, None).await?;let task_key = SubagentTaskKey::from_context(parent,task_id,@@ -376,19 +369,24 @@ async fn invoke_driver_tool_with_request(.task_id.clone().unwrap_or_else(|| format!("sub-{}", uuid::Uuid::new_v4()));- let checkpoint_dir =- absolute_checkpoint_dir(host_request.options.checkpoint_dir.clone().unwrap_or_else(|| {- parent- .data- .parent- .as_ref()- .map(|context| {- context- .workspace_dir- .join(".openhuman/subagent_checkpoints")- })- .unwrap_or_else(|| PathBuf::from(".openhuman/subagent_checkpoints"))- }));+ let checkpoint_dir = absolute_checkpoint_dir(+ host_request+ .options+ .checkpoint_dir+ .clone()+ .unwrap_or_else(|| {+ parent+ .data+ .parent+ .as_ref()+ .map(|context| {+ context+ .workspace_dir+ .join(".openhuman/subagent_checkpoints")+ })+ .unwrap_or_else(|| PathBuf::from(".openhuman/subagent_checkpoints"))+ }),+ );let bundle = OpenHumanDriverBundle::new(checkpoint_dir)?;let request_host = host_request.clone();let request_task_id = task_id.clone();@@ -1102,10 +1100,8 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O));let result = match dispatch.into_core() {Some(core) => {- crate::core::runtime::CoreContext::scope_with_turn_origin(- core, origin, run,- )- .await+ crate::core::runtime::CoreContext::scope_with_turn_origin(core, origin, run)+ .await}None => run.await,};@@ -1190,14 +1186,12 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O);let mut neutral = SubagentOutcome::cancelled(task_key.task_id.clone());neutral.output = output;- neutral.extensions.insert(- "agent_id".into(),- serde_json::Value::String(agent_id),- );- neutral.extensions.insert(- "iterations".into(),- serde_json::Value::Number(1.into()),- );+ neutral+ .extensions+ .insert("agent_id".into(), serde_json::Value::String(agent_id));+ neutral+ .extensions+ .insert("iterations".into(), serde_json::Value::Number(1.into()));neutral.status = if tool_result.is_error {SubagentOutcomeKind::Incomplete(SubagentIncomplete::new("configured delegate reported failure",diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rsindex d950237a02..88bb70c07f 100644--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs@@ -7,9 +7,7 @@ use super::lifecycle::{decode_driver_job_result, host_in_flight, load_subagent_checkpoint, merged_resume_history,HostInFlight, OpenHumanDriverBundle, OpenHumanPersistence,};-use super::{- SubagentMode, SubagentRunError, SubagentRunOutcome, SubagentRunStatus, SubagentUsage,-};+use super::{SubagentMode, SubagentRunError, SubagentRunOutcome, SubagentRunStatus, SubagentUsage};fn key() -> SubagentTaskKey {SubagentTaskKey {@@ -72,12 +70,9 @@ fn driver_error_accepts_only_matching_nonterminal_lifecycle_snapshots() {.lock().unwrap().insert(task_key.clone(), cached_outcome(host_status));- let decoded = decode_driver_job_result(- lifecycle_error(status, public_id),- &bundle,- &task_key,- )- .unwrap();+ let decoded =+ decode_driver_job_result(lifecycle_error(status, public_id), &bundle, &task_key)+ .unwrap();assert_eq!(decoded, public_id);}}@@ -87,15 +82,14 @@ fn driver_error_does_not_hide_completed_mismatched_or_persistence_failures() {let workspace = tempfile::tempdir().unwrap();let bundle = OpenHumanDriverBundle::new(workspace.path().join("checkpoints")).unwrap();let task_key = key();- bundle- .host_outcome- .lock()- .unwrap()- .insert(task_key.clone(), cached_outcome(SubagentRunStatus::AwaitingUser {+ bundle.host_outcome.lock().unwrap().insert(+ task_key.clone(),+ cached_outcome(SubagentRunStatus::AwaitingUser {question: "Need clarification".into(),options: None,checkpoint: None,- }));+ }),+ );for result in [lifecycle_error("cancelled", "subagent-job-42"),@@ -103,7 +97,9 @@ fn driver_error_does_not_hide_completed_mismatched_or_persistence_failures() {tinytools::ToolResult::error("provider transport failed"),] {let error = decode_driver_job_result(result, &bundle, &task_key).unwrap_err();- assert!(error.to_string().contains("driver-backed async spawn failed"));+ assert!(error+ .to_string()+ .contains("driver-backed async spawn failed"));}bundle.failures.lock().unwrap().insert(@@ -129,7 +125,9 @@ fn driver_error_does_not_hide_completed_mismatched_or_persistence_failures() {&task_key,).unwrap_err();- assert!(error.to_string().contains("driver-backed async spawn failed"));+ assert!(error+ .to_string()+ .contains("driver-backed async spawn failed"));bundle.host_outcome.lock().unwrap().insert(task_key.clone(),@@ -139,12 +137,8 @@ fn driver_error_does_not_hide_completed_mismatched_or_persistence_failures() {checkpoint: None,}),);- let error = decode_driver_job_result(- lifecycle_error("awaiting_input", ""),- &bundle,- &task_key,- )- .unwrap_err();+ let error = decode_driver_job_result(lifecycle_error("awaiting_input", ""), &bundle, &task_key)+ .unwrap_err();assert!(error.to_string().contains("omitted its registered job id"));}diff --git a/crates/openhuman-core/src/agent/subagent_host/mod.rs b/crates/openhuman-core/src/agent/subagent_host/mod.rsindex 5d3229808d..deba91837d 100644--- a/crates/openhuman-core/src/agent/subagent_host/mod.rs+++ b/crates/openhuman-core/src/agent/subagent_host/mod.rs@@ -57,12 +57,12 @@ mod persisted_compat_tests;// Public API — the entry point and the shapes it returns.pub use autonomous::{definition_iter_cap, subagent_iter_cap_with_autonomous_lift};pub(crate) use lifecycle::load_subagent_checkpoint;-pub(crate) use lifecycle::{checkpoint_resume, continue_subagent_via_driver_tool};-pub(crate) use lifecycle::run_subagent_via_driver_tool;pub(crate) use lifecycle::run_configured_delegate_via_driver_tool;+pub(crate) use lifecycle::run_subagent_via_driver_tool;+pub(crate) use lifecycle::spawn_async_via_driver_tool;#[cfg(test)]pub(crate) use lifecycle::spawn_async_via_driver_tool_with_jobs;-pub(crate) use lifecycle::spawn_async_via_driver_tool;+pub(crate) use lifecycle::{checkpoint_resume, continue_subagent_via_driver_tool};pub use lifecycle::{continue_subagent, continue_subagent_with_parent, run_subagent, run_subagent_with_parent,OpenHumanSubagentHost,diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rsindex bad4057f31..17fd5faa64 100644--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs@@ -6,6 +6,7 @@use std::collections::HashSet;use std::sync::Arc;+use async_trait::async_trait;use tinyagents_graph::goals::GoalToolKind;use tinyagents_harness::tool::packs::USE_SKILL;use tinyagents_harness::tool::{@@ -13,18 +14,17 @@ use tinyagents_harness::tool::{};use tinyagents_registry::{CapabilityRegistry, ComponentKind, RegistryDiagnostic};use tinyagents_runtime::turn_driver::{SharedToolSet, ToolSetBuilder};-use tinyagents_runtime::{ToolAdmission, project_descriptors};+use tinyagents_runtime::{project_descriptors, ToolAdmission};use tinyinference_llm::model::ChatModel;use tinytools::{Tool, ToolCallOptions, ToolResult, ToolRunContext};-use async_trait::async_trait;use crate::agent::orchestration::tools::{CloseSubagentDispatch, ContinueSubagentDispatch, DelegateGraphDispatch, DelegationDispatch,ListSubagentsDispatch, SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch,SpawnSubagentDispatch, SteerSubagentDispatch, WaitSubagentDispatch,};-use crate::agent::tinyagents::host::OpenHumanRunContext;use crate::agent::tinyagents::host::run_context::HostOperationContext;+use crate::agent::tinyagents::host::OpenHumanRunContext;use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;use crate::agent::tinyagents::use_skill_dispatch::UseSkillDispatch;use crate::agent::tools::TodoToolDispatch;diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rsindex 4397f26067..d937de22ab 100644--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs@@ -46,7 +46,7 @@ fn threaded_turn_keeps_goal_tools_as_exposure_candidates() {#[tokio::test]async fn registered_memory_dispatch_enforces_one_budget_across_distinct_calls() {use crate::memory::test_fixtures::{bind_reference, config_in};- use tinyagents_harness::{CallId, context::RunConfig};+ use tinyagents_harness::{context::RunConfig, CallId};use tinytools::ToolCallOptions;let workspace = tempfile::tempdir().unwrap();let config = config_in(&workspace);