Skip to content

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

feat(composio): validate flow tool calls against the live catalog

Steven Enamakelc90fae861c23
diff --git a/crates/openhuman-core/src/integrations/composio/contract/validation.rs b/crates/openhuman-core/src/integrations/composio/contract/validation.rs
index 634dbc6d23..20bd0b0db1 100644
--- a/crates/openhuman-core/src/integrations/composio/contract/validation.rs
+++ b/crates/openhuman-core/src/integrations/composio/contract/validation.rs
@@ -15,6 +15,14 @@ pub(crate) struct ConnectedAccountRef {
pub toolkit: Option<String>,
}
+/// A flow tool call reduced to the fields needed for contract validation.
+#[derive(Debug, Clone)]
+pub(crate) struct ToolContractNode {
+ pub id: String,
+ pub slug: String,
+ pub args: Value,
+}
+
/// Parses a `composio:<toolkit>:<connection_id>` reference.
pub(crate) fn parse_composio_connection_ref(conn_ref: &str) -> Option<(&str, &str)> {
let rest = conn_ref.strip_prefix("composio:")?;
@@ -100,3 +108,93 @@ pub(crate) fn validate_connection_refs(
}
errors
}
+
+/// Checks live action existence, curated runtime eligibility, and its args.
+pub(crate) async fn validate_tool_contract_nodes(
+ config: &crate::config::Config,
+ nodes: &[ToolContractNode],
+) -> Vec<String> {
+ use crate::integrations::composio::{catalog, contract};
+
+ let mut errors = Vec::new();
+ for node in nodes {
+ let slug = node.slug.as_str();
+ if slug.starts_with('=') || slug.starts_with("oh:") {
+ continue;
+ }
+ let Some(toolkit) = contract::toolkit_from_slug(slug) else {
+ continue;
+ };
+ let Some(actions) = catalog::fetch_live_toolkit_catalog(config, &toolkit).await else {
+ tracing::debug!(target: "flows", node = %node.id, %slug, %toolkit, "[flows] tool-contract check: live catalog fetch failed — skipping (best-effort, never false-rejects)");
+ continue;
+ };
+ let Some(action) = actions
+ .iter()
+ .find(|item| contract::action_slug_matches(&item.slug, slug))
+ else {
+ tracing::warn!(target: "flows", node = %node.id, %slug, %toolkit, "[flows] tool-contract check: slug is not a real action in the live catalog — rejecting");
+ errors.push(format!("Node '{}': `{slug}` is not a real action in the `{toolkit}` toolkit's live \
+ Composio catalog — use search_tool_catalog {{ query: ..., toolkit: \"{toolkit}\" \
+ }} to find a real action slug.", node.id));
+ continue;
+ };
+ if catalog::has_curated_catalog(&toolkit) && !action.is_curated {
+ tracing::warn!(target: "flows", node = %node.id, %slug, %toolkit, "[flows] tool-contract check: slug is real but not curated for a statically-catalogued toolkit — rejecting to match the runtime allowlist");
+ errors.push(format!("Node '{}': `{slug}` is a real `{toolkit}` action but not one of OpenHuman's \
+ curated actions for `{toolkit}` — the runtime tool gate only allows curated \
+ actions for toolkits with a curated catalog, so this would be rejected on \
+ every run. Use search_tool_catalog {{ query: ..., toolkit: \"{toolkit}\" }} and \
+ pick a result with `featured: true`.", node.id));
+ continue;
+ }
+ let missing: Vec<_> = action.required_args.iter()
+ .filter(|name| node.args.get(name.as_str()).is_none_or(Value::is_null))
+ .collect();
+ if !missing.is_empty() {
+ tracing::warn!(target: "flows", node = %node.id, %slug, ?missing, "[flows] tool-contract check: required arg(s) missing or null — rejecting");
+ let list = missing.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>().join(", ");
+ errors.push(format!("Node '{}': tool_call `{slug}` is missing required arg(s) {list} — wire each \
+ from an upstream node's output, e.g. \"{}\": \
+ \"=nodes.<node_id>.item.json.<field>\" (call get_tool_contract {{ slug: \
+ \"{slug}\" }} for the exact required_args list).", node.id, missing[0]));
+ }
+ if let Some(unsupported) = unsupported_arg_names(action.input_schema.as_ref(), &node.args) {
+ if !unsupported.is_empty() {
+ let mut valid_names = action.input_schema.as_ref()
+ .and_then(|schema| schema.get("properties"))
+ .and_then(Value::as_object)
+ .map(|properties| properties.keys().cloned().collect::<Vec<_>>())
+ .unwrap_or_default();
+ valid_names.sort();
+ tracing::warn!(target: "flows", node = %node.id, %slug, ?unsupported, ?valid_names, "[flows] tool-contract check: arg name(s) not declared by the action's input schema — rejecting");
+ let bad_list = unsupported.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>().join(", ");
+ let valid_suffix = if valid_names.is_empty() { String::new() } else { format!(" — valid arg names for `{slug}` are: {}", valid_names.join(", ")) };
+ errors.push(format!("Node '{}': tool_call `{slug}` has unsupported arg name(s) {bad_list} — not \
+ a property of this action's input schema{valid_suffix}. Call \
+ get_tool_contract {{ slug: \"{slug}\" }} and use the exact property names \
+ from `input_schema` (never guess an arg name).", node.id));
+ }
+ }
+ }
+ errors
+}
+
+fn unsupported_arg_names(schema: Option<&Value>, args: &Value) -> Option<Vec<String>> {
+ let schema = schema?.as_object()?;
+ if schema.get("additionalProperties").is_some_and(|value| value.as_bool() == Some(true) || value.is_object()) {
+ return None;
+ }
+ let properties = schema.get("properties")?.as_object()?;
+ let patterns = match schema.get("patternProperties").and_then(Value::as_object) {
+ Some(patterns) => patterns.keys().map(|pattern| regex::Regex::new(pattern))
+ .collect::<Result<Vec<_>, _>>().ok()?,
+ None => Vec::new(),
+ };
+ let Some(args) = args.as_object() else { return Some(Vec::new()) };
+ let mut unsupported = args.keys().filter(|key| {
+ !properties.contains_key(key.as_str()) && !patterns.iter().any(|pattern| pattern.is_match(key))
+ }).cloned().collect::<Vec<_>>();
+ unsupported.sort();
+ Some(unsupported)
+}