Skip to content

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

feat(orchestration): render subagent roster from owner-scoped entries

Steven Enamakel77a0ddf07724
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
index 9fe8fadcdb..6104f6d2a1 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
@@ -5,8 +5,8 @@
use super::*;
use crate::agent::orchestration::background_completions::{
- pending_for_ctx, record_completion, router_for_workspace, router_for_workspace_ctx,
- TestWorkspace,
+ TestWorkspace, pending_for_ctx, record_completion, router_for_workspace,
+ router_for_workspace_ctx,
};
use crate::core::runtime::DispatchCtx;
use crate::core::runtime::{ContextOverlay, DomainSet};
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
index ea56c75dce..c7b5d0eb2d 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
@@ -6,7 +6,7 @@ fn cx() -> crate::core::runtime::DispatchCtx {
}
use crate::agent::orchestration::background_completions::{
- forget_workspace_for_test, pending_for, record_completion, router_for_workspace, TestWorkspace,
+ TestWorkspace, forget_workspace_for_test, pending_for, record_completion, router_for_workspace,
};
use std::path::Path;
use std::sync::atomic::{AtomicU32, Ordering};
@@ -32,8 +32,9 @@ fn pending_ids(ws: &Path, thread: &str) -> Vec<String> {
}
fn test_turns() -> &'static std::sync::Mutex<std::collections::HashMap<String, TurnBusy>> {
- static TURNS: std::sync::OnceLock<std::sync::Mutex<std::collections::HashMap<String, TurnBusy>>> =
- std::sync::OnceLock::new();
+ static TURNS: std::sync::OnceLock<
+ std::sync::Mutex<std::collections::HashMap<String, TurnBusy>>,
+ > = std::sync::OnceLock::new();
TURNS.get_or_init(Default::default)
}
@@ -508,10 +509,12 @@ async fn every_subagent_terminal_event_schedules_a_drain_through_the_handler() {
iterations: 0,
})
.await;
- assert!(scheduled_for_test()
- .lock()
- .expect("scheduled")
- .contains(&("bd-term-thread".to_string(), Duration::from_millis(300))));
+ assert!(
+ scheduled_for_test()
+ .lock()
+ .expect("scheduled")
+ .contains(&("bd-term-thread".to_string(), Duration::from_millis(300)))
+ );
clear_busy(session);
assert_eq!(
drain_schedule(&DomainEvent::SubagentFailed {
@@ -676,10 +679,12 @@ async fn boot_recovery_schedules_a_delivery_for_every_thread_with_undelivered_re
scheduled_for_test().lock().expect("scheduled").clear();
assert_eq!(recover_on_boot(&cx(), w), 1);
- assert!(scheduled_for_test()
- .lock()
- .expect("scheduled")
- .contains(&("thread-boot-sched".to_string(), RECOVERY_DELAY)));
+ assert!(
+ scheduled_for_test()
+ .lock()
+ .expect("scheduled")
+ .contains(&("thread-boot-sched".to_string(), RECOVERY_DELAY))
+ );
assert_eq!(
recover_on_boot(&cx(), w),
0,
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
index 7996adbec6..9be9c054af 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
@@ -2,6 +2,7 @@
//! `[active_subagents]` context block.
use super::registry::admit_workspace;
+use tinyagents_orchestration::subagent::{DurableSubagentSessionSummary, ParentRosterEntry};
#[cfg(test)]
#[path = "roster_tests.rs"]
@@ -12,6 +13,72 @@ fn roster_guidance() -> &'static str {
"reuse its task_key with spawn_subagent to continue or answer a clarification; completed results are delivered automatically."
}
+/// Apply OpenHuman's prompt wording to the owner-scoped data supplied by
+/// TinyAgents. Keeping this formatter here lets the host own product language
+/// while the upstream registry remains the source of live job state.
+fn format_roster(entries: &[ParentRosterEntry]) -> String {
+ if entries.is_empty() {
+ return String::new();
+ }
+ let mut block = format!(
+ "[active_subagents]\n\
+ You have {} sub-agent worker(s). This is your authoritative roster — trust it over memory. Track each by \
+ subagent_session_id. {} Never fabricate a result for a worker still running \
+ or one that has failed.\n",
+ entries.len(),
+ roster_guidance()
+ );
+ for entry in entries {
+ let session = entry.session.as_ref();
+ let (session_id, task_id, task_title, status) = if let Some(session) = session {
+ (
+ session.subagent_session_id.as_str(),
+ session
+ .current_task_id
+ .as_deref()
+ .unwrap_or(entry.task_id.as_str()),
+ session.task_title.as_str(),
+ match session.status {
+ tinyagents_orchestration::subagent::DurableSubagentStatus::Running => "running",
+ tinyagents_orchestration::subagent::DurableSubagentStatus::Idle => "idle",
+ tinyagents_orchestration::subagent::DurableSubagentStatus::AwaitingUser => {
+ "awaiting_user"
+ }
+ tinyagents_orchestration::subagent::DurableSubagentStatus::Failed => "failed",
+ tinyagents_orchestration::subagent::DurableSubagentStatus::Closed => "closed",
+ },
+ )
+ } else if let Some(job) = entry.live_job.as_ref() {
+ (
+ "(live)",
+ entry.task_id.as_str(),
+ "(no durable session)",
+ match job.status {
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Queued => "queued",
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Running => "running",
+ tinyagents_orchestration::subagent::SubAgentJobStatus::AwaitingInput => {
+ "awaiting_user"
+ }
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Completed => "completed",
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Failed => "failed",
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Incomplete => {
+ "incomplete"
+ }
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Cancelled => "cancelled",
+ },
+ )
+ } else {
+ continue;
+ };
+ block.push_str(&format!(
+ "- {} · session={} · task={} · status={} · about: {}\n",
+ entry.agent_id, session_id, task_id, status, task_title
+ ));
+ }
+ block.push_str("[/active_subagents]\n\n");
+ block
+}
+
/// Most-recent durable sessions surfaced in the roster when they are not in
/// the live registry (cold boot / later turn). Bounds prompt growth on
/// threads with a long delegation history.
@@ -39,18 +106,25 @@ pub(crate) fn active_subagents_context_block(
let store = crate::agent::orchestration::subagent_sessions::SubagentSessionStore {
workspace_dir: workspace_dir.to_path_buf(),
};
- let durable: Vec<_> = match crate::agent::orchestration::subagent_sessions::list_for_parent(
- &store,
- parent_session,
- None,
- ) {
+ let load = || {
+ crate::agent::orchestration::subagent_sessions::list_for_parent(
+ &store,
+ parent_session,
+ None,
+ )
+ };
+ let durable = match ctx.resolved() {
+ Some(context) => crate::core::runtime::CoreContext::sync_scope(context, load),
+ None => load(),
+ };
+ let durable: Vec<DurableSubagentSessionSummary> = match durable {
Ok(sessions) => sessions
.into_iter()
- .filter(|s| {
- use crate::agent::orchestration::subagent_sessions::DurableSubagentStatus;
- s.status != DurableSubagentStatus::Closed
+ .filter(|session| {
+ session.status != tinyagents_orchestration::subagent::DurableSubagentStatus::Closed
})
.take(DURABLE_ROSTER_CAP)
+ .map(|session| DurableSubagentSessionSummary::from(&session))
.collect(),
Err(err) => {
log::warn!(
@@ -60,33 +134,31 @@ pub(crate) fn active_subagents_context_block(
}
};
- if durable.is_empty() {
+ let Some(thread_id) = crate::agent::orchestration::background_completions::thread_for_session(
+ ctx,
+ parent_session,
+ ) else {
return None;
- }
- let mut block = format!(
- "[active_subagents]\n\
- You have {} sub-agent worker(s) from earlier turns. This is your authoritative \
- roster — trust it over memory. Track each by \
- subagent_session_id. {} Never fabricate a result for a worker still running \
- or one that has failed.\n",
- durable.len(),
- roster_guidance()
+ };
+ let jobs = crate::core::runtime::slot_for::<
+ tinyagents_harness_tools::subagents::SubAgentJobRegistry,
+ >(ctx);
+ let owner = crate::agent::tinyagents::tool_registration::subagent_owner_key(
+ workspace_dir,
+ parent_session,
+ Some(&thread_id),
);
- for s in &durable {
- use crate::agent::orchestration::subagent_sessions::DurableSubagentStatus;
- let status = match s.status {
- DurableSubagentStatus::Running => "running",
- DurableSubagentStatus::Idle => "idle",
- DurableSubagentStatus::AwaitingUser => "awaiting_user",
- DurableSubagentStatus::Failed => "failed",
- DurableSubagentStatus::Closed => "closed",
- };
- let task = s.current_task_id.as_deref().unwrap_or("(none)");
- block.push_str(&format!(
- "- {} · session={} · task={} · status={} · about: {}\n",
- s.agent_id, s.subagent_session_id, task, status, s.task_title
- ));
- }
- block.push_str("[/active_subagents]\n\n");
- Some(block)
+ let scope = tinyagents_orchestration::subagent::ParentJobScope::new(
+ tinytools::WorkspaceDescriptor::new(workspace_dir),
+ thread_id,
+ );
+ let block = tinyagents_orchestration::subagent::format_parent_roster_for_owner(
+ &jobs,
+ &owner,
+ &scope,
+ &durable,
+ format_roster,
+ )
+ .ok()?;
+ (!block.is_empty()).then_some(block)
}