Skip to content

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

fix(composio): gate agent writes for approval

simple_naivee3e6954e1ab5
diff --git a/src/openhuman/integrations/composio/action_tool.rs b/src/openhuman/integrations/composio/action_tool.rs
index e639e17b4f..3cddef93d5 100644
--- a/src/openhuman/integrations/composio/action_tool.rs
+++ b/src/openhuman/integrations/composio/action_tool.rs
@@ -148,6 +148,10 @@ impl Tool for ComposioActionTool {
PermissionLevel::Write
}
+ fn external_effect(&self) -> bool {
+ super::tools::action_mutates_external_state(&self.action_name)
+ }
+
fn category(&self) -> ToolCategory {
ToolCategory::Workflow
}
diff --git a/src/openhuman/integrations/composio/action_tool_tests.rs b/src/openhuman/integrations/composio/action_tool_tests.rs
index 767d9d9e6b..be7f8b7705 100644
--- a/src/openhuman/integrations/composio/action_tool_tests.rs
+++ b/src/openhuman/integrations/composio/action_tool_tests.rs
@@ -96,6 +96,25 @@ fn display_label_is_human_and_detail_pulls_recipient() {
);
}
+#[test]
+fn per_action_tool_requires_approval_for_external_writes_only() {
+ let write = ComposioActionTool::new(
+ fake_config(),
+ "GMAIL_SEND_EMAIL".to_string(),
+ "send".to_string(),
+ None,
+ );
+ let read = ComposioActionTool::new(
+ fake_config(),
+ "GMAIL_FETCH_EMAILS".to_string(),
+ "fetch".to_string(),
+ None,
+ );
+
+ assert!(write.external_effect_with_args(&serde_json::Value::Null));
+ assert!(!read.external_effect_with_args(&serde_json::Value::Null));
+}
+
#[tokio::test]
async fn sandbox_read_only_blocks_per_action_write_call() {
let t = ComposioActionTool::new(
diff --git a/src/openhuman/integrations/composio/tools_part_01.rs b/src/openhuman/integrations/composio/tools_part_01.rs
index 4e4194f8c4..0f1f0f614a 100644
--- a/src/openhuman/integrations/composio/tools_part_01.rs
+++ b/src/openhuman/integrations/composio/tools_part_01.rs
@@ -47,6 +47,11 @@ enum ToolDecision {
/// blocking rather than letting a potentially-mutating action slip
/// through uncategorised.
pub(super) async fn resolve_action_scope(slug: &str) -> ToolScope {
+ resolve_action_scope_sync(slug)
+}
+
+/// Synchronous core used by policy hooks that cannot await.
+fn resolve_action_scope_sync(slug: &str) -> ToolScope {
let Some(toolkit) = toolkit_from_slug(slug) else {
return ToolScope::Write;
};
@@ -59,6 +64,14 @@ pub(super) async fn resolve_action_scope(slug: &str) -> ToolScope {
classify_unknown(slug)
}
+/// Whether an action must pass through the human approval gate.
+pub(super) fn action_mutates_external_state(slug: &str) -> bool {
+ matches!(
+ resolve_action_scope_sync(slug),
+ ToolScope::Write | ToolScope::Admin
+ )
+}
+
/// Decide whether a Composio action slug should be visible / executable
/// for the current user, given the registered provider's curated list
/// (if any) and the user's stored scope preference.
diff --git a/src/openhuman/integrations/composio/tools_part_03.rs b/src/openhuman/integrations/composio/tools_part_03.rs
index c28f6a606c..566894a853 100644
--- a/src/openhuman/integrations/composio/tools_part_03.rs
+++ b/src/openhuman/integrations/composio/tools_part_03.rs
@@ -36,6 +36,17 @@ impl Tool for ComposioExecuteTool {
// as write-level to respect channel permission caps.
PermissionLevel::Write
}
+ fn external_effect(&self) -> bool {
+ true
+ }
+ fn external_effect_with_args(&self, args: &Value) -> bool {
+ args.get("tool")
+ .and_then(Value::as_str)
+ .map(str::trim)
+ .filter(|slug| !slug.is_empty())
+ .map(action_mutates_external_state)
+ .unwrap_or(true)
+ }
fn category(&self) -> ToolCategory {
ToolCategory::Workflow
}
diff --git a/src/openhuman/integrations/composio/tools_tests_part_01_tests.rs b/src/openhuman/integrations/composio/tools_tests_part_01_tests.rs
index 0a1bda7065..d76d57bc18 100644
--- a/src/openhuman/integrations/composio/tools_tests_part_01_tests.rs
+++ b/src/openhuman/integrations/composio/tools_tests_part_01_tests.rs
@@ -241,6 +241,23 @@ fn execute_tool_requires_tool_argument() {
assert_eq!(required, vec!["tool"]);
}
+#[test]
+fn execute_tool_requires_approval_for_external_writes_only() {
+ let tool = ComposioExecuteTool::new(fake_config_arc());
+
+ assert!(tool.external_effect_with_args(&serde_json::json!({
+ "tool": "GMAIL_SEND_EMAIL"
+ })));
+ assert!(tool.external_effect_with_args(&serde_json::json!({
+ "tool": "GMAIL_DELETE_EMAIL"
+ })));
+ assert!(!tool.external_effect_with_args(&serde_json::json!({
+ "tool": "GMAIL_FETCH_EMAILS"
+ })));
+ assert!(tool.external_effect_with_args(&serde_json::json!({})));
+ assert!(tool.external_effect_with_args(&serde_json::json!({ "tool": " " })));
+}
+
#[tokio::test]
async fn execute_tool_execute_rejects_missing_tool() {
let t = ComposioExecuteTool::new(fake_config_arc());