Skip to content

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

chore: files changed crates/openhuman-core/src/flows/builder_tools/tool_contract.rs,crates/openhuman

Steven Enamakel42293ede85ec
diff --git a/crates/openhuman-core/src/flows/builder_tools/tool_contract.rs b/crates/openhuman-core/src/flows/builder_tools/tool_contract.rs
index c846fe9ea4..296ffabda2 100644
--- a/crates/openhuman-core/src/flows/builder_tools/tool_contract.rs
+++ b/crates/openhuman-core/src/flows/builder_tools/tool_contract.rs
@@ -88,37 +88,8 @@ impl Tool for GetToolContractTool {
// otherwise resolve to a bogus toolkit and come back as the catalog
// error below, which tells the model to retry a fetch that can never
// succeed.
- let Some(toolkit) = crate::flows::ops::toolkit_for_contract_slug(&slug) else {
- return Ok(ToolResult::error(format!(
- "Could not extract a toolkit from slug '{slug}' — it must look like \
- '<TOOLKIT>_<ACTION>' (e.g. 'GMAIL_SEND_EMAIL')."
- )));
- };
-
- tracing::debug!(
- target: "flows",
- %slug,
- %toolkit,
- "[flows] get_tool_contract: fetching the live contract (read-only)"
- );
-
- let Some(catalog) =
- crate::flows::tinyflows::caps::fetch_live_toolkit_catalog(&self.config, &toolkit).await
- else {
- return Ok(ToolResult::error(format!(
- "Could not fetch the live Composio catalog for toolkit '{toolkit}' (no backend \
- session, or a transient failure) — try again, or use search_tool_catalog to \
- confirm the toolkit is reachable."
- )));
- };
-
- // `action_slug_matches` also accepts a separated alias
- // (`GOOGLE_DRIVE_FIND_FILE` for `GOOGLEDRIVE_FIND_FILE`).
- match catalog
- .iter()
- .find(|c| crate::integrations::composio::contract::action_slug_matches(&c.slug, &slug))
- {
- Some(contract) => {
+ match ops::lookup_contract(&self.config, &slug).await {
+ Ok((contract, runtime_gate)) => {
// B12: a prior real-output probe (get_tool_output_sample) for
// this exact slug is ACTUAL observed data and always wins
// over the schema-derived hint — most relevant for an action
@@ -128,18 +99,11 @@ impl Tool for GetToolContractTool {
// permanently `None`.
let contract = contract.clone();
- // WS3 — EARLY runtime-gate warning (transcript failure #2): a
- // real-but-uncurated action of a toolkit that ships a curated
- // catalog is a hard curated-only allowlist at RUNTIME, so it is
- // REJECTED on every real run. The late `validate_workflow` gate
- // catches it, but only ~15 tool calls after the agent has built
- // and wired the node. Surface the blocker HERE, at contract-fetch
- // time (and first in the payload), so the agent never wires it.
- if !contract.is_curated && ops::toolkit_has_curated_catalog(&toolkit) {
+ if let Some(runtime_gate) = runtime_gate {
tracing::debug!(
target: "flows",
%slug,
- %toolkit,
+ toolkit = %contract.toolkit,
"[flows] get_tool_contract: uncurated action of a curated toolkit — attaching runtime_gate warning"
);
#[derive(serde::Serialize)]
@@ -149,10 +113,7 @@ impl Tool for GetToolContractTool {
contract: crate::flows::tinyflows::caps::ToolContract,
}
let payload = ContractWithRuntimeGate {
- runtime_gate: "This action will be REJECTED on every real run — the \
- runtime tool gate only allows curated actions for this \
- toolkit. Pick a `featured: true` result from \
- search_tool_catalog instead.",
+ runtime_gate,
contract,
};
return Ok(ToolResult::success(serde_json::to_string_pretty(&payload)?));
@@ -162,10 +123,23 @@ impl Tool for GetToolContractTool {
&contract,
)?))
}
- None => Ok(ToolResult::error(format!(
- "'{slug}' is not a real action in the '{toolkit}' toolkit's live catalog — use \
- search_tool_catalog to find a real slug."
+ Err(ops::ContractLookupError::InvalidSlug { slug }) => Ok(ToolResult::error(format!(
+ "Could not extract a toolkit from slug '{slug}' — it must look like \
+ '<TOOLKIT>_<ACTION>' (e.g. 'GMAIL_SEND_EMAIL')."
))),
+ Err(ops::ContractLookupError::CatalogUnavailable { toolkit }) => {
+ Ok(ToolResult::error(format!(
+ "Could not fetch the live Composio catalog for toolkit '{toolkit}' (no backend \
+ session, or a transient failure) — try again, or use search_tool_catalog to \
+ confirm the toolkit is reachable."
+ )))
+ }
+ Err(ops::ContractLookupError::ActionNotFound { slug, toolkit }) => {
+ Ok(ToolResult::error(format!(
+ "'{slug}' is not a real action in the '{toolkit}' toolkit's live catalog — use \
+ search_tool_catalog to find a real slug."
+ )))
+ }
}
}
}
diff --git a/crates/openhuman-core/src/flows/ops/catalog.rs b/crates/openhuman-core/src/flows/ops/catalog.rs
index 49fcb5b5fb..9301e02157 100644
--- a/crates/openhuman-core/src/flows/ops/catalog.rs
+++ b/crates/openhuman-core/src/flows/ops/catalog.rs
@@ -1,4 +1,42 @@
use super::*;
+use crate::flows::tinyflows::caps::{fetch_live_toolkit_catalog, ToolContract};
+
+pub(crate) const RUNTIME_GATE_WARNING: &str = "This action will be REJECTED on every real run — the runtime tool gate only allows curated actions for this toolkit. Pick a `featured: true` result from search_tool_catalog instead.";
+
+pub(crate) enum ContractLookupError {
+ InvalidSlug { slug: String },
+ CatalogUnavailable { toolkit: String },
+ ActionNotFound { slug: String, toolkit: String },
+}
+
+/// Resolves one live action and the runtime-curation warning used by both
+/// builder surfaces. The runtime allowlist remains authoritative; this only
+/// classifies an action so authoring can explain an inevitable rejection.
+pub(crate) async fn lookup_contract(
+ config: &Config,
+ slug: &str,
+) -> Result<(ToolContract, Option<&'static str>), ContractLookupError> {
+ let trimmed = slug.trim();
+ let Some(toolkit) = toolkit_for_contract_slug(trimmed) else {
+ return Err(ContractLookupError::InvalidSlug {
+ slug: slug.to_string(),
+ });
+ };
+ let Some(catalog) = fetch_live_toolkit_catalog(config, &toolkit).await else {
+ return Err(ContractLookupError::CatalogUnavailable { toolkit });
+ };
+ let Some(contract) = catalog.iter().find(|contract| {
+ crate::integrations::composio::contract::action_slug_matches(&contract.slug, trimmed)
+ }) else {
+ return Err(ContractLookupError::ActionNotFound {
+ slug: trimmed.to_string(),
+ toolkit,
+ });
+ };
+ let warning = (!contract.is_curated && toolkit_has_curated_catalog(&toolkit))
+ .then_some(RUNTIME_GATE_WARNING);
+ Ok((contract.clone(), warning))
+}
// ─────────────────────────────────────────────────────────────────────────────
// Catalog RPCs for the UI (Phase 5, item 16) — one implementation, two consumers
@@ -57,39 +95,26 @@ pub async fn flows_get_tool_contract(
slug: &str,
) -> Result<Outcome<Value>, String> {
let trimmed = slug.trim();
- // Shape-check before `toolkit_from_slug`, and before any I/O: the shared
- // helper is deliberately permissive, so an unshaped slug would otherwise
- // fall through to a catalog round trip and fail with an unrelated message.
- // The message quotes the caller's own slug, not `trimmed` — reporting the
- // trimmed form named an empty string back at whoever sent whitespace.
- let Some(toolkit) = toolkit_for_contract_slug(trimmed) else {
- return Err(format!(
- "Could not extract a toolkit from slug '{slug}' — it must look like \
+ let (contract, runtime_gate) =
+ lookup_contract(config, slug)
+ .await
+ .map_err(|error| match error {
+ ContractLookupError::InvalidSlug { slug } => format!(
+ "Could not extract a toolkit from slug '{slug}' — it must look like \
'<TOOLKIT>_<ACTION>' (e.g. 'GMAIL_SEND_EMAIL')."
- ));
- };
- tracing::debug!(target: "flows", slug = %trimmed, %toolkit, "[flows] flows_get_tool_contract: fetching contract");
- let Some(catalog) =
- crate::flows::tinyflows::caps::fetch_live_toolkit_catalog(config, &toolkit).await
- else {
- return Err(format!(
- "Could not fetch the live Composio catalog for toolkit '{toolkit}'."
- ));
- };
- match catalog
- .iter()
- .find(|c| crate::integrations::composio::contract::action_slug_matches(&c.slug, trimmed))
- {
- Some(contract) => {
- let contract = contract.clone();
- let value = serde_json::to_value(&contract).map_err(|e| e.to_string())?;
- Ok(Outcome::single_log(
- json!({ "contract": value }),
- "tool contract fetched",
- ))
- }
- None => Err(format!(
- "'{trimmed}' is not a real action in the '{toolkit}' toolkit's live catalog."
- )),
+ ),
+ ContractLookupError::CatalogUnavailable { toolkit } => {
+ format!("Could not fetch the live Composio catalog for toolkit '{toolkit}'.")
+ }
+ ContractLookupError::ActionNotFound { slug, toolkit } => format!(
+ "'{slug}' is not a real action in the '{toolkit}' toolkit's live catalog."
+ ),
+ })?;
+ let value = serde_json::to_value(&contract).map_err(|e| e.to_string())?;
+ tracing::debug!(target: "flows", slug = %trimmed, toolkit = %contract.toolkit, "[flows] flows_get_tool_contract: fetching contract");
+ let mut response = json!({ "contract": value });
+ if let Some(warning) = runtime_gate {
+ response["runtime_gate"] = json!(warning);
}
+ Ok(Outcome::single_log(response, "tool contract fetched"))
}
diff --git a/crates/openhuman-core/src/flows/ops/tool_contract_gate.rs b/crates/openhuman-core/src/flows/ops/tool_contract_gate.rs
index a1c798bfdb..72ae170934 100644
--- a/crates/openhuman-core/src/flows/ops/tool_contract_gate.rs
+++ b/crates/openhuman-core/src/flows/ops/tool_contract_gate.rs
@@ -90,7 +90,10 @@ pub(crate) async fn validate_tool_contracts(config: &Config, graph: &WorkflowGra
continue;
};
- let Some(contract) = catalog.iter().find(|c| c.slug.eq_ignore_ascii_case(slug)) else {
+ let Some(contract) = catalog
+ .iter()
+ .find(|c| crate::integrations::composio::contract::action_slug_matches(&c.slug, slug))
+ else {
tracing::warn!(
target: "flows",
node = %node.id,
diff --git a/crates/openhuman-core/src/flows/ops/wiring_warnings.rs b/crates/openhuman-core/src/flows/ops/wiring_warnings.rs
index c089bd1b84..23528cacd4 100644
--- a/crates/openhuman-core/src/flows/ops/wiring_warnings.rs
+++ b/crates/openhuman-core/src/flows/ops/wiring_warnings.rs
@@ -127,10 +127,9 @@ pub(super) async fn graph_output_field_warnings(
let Some(catalog) = fetch_live_toolkit_catalog(config, &ref_toolkit).await else {
continue;
};
- let Some(contract) = catalog
- .iter()
- .find(|c| c.slug.eq_ignore_ascii_case(ref_slug))
- else {
+ let Some(contract) = catalog.iter().find(|c| {
+ crate::integrations::composio::contract::action_slug_matches(&c.slug, ref_slug)
+ }) else {
continue;
};
// B12: a real-output probe (`get_tool_output_sample`) for this
@@ -268,10 +267,9 @@ async fn graph_split_out_path_warnings(config: &Config, graph: &WorkflowGraph) -
let Some(catalog) = fetch_live_toolkit_catalog(config, &pred_toolkit).await else {
continue;
};
- let Some(contract) = catalog
- .iter()
- .find(|c| c.slug.eq_ignore_ascii_case(pred_slug))
- else {
+ let Some(contract) = catalog.iter().find(|c| {
+ crate::integrations::composio::contract::action_slug_matches(&c.slug, pred_slug)
+ }) else {
continue;
};
// B12: a real-output probe overrides the schema-derived
diff --git a/crates/openhuman-core/src/flows/ops_tool_contract_and_wiring_warnings_tests.rs b/crates/openhuman-core/src/flows/ops_tool_contract_and_wiring_warnings_tests.rs
index 3eebcdbaa0..77e8ca911b 100644
--- a/crates/openhuman-core/src/flows/ops_tool_contract_and_wiring_warnings_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_tool_contract_and_wiring_warnings_tests.rs
@@ -39,9 +39,18 @@ async fn flows_get_tool_contract_rpc_warns_for_runtime_gated_uncurated_action()
.await
.expect("seeded catalog lookup should succeed");
- assert_eq!(outcome.value["contract"]["slug"], "SPOTIFY_OBSCURE_RPC_ACTION");
+ assert_eq!(
+ outcome.value["contract"]["slug"],
+ "SPOTIFY_OBSCURE_RPC_ACTION"
+ );
assert_eq!(outcome.value["contract"]["is_curated"], false);
- assert!(outcome.value["runtime_gate"].as_str().unwrap().contains("REJECTED on every real run"));
+ assert!(
+ outcome.value["runtime_gate"]
+ .as_str()
+ .is_some_and(|warning| warning.contains("REJECTED on every real run")),
+ "RPC should explain the runtime rejection: {}",
+ outcome.value
+ );
}
#[tokio::test]
@@ -58,7 +67,10 @@ async fn validate_tool_contracts_accepts_a_separated_action_slug_alias() {
let errors = validate_tool_contracts(&Config::default(), &g).await;
- assert!(errors.is_empty(), "valid action alias was rejected: {errors:?}");
+ assert!(
+ errors.is_empty(),
+ "valid action alias was rejected: {errors:?}"
+ );
}
#[tokio::test]
@@ -83,9 +95,21 @@ async fn graph_wiring_warnings_resolves_a_separated_action_slug_alias() {
let warnings = graph_wiring_warnings(&Config::default(), &g).await;
- assert_eq!(warnings.len(), 2, "alias should reach both wiring checks: {warnings:?}");
- assert!(warnings.iter().any(|warning| warning.contains("json.data.files")), "{warnings:?}");
- assert!(warnings.iter().any(|warning| warning.contains("wrong")), "{warnings:?}");
+ assert_eq!(
+ warnings.len(),
+ 2,
+ "alias should reach both wiring checks: {warnings:?}"
+ );
+ assert!(
+ warnings
+ .iter()
+ .any(|warning| warning.contains("json.data.files")),
+ "{warnings:?}"
+ );
+ assert!(
+ warnings.iter().any(|warning| warning.contains("wrong")),
+ "{warnings:?}"
+ );
}
/// (Codex feedback on this PR) `notion` ships a static curated catalog
diff --git a/crates/openhuman-core/src/flows/schemas/builder_schemas.rs b/crates/openhuman-core/src/flows/schemas/builder_schemas.rs
index eddf9001c0..17577eb63a 100644
--- a/crates/openhuman-core/src/flows/schemas/builder_schemas.rs
+++ b/crates/openhuman-core/src/flows/schemas/builder_schemas.rs
@@ -171,6 +171,11 @@ pub(super) fn lookup(function: &str) -> Option<ControllerSchema> {
ty: TypeSchema::Json,
comment: "The action contract: { slug, toolkit, description, required_args, input_schema, output_fields, output_schema, primary_array_path, is_curated }.",
required: true,
+ }, FieldSchema {
+ name: "runtime_gate",
+ ty: TypeSchema::Option(Box::new(TypeSchema::String)),
+ comment: "Present when this real action is outside the toolkit's curated runtime allowlist and will be rejected on every real run.",
+ required: false,
}],
}),
"discover" => Some(ControllerSchema {