Skip to content

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

refactor(subagent): route detached steering through tinyagents

Steven Enamakel187aa22cb161
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
index 275752776b..a569723274 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
@@ -1,74 +1,15 @@
-//! Injecting messages and crate-native control-flow directives into a running
-//! sub-agent: the `RunQueue` compatibility lane, and the TinyAgents
-//! `SteeringHandle` fast path for runs that have registered one.
+//! OpenHuman's `RunQueue` fallback for TinyAgents detached steering.
use tinyagents_harness::ids::TaskId;
use tinyagents_harness::run_queue::QueueLane;
-use tinyagents_harness::steering::SteeringCommand;
-use tinyagents_tasks::DetachedTaskRegistryError;
-use tinyinference_llm::message::Message as TaMessage;
+use tinyagents_orchestration::subagent::{steer_detached, SteerAccess};
use super::cancel::now_ms;
use super::registry::{control_admits, owner_key, registry};
-/// Why a steer could not be delivered.
-#[derive(Debug, PartialEq, Eq)]
-pub enum SteerError {
- /// No such sub-agent — never existed, or already finished and pruned.
- Unknown,
- /// The caller's `parent_session` does not own this sub-agent.
- NotOwned,
- /// The sub-agent already reached a terminal status.
- AlreadyDone,
- /// Detached sub-agents can only receive an injected instruction or
- /// collected context. Follow-up work is a web-turn concern and cannot be
- /// meaningfully dispatched from this fallback queue.
- UnsupportedLane,
-}
-
-pub(crate) fn steer_error_from_registry(error: DetachedTaskRegistryError) -> SteerError {
- match error {
- DetachedTaskRegistryError::NotOwned => SteerError::NotOwned,
- DetachedTaskRegistryError::AlreadyDone => SteerError::AlreadyDone,
- _ => SteerError::Unknown,
- }
-}
-
-fn steering_command_for_lane(lane: QueueLane, text: String) -> Option<SteeringCommand> {
- match lane {
- QueueLane::Steer => Some(SteeringCommand::InjectMessage(TaMessage::user(format!(
- "[User steering message]: {text}"
- )))),
- QueueLane::Collect => Some(SteeringCommand::InjectMessage(TaMessage::user(format!(
- "[Additional context from user]: {text}"
- )))),
- QueueLane::Followup => None,
- }
-}
-
-fn queue_lane_name(lane: QueueLane) -> &'static str {
- match lane {
- QueueLane::Steer => "steer",
- QueueLane::Followup => "followup",
- QueueLane::Collect => "collect",
- }
-}
-
-fn send_registered_steering(
- handle: &tinyagents_harness::steering::SteeringHandle,
- text: String,
- lane: QueueLane,
-) -> bool {
- let Some(command) = steering_command_for_lane(lane, text) else {
- return false;
- };
- handle.send(command);
- true
-}
+pub use tinyagents_orchestration::subagent::SteerError;
-/// Inject a message into a running sub-agent. Prefer the crate-native
-/// TinyAgents steering registry when the child run has registered its live
-/// handle, and fall back to the OpenHuman `RunQueue` compatibility path.
+/// Inject an instruction into a detached sub-agent owned by `parent_session`.
pub async fn steer(
ctx: &crate::core::runtime::DispatchCtx,
task_id: &str,
@@ -76,126 +17,91 @@ pub async fn steer(
text: String,
lane: QueueLane,
) -> Result<(), SteerError> {
- if !matches!(lane, QueueLane::Steer | QueueLane::Collect) {
- log::warn!(
- "[running_subagents] rejected unsupported queue lane task_id={} lane={}",
- task_id,
- queue_lane_name(lane)
- );
- return Err(SteerError::UnsupportedLane);
- }
- let task_id_key = TaskId::new(task_id);
let owner = owner_key(ctx, parent_session).map_err(|_| SteerError::NotOwned)?;
- let snapshot = registry()
- .snapshot(&task_id_key, &owner)
- .map_err(steer_error_from_registry)?;
- if snapshot.status.is_terminal() {
- return Err(SteerError::AlreadyDone);
- }
-
- let steered_via_registry = registry()
- .steering_handle(&task_id_key, &owner)
- .map(|handle| send_registered_steering(&handle, text.clone(), lane))
- .unwrap_or(false);
- if steered_via_registry {
- log::info!(
- "[running_subagents] steered task_id={} lane={} via=tinyagents_registry",
- task_id,
- queue_lane_name(lane)
- );
- return Ok(());
- }
-
- snapshot
- .metadata
- .run_queue
- .push(
- lane,
- crate::agent::queued_turn::QueuedTurn {
- id: uuid::Uuid::new_v4().to_string(),
- text,
- client_id: "steer_subagent".to_string(),
- thread_id: task_id.to_string(),
- queued_at_ms: now_ms(),
- model_override: None,
- temperature: None,
- locale: None,
- },
- )
- .await;
- log::info!(
- "[running_subagents] steered task_id={} lane={}",
+ let route = steer_detached(
+ registry(),
+ task_id,
+ SteerAccess::Owner(&owner),
+ text,
+ lane,
+ |metadata, lane, text| async move {
+ metadata
+ .run_queue
+ .push(
+ lane,
+ crate::agent::queued_turn::QueuedTurn {
+ id: uuid::Uuid::new_v4().to_string(),
+ text,
+ client_id: "steer_subagent".to_string(),
+ thread_id: task_id.to_string(),
+ queued_at_ms: now_ms(),
+ model_override: None,
+ temperature: None,
+ locale: None,
+ },
+ )
+ .await;
+ },
+ )
+ .await?;
+ tracing::info!(
task_id,
- queue_lane_name(lane)
+ lane = tinyagents_orchestration::subagent::queue_lane_name(lane),
+ ?route,
+ "[running_subagents] steered detached task"
);
Ok(())
}
-/// User-control variant used by JSON-RPC sub-agent controls.
+/// User-control variant for JSON-RPC sub-agent controls.
///
-/// This intentionally does not require the caller to provide `parent_session`:
-/// the captured profile is checked against the caller in SaaS. Desktop controls
-/// retain authority over the process user's workers. Unknown, foreign or
-/// terminal tasks are refused, and steered text is never logged.
+/// The caller's profile is checked against the task metadata before using the
+/// trusted upstream route. Desktop controls retain authority over process
+/// workers, while SaaS controls remain scoped to their captured profile.
pub(crate) async fn steer_control(
ctx: &crate::core::runtime::DispatchCtx,
task_id: &str,
text: String,
lane: QueueLane,
) -> Result<(), SteerError> {
- if !matches!(lane, QueueLane::Steer | QueueLane::Collect) {
- log::warn!(
- "[running_subagents] rejected unsupported control queue lane task_id={} lane={}",
- task_id,
- queue_lane_name(lane)
- );
- return Err(SteerError::UnsupportedLane);
- }
- let task_id_key = TaskId::new(task_id);
+ let key = TaskId::new(task_id);
let snapshot = registry()
- .snapshot_trusted(&task_id_key)
- .map_err(steer_error_from_registry)?;
+ .snapshot_trusted(&key)
+ .map_err(SteerError::from)?;
if !control_admits(ctx, &snapshot.metadata) {
return Err(SteerError::NotOwned);
}
- if snapshot.status.is_terminal() {
- return Err(SteerError::AlreadyDone);
- }
-
- let steered_via_registry = registry()
- .steering_handle(&task_id_key, &snapshot.owner_id)
- .map(|handle| send_registered_steering(&handle, text.clone(), lane))
- .unwrap_or(false);
- if steered_via_registry {
- log::info!(
- "[running_subagents] control_steered task_id={} lane={} via=tinyagents_registry",
- task_id,
- queue_lane_name(lane)
- );
- return Ok(());
- }
-
- snapshot
- .metadata
- .run_queue
- .push(
- lane,
- crate::agent::queued_turn::QueuedTurn {
- id: uuid::Uuid::new_v4().to_string(),
- text,
- client_id: "subagent_control_rpc".to_string(),
- thread_id: task_id.to_string(),
- queued_at_ms: now_ms(),
- model_override: None,
- temperature: None,
- locale: None,
- },
- )
- .await;
- log::info!(
- "[running_subagents] control_steered task_id={} lane={}",
+ let route = steer_detached(
+ registry(),
+ task_id,
+ SteerAccess::Trusted,
+ text,
+ lane,
+ |metadata, lane, text| async move {
+ metadata
+ .run_queue
+ .push(
+ lane,
+ crate::agent::queued_turn::QueuedTurn {
+ id: uuid::Uuid::new_v4().to_string(),
+ text,
+ client_id: "subagent_control_rpc".to_string(),
+ thread_id: task_id.to_string(),
+ queued_at_ms: now_ms(),
+ model_override: None,
+ temperature: None,
+ locale: None,
+ },
+ )
+ .await;
+ },
+ )
+ .await?;
+ tracing::info!(
task_id,
- queue_lane_name(lane)
+ lane = tinyagents_orchestration::subagent::queue_lane_name(lane),
+ ?route,
+ "[running_subagents] control-steered detached task"
);
Ok(())
}
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
index 7912028c03..16927c36d3 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
@@ -5,6 +5,15 @@ use std::sync::Arc;
use tinyagents_runtime::ToolSnapshot;
use tinytools::ToolSpec;
+fn synthesized_tool_names(prelude: &super::SessionPrelude) -> std::collections::HashSet<String> {
+ prelude
+ .tool_surface
+ .lock()
+ .expect("tool surface")
+ .synthesized_tool_names
+ .clone()
+}
+
#[tokio::test]
async fn committed_progress_uses_each_turns_receipt_sender() {
use crate::agent::progress::AgentProgress;
@@ -238,7 +247,7 @@ fn connected_mcp_actions_enter_search_and_leave_on_disconnect() {
let action = "mcp_weather_forecast_abc123".to_string();
prelude.refresh_delegation_tool_surface().unwrap();
- assert!(prelude.synthesized_tool_names_for_test().contains(&action));
+ assert!(synthesized_tool_names(&prelude).contains(&action));
{
let surface = prelude.tool_surface.lock().expect("tool surface");
assert!(surface.deferred_tool_names.contains(&action));
@@ -253,7 +262,7 @@ fn connected_mcp_actions_enter_search_and_leave_on_disconnect() {
.connected
.clear();
prelude.refresh_delegation_tool_surface().unwrap();
- assert!(!prelude.synthesized_tool_names_for_test().contains(&action));
+ assert!(!synthesized_tool_names(&prelude).contains(&action));
assert!(!prelude
.tool_surface
.lock()
@@ -464,9 +473,7 @@ async fn a_resumed_orchestrator_keeps_the_integration_actions_it_was_sent() {
// Fresh process: no integrations known, so no actions are synthesised.
prelude.refresh_delegation_tool_surface().unwrap();
- assert!(!prelude
- .synthesized_tool_names_for_test()
- .contains("GMAIL_SEND_EMAIL"));
+ assert!(!synthesized_tool_names(&prelude).contains("GMAIL_SEND_EMAIL"));
// Resume hands back what the thread was sent.
let recorded = ToolSnapshot::new(vec![
@@ -491,7 +498,7 @@ async fn a_resumed_orchestrator_keeps_the_integration_actions_it_was_sent() {
}
prelude.refresh_delegation_tool_surface().unwrap();
- let names = prelude.synthesized_tool_names_for_test();
+ let names = synthesized_tool_names(&prelude);
assert!(names.contains("GMAIL_SEND_EMAIL"), "{names:?}");
assert!(names.contains("GMAIL_FETCH_EMAILS"), "{names:?}");
assert!(
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs b/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs
index 3ee344741a..90857e9b08 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs
@@ -39,66 +39,6 @@ pub(crate) fn is_safe_task_id(task_id: &str) -> bool {
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_'))
}
-pub(super) fn write(
- checkpoint_dir: &std::path::Path,
- task_id: &str,
- data: &crate::agent::subagent_host::types::SubagentCheckpointData,
-) -> Option<std::path::PathBuf> {
- if !is_safe_task_id(task_id) {
- tracing::error!(
- task_id = %task_id,
- dir = %checkpoint_dir.display(),
- "[subagent_host] refusing to write a checkpoint under an unsafe task id; \
- this pause will not be resumable from disk"
- );
- return None;
- }
-
- if let Err(e) = std::fs::create_dir_all(checkpoint_dir) {
- tracing::error!(
- task_id = %task_id,
- dir = %checkpoint_dir.display(),
- error = %e,
- "[subagent_host] could not create the checkpoint directory; this pause will not be \
- resumable from disk"
- );
- return None;
- }
-
- let json = match serde_json::to_string_pretty(data) {
- Ok(json) => json,
- Err(e) => {
- tracing::error!(
- task_id = %task_id,
- error = %e,
- "[subagent_host] could not serialize the checkpoint; this pause will not be \
- resumable from disk"
- );
- return None;
- }
- };
-
- let checkpoint_path = checkpoint_dir.join(format!("{task_id}.json"));
- if let Err(e) = std::fs::write(&checkpoint_path, json) {
- tracing::error!(
- task_id = %task_id,
- path = %checkpoint_path.display(),
- error = %e,
- "[subagent_host] could not write the checkpoint; this pause will not be resumable \
- from disk"
- );
- return None;
- }
-
- tracing::info!(
- task_id = %task_id,
- path = %checkpoint_path.display(),
- history_len = data.history.len(),
- "[subagent_host] checkpoint written for awaiting_user"
- );
- Some(checkpoint_path)
-}
-
#[cfg(test)]
#[path = "runner_checkpoint_tests.rs"]
mod tests;
diff --git a/vendor/tinyagents b/vendor/tinyagents
index e72242cbf1..0cdfcf157d 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit e72242cbf1d6279849f60c5c837aa79ca787bbbe
+Subproject commit 0cdfcf157d612978bc86e38e3e1fa4d600a303bb