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 handling

Steven Enamakel68a43e953f35
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 34c44ce7b5..1179cfff17 100644
--- a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
+++ b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
@@ -197,6 +197,7 @@ pub async fn start_member_run(
task_for_loop,
&rid,
model_override,
+ None,
),
)
.await;
@@ -225,23 +226,32 @@ async fn run_member_loop(
task: AgentTeamTask,
run_id: &str,
model_override: Option<String>,
+ parent_override: Option<ParentExecutionContext>,
) {
// The member acts on memory as itself within the team: its node is
// `team:<team>/agent:<agent>`, so members share the team's node and
// never read each other's.
let identity = crate::memory::scope::MemoryIdentity::team_member(team_id, agent_id);
- let member_turn = with_root_parent(config, "agent_team_runtime", "team", "teamrun", async {
- drive_member(
- config,
- team_id,
- member_id,
- agent_id,
- &task,
- run_id,
- model_override,
- )
- .await
- });
+ let member_turn = with_root_parent(
+ parent_override,
+ config,
+ "agent_team_runtime",
+ "team",
+ "teamrun",
+ |parent| async {
+ drive_member(
+ config,
+ team_id,
+ member_id,
+ agent_id,
+ &task,
+ run_id,
+ model_override,
+ parent,
+ )
+ .await
+ },
+ );
let outcome = crate::memory::scope::within(identity, Box::pin(member_turn))
.await
// Flatten: outer Err = root-parent build failure, inner = drive_member result.
@@ -273,6 +283,7 @@ async fn drive_member(
task: &AgentTeamTask,
run_id: &str,
model_override: Option<String>,
+ parent: ParentExecutionContext,
) -> Result<()> {
let ledger = SessionTeamLedger::new(
crate::agent::session_store::require_ledger(&config.workspace_dir)
@@ -294,6 +305,7 @@ async fn drive_member(
let task_id = task.id.clone();
let run_id = run_id.to_string();
move || {
+ let parent = parent.clone();
let session = session.clone();
let agent_id = agent_id.clone();
let prompt = prompt.clone();
@@ -304,20 +316,23 @@ async fn drive_member(
let run_id = run_id.clone();
async move {
let resp = session
- .spawn_agent(SpawnAgentRequest {
- agent_id,
- prompt,
- model,
- metadata: [
- ("teamId".to_string(), team_id),
- ("memberId".to_string(), member_id),
- ("taskId".to_string(), task_id),
- ("teamRunId".to_string(), run_id),
- ]
- .into_iter()
- .collect(),
- ..Default::default()
- })
+ .spawn_agent(
+ parent,
+ SpawnAgentRequest {
+ agent_id,
+ prompt,
+ model,
+ metadata: [
+ ("teamId".to_string(), team_id),
+ ("memberId".to_string(), member_id),
+ ("taskId".to_string(), task_id),
+ ("teamRunId".to_string(), run_id),
+ ]
+ .into_iter()
+ .collect(),
+ ..Default::default()
+ },
+ )
.await
.map_err(|e| anyhow!("spawn teammate worker failed: {e}"))?;
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 9205252c4d..49ca90f001 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
@@ -285,6 +285,7 @@ pub(crate) async fn run_engine_loop(
return;
}
};
+ let cancel_token = cancel.token.clone();
let outcome = with_root_parent(
parent_override,
config,
@@ -305,7 +306,7 @@ pub(crate) async fn run_engine_loop(
"workflow:{run_id}"
))));
engine
- .drive(run_id, &definition, cancel.token.clone())
+ .drive(run_id, &definition, cancel_token)
.await
.map_err(anyhow::Error::msg)
},