Skip to content

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

feat(flows): add builder host and gate operations

Steven Enamakel5d1ae07cddcf
diff --git a/crates/openhuman-core/src/flows/builder_host.rs b/crates/openhuman-core/src/flows/builder_host.rs
index 9888576a02..8082c2d451 100644
--- a/crates/openhuman-core/src/flows/builder_host.rs
+++ b/crates/openhuman-core/src/flows/builder_host.rs
@@ -233,7 +233,7 @@ impl AgentDirectory for FlowsHost {
async fn list(&self) -> PortResult<Vec<AgentDefinition>> {
let agents = crate::agent::registry::list_agents(&self.ctx(), false)
.await
- .map_err(|e| e.to_string())?;
+ .map_err(|e| e.to_string())?;
Ok(agents
.iter()
.map(|a| AgentDefinition {
diff --git a/crates/openhuman-core/src/flows/ops/builder_gates.rs b/crates/openhuman-core/src/flows/ops/builder_gates.rs
index bbc1869813..41598b697f 100644
--- a/crates/openhuman-core/src/flows/ops/builder_gates.rs
+++ b/crates/openhuman-core/src/flows/ops/builder_gates.rs
@@ -135,8 +135,12 @@ impl tinyflows::gates::BuilderGateHost for OpenHumanBuilderGateHost<'_> {
use tinyflows::gates::HostGateStage;
Ok(match stage {
HostGateStage::ToolPolicy => validate_upload_paths(graph),
- HostGateStage::AgentReferences => validate_agent_refs(self.ctx, self.config, graph).await,
- HostGateStage::Connections => validate_connection_refs(self.ctx, self.config, graph).await,
+ HostGateStage::AgentReferences => {
+ validate_agent_refs(self.ctx, self.config, graph).await
+ }
+ HostGateStage::Connections => {
+ validate_connection_refs(self.ctx, self.config, graph).await
+ }
HostGateStage::ToolContracts => validate_tool_contracts(self.config, graph).await,
})
}
@@ -227,8 +231,7 @@ pub(crate) async fn build_builder_proposal(
// Connector onboarding (Phase 5, item 18): tell the proposal card which
// toolkits this graph needs and whether they're connected, so it can render
// "Connect <toolkit>" CTAs instead of a bare gate error later.
- let required_connections =
- compute_required_connections(ctx, config, graph).await;
+ let required_connections = compute_required_connections(ctx, config, graph).await;
// B45 (design correction): the LLM-provider-connectivity evaluation is
// ADVISORY here, never a rejection — `run_builder_gates` above no longer
// includes it (that used to hard-block `propose_workflow`/`edit_workflow`
@@ -399,9 +402,7 @@ pub(crate) async fn validate_agent_refs(
}
AgentRoute::RegistryFallback => {
if custom_registry.is_none() {
- custom_registry = Some(
- crate::agent::registry::list_agents(ctx, true).await,
- );
+ custom_registry = Some(crate::agent::registry::list_agents(ctx, true).await);
}
match custom_registry.as_ref().expect("just populated") {
Ok(entries) => match entries.iter().find(|entry| entry.id == agent_ref) {
diff --git a/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs b/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs
index e8300d0348..84c766803b 100644
--- a/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs
@@ -17,7 +17,8 @@ async fn agent_ref_plain_node_without_ref_is_accepted() {
],
"edges": [ { "from_node": "t", "to_node": "a" } ]
}));
- let errors = validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
+ let errors =
+ validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
assert!(errors.is_empty(), "{errors:?}");
}
@@ -35,7 +36,8 @@ async fn agent_ref_blank_string_is_treated_as_absent() {
],
"edges": [ { "from_node": "t", "to_node": "a" } ]
}));
- let errors = validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
+ let errors =
+ validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
assert!(errors.is_empty(), "{errors:?}");
}
@@ -61,7 +63,8 @@ async fn agent_ref_resolving_to_a_harness_definition_is_accepted() {
],
"edges": [ { "from_node": "t", "to_node": "a" } ]
}));
- let errors = validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
+ let errors =
+ validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
assert!(
errors.is_empty(),
"a real harness agent_ref must never be rejected: {errors:?}"
@@ -86,7 +89,8 @@ async fn agent_ref_unknown_is_rejected() {
],
"edges": [ { "from_node": "t", "to_node": "a" } ]
}));
- let errors = validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
+ let errors =
+ validate_agent_refs(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
assert!(!errors.is_empty(), "an unknown agent_ref must be rejected");
assert!(
errors.iter().any(|e| e.contains("no_such_agent_xyz")),
@@ -472,3 +476,64 @@ async fn harness_readiness_checks_session_for_execution_provider() {
}
}
}
+
+/// The agent-ref gate resolves a custom agent through the context it is handed,
+/// not the one the calling task happens to run under: two tenants' registries
+/// never cross.
+#[tokio::test]
+async fn agent_ref_gate_reads_the_registry_of_the_explicit_context() {
+ use crate::agent::registry::types::{AgentRegistryEntry, AgentRegistrySource};
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+
+ let entry = AgentRegistryEntry {
+ id: "tenant_a_only_agent".to_string(),
+ name: "A".to_string(),
+ description: "registered for tenant A".to_string(),
+ source: AgentRegistrySource::Custom,
+ enabled: true,
+ model: None,
+ system_prompt: None,
+ tool_allowlist: Vec::new(),
+ tool_denylist: Vec::new(),
+ tool_rules: None,
+ subagents: Default::default(),
+ tags: Vec::new(),
+ metadata: Value::Null,
+ };
+ let tmp_a = TempDir::new().unwrap();
+ let tmp_b = TempDir::new().unwrap();
+ let mut config_a = test_config(&tmp_a);
+ config_a.agent_registry.entries.push(entry);
+ let config_b = test_config(&tmp_b);
+ let core_a = CoreContext::for_test_with_config(DomainSet::full(), config_a.clone());
+ let core_b = CoreContext::for_test_with_config(DomainSet::full(), config_b.clone());
+ let ctx_a = DispatchCtx::new(core_a);
+ let ctx_b = DispatchCtx::new(std::sync::Arc::clone(&core_b));
+
+ let g = graph(json!({
+ "nodes": [
+ { "id": "t", "kind": "trigger", "name": "Manual" },
+ { "id": "a", "kind": "agent", "name": "Plan",
+ "config": { "agent_ref": "tenant_a_only_agent", "prompt": "go" } }
+ ],
+ "edges": [ { "from_node": "t", "to_node": "a" } ]
+ }));
+
+ // Both calls run scoped to tenant B, so an ambient read would answer B's
+ // registry for A's call.
+ let (for_a, for_b) = CoreContext::scope(core_b, async {
+ (
+ validate_agent_refs(&ctx_a, &config_a, &g).await,
+ validate_agent_refs(&ctx_b, &config_b, &g).await,
+ )
+ })
+ .await;
+ assert!(
+ for_a.is_empty(),
+ "tenant A's own agent must resolve: {for_a:?}"
+ );
+ assert!(
+ for_b.iter().any(|e| e.contains("tenant_a_only_agent")),
+ "tenant B must not see tenant A's agent: {for_b:?}"
+ );
+}
diff --git a/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs b/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
index 5e5eecc3d8..5e912bbe5e 100644
--- a/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
@@ -46,7 +46,8 @@ async fn run_builder_gates_does_not_reject_when_signed_out() {
],
"edges": [ { "from_node": "t", "to_node": "a" } ]
}));
- let errors = run_builder_gates(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
+ let errors =
+ run_builder_gates(&crate::core::runtime::DispatchCtx::ambient(), &config, &g).await;
assert!(
errors.is_empty(),
"authoring must not be blocked by a signed-out session: {errors:?}"
diff --git a/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs b/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs
index 1450eaf3ce..46053d9346 100644
--- a/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs
@@ -334,21 +334,33 @@ async fn flows_update_does_not_force_require_approval_on_readonly_graph() {
async fn strict_gate_passes_a_valid_graph_and_rejects_a_structurally_invalid_one() {
let config = Config::default();
// A trigger-only graph is structurally valid and has no outbound gates.
- assert!(strict_gate(&crate::core::runtime::DispatchCtx::ambient(), &config, &trigger_only_graph()).await.is_ok());
+ assert!(strict_gate(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &trigger_only_graph()
+ )
+ .await
+ .is_ok());
// No trigger → structural failure surfaced by strict mode.
let bad = json!({
"nodes": [ { "id": "a", "kind": "output_parser", "name": "A" } ],
"edges": []
});
- let err = strict_gate(&crate::core::runtime::DispatchCtx::ambient(), &config, &bad).await.unwrap_err();
+ let err = strict_gate(&crate::core::runtime::DispatchCtx::ambient(), &config, &bad)
+ .await
+ .unwrap_err();
assert!(err.contains("structurally invalid"), "{err}");
assert!(err.contains("trigger"), "{err}");
// A structurally valid graph must still pass the shared engine gate.
- let err = strict_gate(&crate::core::runtime::DispatchCtx::ambient(), &config, &nested_conditional_fan_in_graph())
- .await
- .unwrap_err();
+ let err = strict_gate(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &nested_conditional_fan_in_graph(),
+ )
+ .await
+ .unwrap_err();
assert!(err.contains(UNSUPPORTED_NESTED_CONDITIONAL_FAN_IN), "{err}");
}
@@ -365,9 +377,13 @@ async fn strict_gate_rejects_an_incompatible_saved_child_reference() {
)
.unwrap();
- let error = strict_gate(&crate::core::runtime::DispatchCtx::ambient(), &config, &referenced_child_graph(&child.id))
- .await
- .expect_err("strict authoring must reject an incompatible saved child");
+ let error = strict_gate(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &referenced_child_graph(&child.id),
+ )
+ .await
+ .expect_err("strict authoring must reject an incompatible saved child");
assert!(
error.contains(UNSUPPORTED_NESTED_CONDITIONAL_FAN_IN),
"{error}"