Skip to content

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

feat(composio): add flow_gate module

Steven Enamakela283e60abcbd
diff --git a/crates/openhuman-core/src/integrations/composio/flow_gate.rs b/crates/openhuman-core/src/integrations/composio/flow_gate.rs
new file mode 100644
index 0000000000..667cd2d8d7
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/flow_gate.rs
@@ -0,0 +1,187 @@
+//! Composio policy used by flow stages and capability adapters.
+//!
+//! This module owns the host's Composio-specific decisions. It accepts plain
+//! product inputs and returns ordinary values so it stays independent of the
+//! flow engine implementation.
+
+use serde_json::Value;
+
+use crate::config::Config;
+
+/// Extracts a connection id from a `composio:<toolkit>:<id>` reference.
+pub(crate) fn composio_connection_id(conn: &str) -> Option<&str> {
+ let rest = conn.strip_prefix("composio:")?;
+ let id = rest.rsplit(':').next()?;
+ (!id.is_empty()).then_some(id)
+}
+
+/// Whether a slug needs a live connected-toolkit set to be authorized.
+pub(crate) fn slug_needs_connected_set(slug: &str) -> bool {
+ use crate::integrations::composio::contract::{catalog_for_toolkit, toolkit_from_slug};
+ toolkit_from_slug(slug).is_some_and(|toolkit| catalog_for_toolkit(&toolkit).is_none())
+}
+
+/// Current active connected toolkits, with last-known cache fallback on outage.
+pub(crate) async fn connected_toolkit_slugs(config: &Config) -> Option<Vec<String>> {
+ use crate::integrations::composio::{
+ cached_active_integrations, fetch_connected_integrations_status,
+ FetchConnectedIntegrationsStatus,
+ };
+
+ let integrations = match fetch_connected_integrations_status(config).await {
+ FetchConnectedIntegrationsStatus::Authoritative(items) => items,
+ FetchConnectedIntegrationsStatus::Unavailable => match cached_active_integrations(config) {
+ Some(items) => {
+ tracing::warn!(target: "flows", "[flows] connected-toolkit lookup: backend unavailable — using last-known (possibly stale) cached connections for the tool_call allowlist");
+ items
+ }
+ None => {
+ tracing::warn!(target: "flows", "[flows] connected-toolkit lookup: backend unavailable and no cached snapshot — connected-toolkit allowlist is empty this call");
+ return None;
+ }
+ },
+ };
+ Some(
+ integrations
+ .into_iter()
+ .filter(|item| item.connected)
+ .map(|item| item.toolkit.to_ascii_lowercase())
+ .collect(),
+ )
+}
+
+/// Deny-by-default Composio flow-tool policy, including user scope preference.
+pub(crate) async fn flow_tool_allowed(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ slug: &str,
+ connected_toolkits: Option<&[String]>,
+) -> bool {
+ use crate::integrations::composio::contract::{
+ catalog_for_toolkit, classify_unknown, find_curated, toolkit_from_slug,
+ };
+ use crate::integrations::composio::ops::load_user_scope_pref;
+
+ let Some(toolkit) = toolkit_from_slug(slug) else {
+ tracing::debug!(target: "flows", %slug, "[flows] tool_call curation: reject — slug has no extractable toolkit prefix");
+ return false;
+ };
+ if let Some(catalog) = catalog_for_toolkit(&toolkit) {
+ let Some(curated) = find_curated(&catalog, slug) else {
+ tracing::debug!(target: "flows", %slug, %toolkit, "[flows] tool_call curation: reject — slug is not a curated action of this toolkit");
+ return false;
+ };
+ let allowed = load_user_scope_pref(ctx, config, &toolkit)
+ .await
+ .allows(curated.scope);
+ tracing::debug!(target: "flows", %slug, %toolkit, allowed, "[flows] tool_call curation: static curated catalog decision");
+ return allowed;
+ }
+
+ if !connected_toolkits.is_some_and(|toolkits| {
+ toolkits.iter().any(|item| item.eq_ignore_ascii_case(&toolkit))
+ }) {
+ tracing::debug!(target: "flows", %slug, %toolkit, "[flows] tool_call curation: reject — toolkit has no static catalog and is not connected");
+ return false;
+ }
+ let Some(live_catalog) = crate::integrations::composio::catalog::fetch_live_toolkit_catalog(config, &toolkit).await else {
+ tracing::warn!(target: "flows", %slug, %toolkit, "[flows] tool_call curation: reject — connected but the live catalog fetch failed (fail-closed)");
+ return false;
+ };
+ if !live_catalog.iter().any(|item| item.slug.eq_ignore_ascii_case(slug)) {
+ tracing::debug!(target: "flows", %slug, %toolkit, "[flows] tool_call curation: reject — slug is not a real action in this toolkit's live catalog");
+ return false;
+ }
+ let allowed = load_user_scope_pref(ctx, config, &toolkit)
+ .await
+ .allows(classify_unknown(slug));
+ tracing::debug!(target: "flows", %slug, %toolkit, allowed, "[flows] tool_call curation: live catalog + scope decision");
+ allowed
+}
+
+/// Classifies a curated action for the autonomy-tier gate.
+pub(crate) fn classify_composio_action_for_tier(slug: &str) -> tinybox_bus::CommandClass {
+ use crate::integrations::composio::contract::{curated_scope_for, ToolScope};
+ use tinybox_bus::CommandClass;
+ match curated_scope_for(slug) {
+ Some(ToolScope::Read) => CommandClass::Read,
+ Some(ToolScope::Write) | Some(ToolScope::Admin) | None => CommandClass::Network,
+ }
+}
+
+/// Resolves a connection id to its toolkit and display label from a snapshot.
+pub(crate) fn resolve_account<'a>(
+ integrations: &'a [crate::integrations::composio::ConnectedIntegration],
+ connection_id: &str,
+) -> Option<(&'a str, Option<&'a str>)> {
+ integrations.iter().find_map(|integration| {
+ integration
+ .connections
+ .iter()
+ .find(|connection| connection.connection_id == connection_id)
+ .map(|connection| (integration.toolkit.as_str(), connection.label.as_deref()))
+ })
+}
+
+/// Best-effort account lookup used for safe execution logging.
+pub(crate) async fn resolve_composio_account(
+ config: &Config,
+ connection_id: &str,
+) -> Option<(String, Option<String>)> {
+ let integrations = crate::integrations::composio::fetch_connected_integrations(config).await;
+ resolve_account(&integrations, connection_id)
+ .map(|(toolkit, label)| (toolkit.to_string(), label.map(str::to_string)))
+}
+
+/// Runs the product-owned static and live-catalog required-argument checks.
+pub(crate) async fn preflight_composio_args(
+ config: &Config,
+ slug: &str,
+ args: &Value,
+) -> Result<(), String> {
+ if let Err(error) = crate::integrations::composio::processing::prepare(
+ config,
+ slug,
+ Some(args.clone()),
+ None,
+ None,
+ )
+ .await
+ {
+ tracing::warn!(target: "flows", %slug, error = %error, "[flows] preflight: static arg rule rejected the call — failing before dispatch");
+ return Err(format!("tool_call `{slug}`: {error}"));
+ }
+ let Some(required) = crate::integrations::composio::catalog::composio_required_args(config, slug).await else {
+ tracing::info!(target: "flows", %slug, "[flows] preflight: no live catalog schema for action — required-arg check limited to static rules");
+ return Ok(());
+ };
+ let missing: Vec<_> = required
+ .iter()
+ .filter(|name| args.get(name.as_str()).is_none_or(Value::is_null))
+ .collect();
+ if missing.is_empty() {
+ tracing::debug!(target: "flows", %slug, "[flows] preflight: all required args present");
+ return Ok(());
+ }
+ tracing::warn!(target: "flows", %slug, ?missing, "[flows] preflight: required arg(s) missing or null — failing before dispatch");
+ let list = missing.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>().join(", ");
+ let first = missing[0];
+ Err(format!("tool_call `{slug}`: required arg(s) {list} missing or resolved to null — wire each from an upstream node's output, e.g. \"{first}\": \"=nodes.<node_id>.item.json.<field>\" (drop `.json` only if `<node_id>` is a code/transform/split_out/merge/trigger node — `agent`/`tool_call`/`http_request` nodes wrap their output in a `{{json,text,raw}}` envelope). If the value comes from an agent node, give that agent an output schema (config.output_parser.schema) so its fields are addressable."))
+}
+
+/// Converts a provider-side unsuccessful execution response into a policy error.
+pub(crate) fn reject_unsuccessful_composio_response(
+ slug: &str,
+ response: crate::integrations::composio::ComposioExecuteResponse,
+) -> Result<crate::integrations::composio::ComposioExecuteResponse, String> {
+ if response.successful {
+ return Ok(response);
+ }
+ let detail = response
+ .error
+ .as_deref()
+ .map(str::trim)
+ .filter(|value| !value.is_empty())
+ .unwrap_or("no error detail returned by the provider");
+ Err(format!("tool_call `{slug}` failed at the connected provider: {detail}"))
+}
diff --git a/crates/openhuman-core/src/integrations/composio/mod.rs b/crates/openhuman-core/src/integrations/composio/mod.rs
index f5e32080e2..a902040042 100644
--- a/crates/openhuman-core/src/integrations/composio/mod.rs
+++ b/crates/openhuman-core/src/integrations/composio/mod.rs
@@ -44,6 +44,7 @@ pub mod client;
pub mod connected_integrations;
pub mod contract;
pub mod contract_gate;
+pub mod flow_gate;
pub(crate) mod direct_auth;
pub mod execute_dispatch;
pub(crate) mod file_store;