Skip to content

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

feat(agent): add run context to tinyagents host

Steven Enamakel8b376985a7a7
diff --git a/crates/openhuman-core/src/agent/orchestration/delegation.rs b/crates/openhuman-core/src/agent/orchestration/delegation.rs
index 5589d25f8f..4f6b340dce 100644
--- a/crates/openhuman-core/src/agent/orchestration/delegation.rs
+++ b/crates/openhuman-core/src/agent/orchestration/delegation.rs
@@ -108,6 +108,10 @@ pub(crate) async fn run_subagent_delegation_with_parent_context(
stage_context.clone(),
)
.map_err(|error| format!("delegation stage context: {error}"))?;
+ // The stage run carries its own linked child token; keep the
+ // host carrier on that token (a graph cancel still reaches it
+ // through the parent) rather than the shared graph token.
+ stage_context.cancellation = stage_parent.cancellation.clone();
match run_subagent_with_parent(
&stage_parent,
definition,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 3d9e4a0699..1efa5f1dc7 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -62,7 +62,13 @@ pub(crate) fn direct_subagent_child(
.data
.child()
.with_cancellation(parent.cancellation.clone());
- let child = parent.child(child_config, child_data)?;
+ let mut child = parent.child(child_config, child_data)?;
+ // TinyAgents gives the child a linked `child_token()` of the parent's, so a
+ // parent cancel cascades down but cancelling the child (policy timeout,
+ // steering) leaves the parent running. Point the host carrier at that same
+ // child token; otherwise it keeps the parent's token and the host tools
+ // observe (and could trigger) the wrong scope.
+ child.data.cancellation = child.cancellation.clone();
Ok((task_key, child))
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
index 2e439e6db7..edb3ce09d1 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
@@ -75,6 +75,23 @@ fn direct_subagent_child_shares_tinyagents_and_host_cancellation_tree() {
assert!(child.data.cancellation.is_cancelled());
}
+#[test]
+fn cancelling_a_direct_child_reaches_host_data_and_spares_the_parent() {
+ let parent = OpenHumanRunContext::new()
+ .into_tinyagents(tinyagents_harness::context::RunConfig::new("root-iso"));
+ let (_, child) = direct_subagent_child(
+ &parent,
+ "iso-task",
+ tinyagents_harness::context::RunConfig::new("child-iso"),
+ )
+ .expect("direct child");
+
+ child.cancellation.cancel();
+ assert!(child.data.cancellation.is_cancelled());
+ assert!(!parent.cancellation.is_cancelled());
+ assert!(!parent.data.cancellation.is_cancelled());
+}
+
#[test]
fn child_inherits_tree_handles_but_isolates_observations_and_usage() {
let mut parent = OpenHumanRunContext::new();