Skip to content

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

feat(flows): add connection reference gate for builder tools

Steven Enamakelc99df7d3b618
diff --git a/crates/openhuman-core/src/flows/builder_tools/connection_reads.rs b/crates/openhuman-core/src/flows/builder_tools/connection_reads.rs
index 2db6a4ce1b..41494577a6 100644
--- a/crates/openhuman-core/src/flows/builder_tools/connection_reads.rs
+++ b/crates/openhuman-core/src/flows/builder_tools/connection_reads.rs
@@ -7,7 +7,7 @@ use serde_json::{json, Value};
use crate::config::Config;
use crate::flows::ops;
-use tinytools::{PermissionLevel, Tool, ToolResult};
+use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext};
/// `list_connectable_toolkits`: read-only list of the Composio toolkits the
/// builder can wire, each tagged connected/unconnected — so the agent can steer
@@ -47,12 +47,23 @@ impl Tool for ListConnectableToolkitsTool {
false
}
- async fn execute(&self, _args: Value) -> anyhow::Result<ToolResult> {
+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.execute_with_context(args, ToolCallOptions::default(), None)
+ .await
+ }
+
+ async fn execute_with_context(
+ &self,
+ _args: Value,
+ _options: ToolCallOptions,
+ tool_context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
// The agent-ready list is the connector module's (`GetVocabulary`),
// read through the host's curated snapshot.
use crate::integrations::composio::contract::agent_ready_toolkits;
tracing::debug!(target: "flows", "[flows] list_connectable_toolkits: listing toolkits + connected state (read-only) via the memory contract");
- let connected = ops::connected_toolkits(&self.config).await;
+ let connected = ops::connected_toolkits(&ctx, &self.config).await;
let toolkits: Vec<Value> = agent_ready_toolkits()
.into_iter()
.map(|tk| {
@@ -115,9 +126,20 @@ impl Tool for ListFlowConnectionsTool {
false
}
- async fn execute(&self, _args: Value) -> anyhow::Result<ToolResult> {
+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.execute_with_context(args, ToolCallOptions::default(), None)
+ .await
+ }
+
+ async fn execute_with_context(
+ &self,
+ _args: Value,
+ _options: ToolCallOptions,
+ tool_context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
tracing::debug!(target: "flows", "[flows] list_flow_connections: enumerating connection refs (read-only)");
- match ops::flows_list_connections(&self.config).await {
+ match ops::flows_list_connections(&ctx, &self.config).await {
Ok(outcome) => {
let conns: Vec<Value> = outcome.value.iter().map(flow_connection_to_json).collect();
Ok(ToolResult::success(serde_json::to_string_pretty(
diff --git a/crates/openhuman-core/src/flows/ops/builder_gates.rs b/crates/openhuman-core/src/flows/ops/builder_gates.rs
index 6f189f277f..db316c66f9 100644
--- a/crates/openhuman-core/src/flows/ops/builder_gates.rs
+++ b/crates/openhuman-core/src/flows/ops/builder_gates.rs
@@ -217,7 +217,11 @@ 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(config, graph).await;
+ let required_connections = compute_required_connections(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ 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`
diff --git a/crates/openhuman-core/src/flows/ops/connection_ref_gate.rs b/crates/openhuman-core/src/flows/ops/connection_ref_gate.rs
index a8a559901b..1e8730ff48 100644
--- a/crates/openhuman-core/src/flows/ops/connection_ref_gate.rs
+++ b/crates/openhuman-core/src/flows/ops/connection_ref_gate.rs
@@ -60,8 +60,10 @@ pub(crate) async fn validate_connection_refs(
config: &Config,
graph: &WorkflowGraph,
) -> Vec<String> {
+ // Transitional (#7801): the builder gates carry no context yet.
+ let ctx = crate::core::runtime::DispatchCtx::ambient();
let connections: Option<Vec<FlowConnection>> =
- match crate::integrations::composio::ops::composio_list_connections(config).await {
+ match crate::integrations::composio::ops::composio_list_connections(&ctx, config).await {
Ok(outcome) => Some(build_flow_connections(
outcome.value.connections,
Vec::new(),
diff --git a/crates/openhuman-core/src/flows/ops/connections.rs b/crates/openhuman-core/src/flows/ops/connections.rs
index d437aad9ed..3f612ddb89 100644
--- a/crates/openhuman-core/src/flows/ops/connections.rs
+++ b/crates/openhuman-core/src/flows/ops/connections.rs
@@ -12,6 +12,7 @@ use super::*;
/// the HTTP credential half, and vice-versa. A failure in one source never
/// fails the whole picker.
pub async fn flows_list_connections(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
) -> Result<Outcome<Vec<FlowConnection>>, String> {
tracing::debug!(
@@ -24,7 +25,7 @@ pub async fn flows_list_connections(
// error); a backend outage returns Err — tolerate it so the picker still
// surfaces HTTP credentials.
let composio_conns =
- match crate::integrations::composio::ops::composio_list_connections(config).await {
+ match crate::integrations::composio::ops::composio_list_connections(ctx, config).await {
Ok(outcome) => {
tracing::debug!(
count = outcome.value.connections.len(),
@@ -75,7 +76,7 @@ pub async fn flows_list_connections(
// connection sync. Loaded once here so `build_flow_connections` can stay
// a pure, unit-testable matcher.
let identities =
- crate::integrations::composio::identity_store::load_connected_identities(config)
+ crate::integrations::composio::identity_store::load_connected_identities(ctx, config)
.await
.unwrap_or_else(|error| {
tracing::warn!(
@@ -281,8 +282,11 @@ pub(super) fn title_case_toolkit(toolkit: &str) -> String {
/// The set of Composio toolkits currently connected (lowercased), derived from
/// the same picker source the node-config credential dropdown uses.
-pub(crate) async fn connected_toolkits(config: &Config) -> std::collections::HashSet<String> {
- match flows_list_connections(config).await {
+pub(crate) async fn connected_toolkits(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+) -> std::collections::HashSet<String> {
+ match flows_list_connections(ctx, config).await {
Ok(outcome) => outcome
.value
.iter()
@@ -301,7 +305,11 @@ pub(crate) async fn connected_toolkits(config: &Config) -> std::collections::Has
/// canvas/proposal "Connect <toolkit>" CTAs (audit Phase 5, item 18). Native
/// `oh:` tools and `http_request` nodes need no Composio connection and are
/// skipped.
-pub async fn compute_required_connections(config: &Config, graph: &WorkflowGraph) -> Vec<Value> {
+pub async fn compute_required_connections(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ graph: &WorkflowGraph,
+) -> Vec<Value> {
use crate::integrations::composio::contract::toolkit_from_slug;
// Collect required toolkits (deduped, order-preserving).
@@ -338,7 +346,7 @@ pub async fn compute_required_connections(config: &Config, graph: &WorkflowGraph
return Vec::new();
}
- let connected = connected_toolkits(config).await;
+ let connected = connected_toolkits(ctx, config).await;
required
.into_iter()
.map(|toolkit| {
@@ -355,11 +363,12 @@ pub async fn compute_required_connections(config: &Config, graph: &WorkflowGraph
/// RPC: compute the toolkits a candidate graph needs and their connected
/// status, so the canvas/proposal can render "Connect <toolkit>" CTAs.
pub async fn flows_required_connections(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
graph_json: Value,
) -> Result<Outcome<Value>, String> {
let graph = tinyflows::migrate::deserialize_graph(graph_json)?;
- let required = compute_required_connections(config, &graph).await;
+ let required = compute_required_connections(ctx, config, &graph).await;
Ok(Outcome::single_log(
json!({ "required_connections": required }),
"required connections computed",
diff --git a/crates/openhuman-core/src/flows/schemas_handlers.rs b/crates/openhuman-core/src/flows/schemas_handlers.rs
index 8a49c97ae6..f08c03a1b6 100644
--- a/crates/openhuman-core/src/flows/schemas_handlers.rs
+++ b/crates/openhuman-core/src/flows/schemas_handlers.rs
@@ -70,7 +70,7 @@ fn handle_list(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFutur
fn handle_list_connections(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let config = ctx.load_config().await?;
- to_json(ops::flows_list_connections(&config).await?)
+ to_json(ops::flows_list_connections(&ctx, &config).await?)
})
}
@@ -362,7 +362,7 @@ fn handle_required_connections(ctx: DispatchCtx, params: Map<String, Value>) ->
Box::pin(async move {
let config = ctx.load_config().await?;
let graph = read_required::<Value>(&params, "graph")?;
- to_json(ops::flows_required_connections(&config, graph).await?)
+ to_json(ops::flows_required_connections(&ctx, &config, graph).await?)
})
}