The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(composio): delegate execution and tool listing to module client
Steven Enamakel434afd262d41
diff --git a/src/openhuman/integrations/composio/ops/execute.rs b/src/openhuman/integrations/composio/ops/execute.rsindex ea84eba923..cbe27bcbcf 100644--- a/src/openhuman/integrations/composio/ops/execute.rs+++ b/src/openhuman/integrations/composio/ops/execute.rs@@ -3,10 +3,34 @@use crate::openhuman::config::Config;use crate::rpc::RpcOutcome;-use super::super::client::create_composio_client;-use super::super::types::ComposioExecuteResponse;+use super::super::module_client::{self as connectors, methods};+use super::super::types::{ComposioExecuteRequest, ComposioExecuteResponse};use super::error_utils::{report_composio_op_error, OpResult};+/// The prefix the module puts on an error it has already classified.+///+/// Matched with `contains` rather than `starts_with`: the bus prefixes a+/// member failure with the member's name, so a tag that used to lead the string+/// now sits inside it. A `starts_with` here would silently stop recognising+/// every classified error and re-wrap them all as unclassified, which is+/// exactly the information the UI uses to tell "reconnect your account" from+/// "the provider is down".+const CLASSIFIED: &str = "[composio:error:";++/// Run one Composio action.+///+/// # What stays here+///+/// The domain event. Execution timing and the `ComposioActionExecuted` event+/// are how the rest of this application learns an action ran — the cost line,+/// the activity feed, the agent's own budget. The module has no bus of the+/// host's to publish on.+///+/// # What the caller must still do+///+/// Apply [`crate::openhuman::security::egress`] *before* calling this. Local+/// only mode refusing an outbound tool call is policy about the user's data,+/// and the module cannot see the reasons behind it.pub async fn composio_execute(config: &Config,tool: &str,@@ -14,20 +38,25 @@ pub async fn composio_execute(connection_id: Option<&str>,) -> OpResult<RpcOutcome<ComposioExecuteResponse>> {tracing::debug!(tool = %tool, connection_id = ?connection_id, "[composio] rpc execute");- let kind = create_composio_client(config).map_err(|e| format!("[composio] execute: {e}"))?;let started = std::time::Instant::now();- let result = super::super::execute_dispatch::execute_composio_action_kind_with_connection(- kind,- tool,- arguments,- &config.composio.entity_id,- connection_id,+ let result = connectors::call::<_, ComposioExecuteResponse>(+ config,+ methods::EXECUTE,+ ComposioExecuteRequest {+ tool: tool.to_string(),+ arguments,+ connection_id: connection_id.map(str::to_string),+ },).await;- let elapsed_ms = started.elapsed().as_millis() as u64;+ let elapsed_ms = u64::try_from(started.elapsed().as_millis()).unwrap_or(u64::MAX);match result {Ok(resp) => {+ // Note that this is reached for a *refused* action too: the module+ // reports a provider's refusal as a successful reply carrying+ // `successful: false`. The event records what happened, not whether+ // the call completed.crate::core::bus::BUS.publish(crate::core::events::DomainEvent::ComposioActionExecuted {tool: tool.to_string(),@@ -47,13 +76,13 @@ pub async fn composio_execute(crate::core::events::DomainEvent::ComposioActionExecuted {tool: tool.to_string(),success: false,- error: Some(e.to_string()),+ error: Some(e.clone()),cost_usd: 0.0,elapsed_ms,},);- report_composio_op_error("execute", &e);- let is_classified = e.starts_with("[composio:error:");+ report_composio_op_error("execute", &anyhow::anyhow!("{e}"));+ let is_classified = e.contains(CLASSIFIED);tracing::debug!(tool = %tool,elapsed_ms,diff --git a/src/openhuman/integrations/composio/ops/tools_ops.rs b/src/openhuman/integrations/composio/ops/tools_ops.rsindex fee92360af..3ade2ed163 100644--- a/src/openhuman/integrations/composio/ops/tools_ops.rs+++ b/src/openhuman/integrations/composio/ops/tools_ops.rs@@ -3,12 +3,22 @@use crate::openhuman::config::Config;use crate::rpc::RpcOutcome;-use super::super::client::{- create_composio_client, direct_list_connections, direct_list_tools, ComposioClientKind,-};-use super::super::types::ComposioToolsResponse;+use super::super::module_client::{self as connectors, methods};+use super::super::types::{ComposioListToolsRequest, ComposioToolsResponse};use super::error_utils::{report_composio_op_error, should_forward_tags, OpResult};+/// List the actions the agent may pick from.+///+/// # What moved+///+/// The direct route used to be a second implementation here: prefetch the+/// connected toolkits, fetch v3 schemas for them, then re-apply OpenHuman's+/// curated whitelist and the user's scope preference. All of it is the module's+/// now, including the scope filter.+///+/// The filter is deliberately *not* mirrored here. Two places deciding what a+/// user permitted is how one of them ends up stale and permissive, and the+/// permissive one is the one that lets an action through.pub async fn composio_list_tools(config: &Config,toolkits: Option<Vec<String>>,@@ -20,126 +30,27 @@ pub async fn composio_list_tools(None};tracing::debug!(?toolkits, ?effective_tags, "[composio] rpc list_tools");- let kind = create_composio_client(config).map_err(|e| format!("[composio] list_tools: {e}"))?;- match kind {- ComposioClientKind::Backend(client) => {- tracing::debug!("[composio] list_tools: backend variant");- let resp = client- .list_tools(toolkits.as_deref(), effective_tags.as_deref())- .await- .map_err(|e| {- report_composio_op_error("list_tools", &e);- format!("[composio] list_tools failed: {e:#}")- })?;- let count = resp.tools.len();- Ok(RpcOutcome::new(- resp,- vec![format!("composio: {count} tool(s) listed")],- ))- }- ComposioClientKind::Direct(direct) => {- let scope: Vec<String> = match toolkits {- Some(list) if !list.is_empty() => list,- _ => {- let conns = direct_list_connections(&direct).await.map_err(|e| {- let rendered = format!(- "[composio-direct] list_tools: prefetch connections failed: {e:#}"- );- report_composio_op_error("list_connections", &rendered);- rendered- })?;- let mut v: Vec<String> = conns- .connections- .iter()- .filter(|c| c.is_active())- .map(|c| c.normalized_toolkit())- .filter(|t| !t.is_empty())- .collect();- v.sort();- v.dedup();- v- }- };- if scope.is_empty() {- tracing::info!(- "[composio-direct] list_tools: no connected toolkits on this tenant — \- returning empty tool list"- );- return Ok(RpcOutcome::new(- ComposioToolsResponse::default(),- vec!["composio: direct mode — 0 tool(s) listed (no connected \- toolkits on this tenant)"- .to_string()],- ));- }- tracing::debug!(- toolkits = scope.len(),- ?effective_tags,- "[composio-direct] list_tools: fetching v3 tool schemas"- );- let mut resp = direct_list_tools(&direct, &scope, effective_tags.as_deref())- .await- .map_err(|e| {- let rendered = format!("[composio-direct] list_tools failed: {e:#}");- report_composio_op_error("list_tools", &rendered);- rendered- })?;- let before = resp.tools.len();- filter_list_tools_response_for_direct(&mut resp).await;- let after = resp.tools.len();- tracing::debug!(- before,- after,- dropped = before - after,- "[composio-direct] list_tools: curated filter applied"- );- let count = resp.tools.len();- Ok(RpcOutcome::new(- resp,- vec![format!(- "composio: direct mode — {count} tool(s) listed across \- {} toolkit(s)",- scope.len()- )],- ))- }- }-}-/// Apply OpenHuman's curated-whitelist + user-scope visibility filter to-/// a fresh `ComposioToolsResponse` in direct mode. Mirrors the per-call-/// filter loop in `tools.rs::filter_list_tools_response` so backend and-/// direct surfaces share the same safety net.-async fn filter_list_tools_response_for_direct(resp: &mut ComposioToolsResponse) {- use super::super::providers::{- catalog_for_toolkit, classify_unknown, find_curated, get_provider,- load_user_scope_or_default, toolkit_from_slug,+ let request = ComposioListToolsRequest {+ toolkits: toolkits.unwrap_or_default(),+ tags: effective_tags.unwrap_or_default(),+ ..ComposioListToolsRequest::default()};+ let named = request.toolkits.len();- let mut keep: Vec<bool> = Vec::with_capacity(resp.tools.len());- for t in &resp.tools {- let slug = &t.function.name;- let Some(toolkit) = toolkit_from_slug(slug) else {- keep.push(true);- continue;- };- let pref = load_user_scope_or_default(&toolkit).await;- let catalog = get_provider(&toolkit)- .and_then(|p| p.curated_tools())- .or_else(|| catalog_for_toolkit(&toolkit));- let allowed = match catalog {- Some(cat) => match find_curated(cat, slug) {- Some(curated) => pref.allows(curated.scope),- None => false,- },- None => pref.allows(classify_unknown(slug)),- };- keep.push(allowed);+ match connectors::call::<_, ComposioToolsResponse>(config, methods::LIST_TOOLS, request).await {+ Ok(resp) => {+ let count = resp.tools.len();+ let line = if named == 0 {+ format!("composio: {count} tool(s) listed")+ } else {+ format!("composio: {count} tool(s) listed across {named} toolkit(s)")+ };+ Ok(RpcOutcome::new(resp, vec![line]))+ }+ Err(error) => {+ report_composio_op_error("list_tools", &anyhow::anyhow!("{error}"));+ Err(format!("[composio] list_tools failed: {error}"))+ }}- let drained: Vec<_> = resp.tools.drain(..).collect();- resp.tools = drained- .into_iter()- .zip(keep)- .filter_map(|(tool, keep_it)| if keep_it { Some(tool) } else { None })- .collect();}