Skip to content

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

feat(agent): add async subagent and worker thread spawn tools

Steven Enamakel7c00c96f05e4
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.rs
index bd9b1d38bc..fe8421b4e1 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
@@ -552,6 +552,7 @@ pub(crate) fn extract_workflow_proposal_from_history(
/// summary; on any persistence error the summary still carries the envelope —
/// losing durability must not lose delivery.
fn attach_workflow_proposal(
+ ctx: &DispatchCtx,
workspace_dir: &std::path::Path,
parent_thread_id: Option<&str>,
task_id: &str,
@@ -583,7 +584,7 @@ fn attach_workflow_proposal(
);
if let Some(thread_id) = parent_thread_id {
let persisted = conversations::append_message(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir.to_path_buf(),
thread_id,
ConversationMessage {
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs
index ddb7554df8..1c81d00bff 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs
@@ -259,6 +259,7 @@ impl SpawnAsyncSubagentTool {
{
if session.worker_thread_id.as_deref() == Some(worker_thread_id.as_str()) {
if let Err(err) = super::worker_thread::append_worker_user_message(
+ &dispatch,
parent.workspace_dir.clone(),
worker_thread_id,
&definition.id,
@@ -446,6 +447,7 @@ impl SpawnAsyncSubagentTool {
// thread (survives reload / reconnect) and carry the full
// payload in the delivery notice for the follow-up turn.
let delivery_summary = attach_workflow_proposal(
+ &background_dispatch,
&background_workspace_dir,
background_parent_thread_id.as_deref(),
&outcome.task_id,
@@ -527,6 +529,7 @@ impl SpawnAsyncSubagentTool {
// proposal before stalling — preserve it durably too.
let status_output = framed.clone();
let framed = attach_workflow_proposal(
+ &background_dispatch,
&background_workspace_dir,
background_parent_thread_id.as_deref(),
&outcome.task_id,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs
index 7688233e0b..7359c187e0 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs
@@ -131,6 +131,7 @@ fn build_worker_thread_title(prompt: &str) -> String {
}
fn persist_worker_thread(
+ ctx: &DispatchCtx,
workspace_dir: &std::path::Path,
agent_id: &str,
prompt: &str,
@@ -141,7 +142,7 @@ fn persist_worker_thread(
let now = chrono::Utc::now().to_rfc3339();
conversations::ensure_thread(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir.to_path_buf(),
CreateConversationThread {
id: thread_id.clone(),
@@ -156,7 +157,7 @@ fn persist_worker_thread(
.map_err(|err| format!("ensure_thread: {err}"))?;
conversations::append_message(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir.to_path_buf(),
&thread_id,
ConversationMessage {
@@ -175,7 +176,7 @@ fn persist_worker_thread(
.map_err(|err| format!("append user message: {err}"))?;
conversations::append_message(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir.to_path_buf(),
&thread_id,
ConversationMessage {
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs
index 72f1ee1818..d708b3b525 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs
@@ -256,6 +256,7 @@ impl SpawnSubagentTool {
let parent_thread_id = parent_thread_id.as_ref()?;
let title: String = prompt.chars().take(60).collect();
super::worker_thread::create_worker_thread(
+ &dispatch,
p.workspace_dir.clone(),
parent_thread_id,
&definition.id,
@@ -408,6 +409,7 @@ impl SpawnSubagentTool {
.clone()
.unwrap_or_else(|| PathBuf::from("."));
let parent_visible = match persist_worker_thread(
+ &dispatch,
&workspace_dir,
&definition.id,
&prompt,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs
index bdeed5975f..e3c36854cc 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs
@@ -241,7 +241,7 @@ impl SpawnWorkerThreadTool {
);
let threads =
- conversations::list_threads(&DispatchCtx::ambient(), parent.workspace_dir.clone())
+ conversations::list_threads(&run_context.dispatch_ctx(), parent.workspace_dir.clone())
.map_err(|e| anyhow::anyhow!(e))?;
if let Some(current_thread) = threads.iter().find(|t| t.id == current_thread_id) {
let is_delegated_label = current_thread
@@ -293,6 +293,7 @@ impl SpawnWorkerThreadTool {
// Shared with `spawn_subagent` so both delegation paths persist an
// identical, reopenable sub-thread seeded with the prompt.
let worker_thread_id = super::worker_thread::create_worker_thread(
+ &run_context.dispatch_ctx(),
parent.workspace_dir.clone(),
&current_thread_id,
&agent_id,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/worker_thread.rs b/crates/openhuman-core/src/agent/orchestration/tools/worker_thread.rs
index 95ef1f3f8b..aa4c70d2c5 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/worker_thread.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/worker_thread.rs
@@ -25,6 +25,7 @@ use crate::threads::store::{self as conversations, ConversationMessage, CreateCo
/// does not fail the call (the thread still exists and the runner will
/// append the sub-agent's turns).
pub(crate) fn create_worker_thread(
+ ctx: &DispatchCtx,
workspace_dir: PathBuf,
parent_thread_id: &str,
agent_id: &str,
@@ -35,7 +36,7 @@ pub(crate) fn create_worker_thread(
let now = chrono::Utc::now().to_rfc3339();
conversations::ensure_thread(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir.clone(),
CreateConversationThread {
id: worker_thread_id.clone(),
@@ -56,7 +57,7 @@ pub(crate) fn create_worker_thread(
);
if let Err(err) = conversations::append_message(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir,
&worker_thread_id,
ConversationMessage {
@@ -79,6 +80,7 @@ pub(crate) fn create_worker_thread(
}
pub(crate) fn append_worker_user_message(
+ ctx: &DispatchCtx,
workspace_dir: PathBuf,
worker_thread_id: &str,
agent_id: &str,
@@ -86,7 +88,7 @@ pub(crate) fn append_worker_user_message(
prompt: &str,
) -> Result<(), String> {
conversations::append_message(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir,
worker_thread_id,
ConversationMessage {