Skip to content

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

feat(agent): add team runtime and workflow lifecycle support

Steven Enamakel4e5fd793049a
diff --git a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
index f206b7c98b..573149f55b 100644
--- a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
+++ b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
@@ -95,6 +95,7 @@ pub enum StartMemberOutcome {
/// unknown, or the member has nothing claimable. An unknown member surfaces as
/// [`TeamError::UnknownMember`].
pub async fn start_member_run(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
team_id: &str,
member_id: &str,
@@ -178,6 +179,7 @@ pub async fn start_member_run(
.clone()
.unwrap_or_else(|| DEFAULT_TEAMMATE_AGENT_ID.to_string());
let cfg = config.clone();
+ let task_ctx = ctx.clone();
let team = team_id.to_string();
let mem = member_id.to_string();
let task_for_loop = claimed.clone();
@@ -191,6 +193,7 @@ pub async fn start_member_run(
crate::agent::turn_origin::with_inherited_origin(
inherited_origin,
run_member_loop(
+ &task_ctx,
&cfg,
&team,
&mem,
@@ -220,6 +223,7 @@ pub async fn start_member_run(
/// and idle the member so the work is reclaimable; they are recorded, not
/// propagated (there is no caller on the spawned task).
async fn run_member_loop(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
team_id: &str,
member_id: &str,
@@ -236,6 +240,7 @@ async fn run_member_loop(
// host environment, so every run started from that parent keeps it.
let identity = crate::memory::scope::MemoryIdentity::team_member(team_id, agent_id);
let member_turn = with_root_parent(
+ ctx,
parent_override,
config,
"agent_team_runtime",
diff --git a/crates/openhuman-core/src/agent/orchestration/agent_teams/schemas.rs b/crates/openhuman-core/src/agent/orchestration/agent_teams/schemas.rs
index 745a7b52b3..d52aeb1b7f 100644
--- a/crates/openhuman-core/src/agent/orchestration/agent_teams/schemas.rs
+++ b/crates/openhuman-core/src/agent/orchestration/agent_teams/schemas.rs
@@ -485,6 +485,7 @@ fn handle_start_member(ctx: DispatchCtx, params: Map<String, Value>) -> Controll
// Test-only seam: pin the spawned worker to a model (e.g. the e2e mock).
let model_override = opt_str(&params, "modelOverride");
let outcome = runtime::start_member_run(
+ &ctx,
&config,
&team_id,
&member_id,
diff --git a/crates/openhuman-core/src/agent/orchestration/parent_context/builder.rs b/crates/openhuman-core/src/agent/orchestration/parent_context/builder.rs
index 23a5272fab..09beda1f66 100644
--- a/crates/openhuman-core/src/agent/orchestration/parent_context/builder.rs
+++ b/crates/openhuman-core/src/agent/orchestration/parent_context/builder.rs
@@ -50,6 +50,7 @@ const LOG_TARGET: &str = "agent_orchestration::parent_context";
/// Every other field is inherited verbatim from the config-built agent, so the
/// spawned children behave exactly like a normal sub-agent dispatch.
pub(crate) async fn build_root_parent(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
agent_definition_id: &str,
channel: &str,
@@ -83,7 +84,7 @@ pub(crate) async fn build_root_parent(
}
}
- let mut agent = OpenHumanSessionHost::from_config(config)
+ let mut agent = OpenHumanSessionHost::from_config(ctx, config)
.context("build Agent from config for orchestration root parent")?;
let integrations = crate::integrations::composio::fetch_connected_integrations(config).await;
@@ -142,6 +143,7 @@ pub(crate) async fn build_root_parent(
/// when the root context can't be constructed — the caller decides how to
/// degrade (fail the run, or fall back to an un-grounded path).
pub(crate) async fn with_root_parent<F, Fut>(
+ ctx: &crate::core::runtime::DispatchCtx,
parent_override: Option<ParentExecutionContext>,
config: &Config,
agent_definition_id: &str,
@@ -155,7 +157,7 @@ where
{
let parent = match parent_override {
Some(parent) => parent,
- None => build_root_parent(config, agent_definition_id, channel, session_prefix).await?,
+ None => build_root_parent(ctx, config, agent_definition_id, channel, session_prefix).await?,
};
Ok(run(parent).await)
}
diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs
index d4628b6c93..e969a2fe84 100644
--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs
@@ -75,7 +75,7 @@ pub async fn start_workflow_run(
Ok(task_config) => {
crate::agent::turn_origin::with_inherited_origin(
inherited_origin,
- run_engine_loop(&task_config, &task_run_id, definition, cancel, None),
+ run_engine_loop(&task_ctx, &task_config, &task_run_id, definition, cancel, None),
)
.await;
}
@@ -219,7 +219,7 @@ pub async fn resume_workflow_run(
Ok(task_config) => {
crate::agent::turn_origin::with_inherited_origin(
inherited_origin,
- run_engine_loop(&task_config, &task_run_id, definition, cancel, None),
+ run_engine_loop(&task_ctx, &task_config, &task_run_id, definition, cancel, None),
)
.await;
}
@@ -243,6 +243,7 @@ pub async fn resume_workflow_run(
/// an owned [`Config`]. Errors are recorded on the run row (status `Failed`)
/// rather than propagated — there is no caller to receive them.
pub(crate) async fn run_engine_loop(
+ ctx: &DispatchCtx,
config: &Config,
run_id: &str,
definition: WorkflowDefinition,
@@ -295,6 +296,7 @@ pub(crate) async fn run_engine_loop(
};
let cancel_token = cancel.token.clone();
let outcome = with_root_parent(
+ ctx,
parent_override,
config,
"workflow_engine",
diff --git a/crates/openhuman-core/src/agent/triage/escalation.rs b/crates/openhuman-core/src/agent/triage/escalation.rs
index 218226e70c..21f372da29 100644
--- a/crates/openhuman-core/src/agent/triage/escalation.rs
+++ b/crates/openhuman-core/src/agent/triage/escalation.rs
@@ -230,10 +230,11 @@ pub async fn apply_decision(
/// `allowed_subagent_ids`: the escalated agent may itself nested-spawn only the
/// dispatched target (the builder defaults this to empty for background roots).
async fn build_triage_parent(
+ ctx: &DispatchCtx,
config: &Config,
agent_id: &str,
) -> anyhow::Result<ParentExecutionContext> {
- let mut parent_ctx = build_root_parent(config, "triage", "triage", "triage")
+ let mut parent_ctx = build_root_parent(ctx, config, "triage", "triage", "triage")
.await
.context("building root parent for sub-agent dispatch")?;
parent_ctx.allowed_subagent_ids = [agent_id.to_string()].into_iter().collect();
@@ -256,7 +257,7 @@ async fn dispatch_target_agent(
.await
.context("loading config for sub-agent dispatch")?;
- let parent_ctx = build_triage_parent(&config, agent_id).await?;
+ let parent_ctx = build_triage_parent(ctx, &config, agent_id).await?;
// `build_root_parent` (inside `build_triage_parent`) guarantees the registry
// is initialised, so this lookup for the target definition is safe here.