Skip to content

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

feat(subagent): resolve reusable sessions through the driver store

Steven Enamakelb21024b89f05
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs
index 89d312c5d7..8e34d1c1ce 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs
@@ -16,7 +16,6 @@ pub(crate) use tiny_port::{open_for_context, OpenHumanTinySubagentSessionStore};
pub use types::{
DurableSubagentStatus, SubagentSessionSelector, SubagentSessionStore, SubagentSessionUpsert,
};
-// Test-only: the host keeps the raw durable row private to its persistence
-// adapter and exposes scoped operations to production callers.
-#[cfg(test)]
-pub use types::DurableSubagentSession;
+// The spawn compatibility adapter retains this host projection while the
+// remaining lifecycle writers migrate to TinyAgents' durable store.
+pub(crate) use types::DurableSubagentSession;
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
index 6285dafb9c..ec6c1f73b3 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
@@ -1,3 +1,42 @@
+async fn find_reusable_driver_session(
+ driver: &std::sync::Arc<dyn tinyagents_orchestration::subagent::SubagentSessionStore>,
+ legacy: &SubagentSessionStore,
+ selector: &SubagentSessionSelector,
+) -> Result<Option<DurableSubagentSession>, String> {
+ use tinyagents_orchestration::subagent::SubagentSessionStore as _;
+
+ let driver_selector = tinyagents_orchestration::subagent::SubagentSessionSelector {
+ parent_session: selector.parent_session.clone(),
+ parent_thread_id: selector.parent_thread_id.clone(),
+ agent_id: selector.agent_id.clone(),
+ model: selector.model.clone(),
+ sandbox_mode: selector.sandbox_mode.clone(),
+ action_root: selector.action_root.clone(),
+ task_key: selector.task_key.clone(),
+ };
+ let sessions = driver
+ .list_for_parent(
+ &selector.parent_session,
+ selector.parent_thread_id.as_deref(),
+ )
+ .await
+ .map_err(|error| error.to_string())?;
+ let Some(selected) = tinyagents_orchestration::subagent::find_reusable_session(
+ sessions,
+ &driver_selector,
+ ) else {
+ return Ok(None);
+ };
+
+ legacy
+ .load()
+ .map(|sessions| {
+ sessions.into_iter().find(|session| {
+ session.subagent_session_id == selected.subagent_session_id
+ })
+ })
+}
+
impl SpawnSubagentTool {
async fn execute_with_context_inner(
&self,
@@ -97,6 +136,23 @@ impl SpawnSubagentTool {
)));
}
};
+ let jobs = crate::core::runtime::slot_for::<
+ tinyagents_harness_tools::subagents::SubAgentJobRegistry,
+ >(&dispatch);
+ let driver_store = match subagent_sessions::open_for_context(
+ &dispatch,
+ parent.workspace_dir.clone(),
+ parent_session.clone(),
+ parent_thread_id.clone(),
+ Some((*jobs).clone()),
+ ) {
+ Ok(store) => store,
+ Err(error) => {
+ return Ok(ToolResult::error(format!(
+ "spawn_subagent: failed to open the caller-scoped driver session store: {error}"
+ )));
+ }
+ };
let workspace_descriptor = tool_context
.and_then(|ctx| ctx.workspace().cloned())
.or_else(|| run_context.workspace.clone());
@@ -176,7 +232,7 @@ impl SpawnSubagentTool {
};
let reusable = if force_fresh {
- match subagent_sessions::find_reusable(&store, &selector) {
+ match find_reusable_driver_session(&driver_store, &store, &selector).await {
Ok(Some(session)) => {
let jobs = crate::core::runtime::slot_for::<
tinyagents_harness_tools::subagents::SubAgentJobRegistry,
@@ -224,7 +280,7 @@ impl SpawnSubagentTool {
}
None
} else {
- match subagent_sessions::find_reusable(&store, &selector) {
+ match find_reusable_driver_session(&driver_store, &store, &selector).await {
Ok(session) => session,
Err(err) => {
log::warn!(