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
fix(composio): redact the Composio key from tool results and errors
oxoxDev7749ce641548
diff --git a/crates/openhuman-core/src/integrations/composio/action_tool.rs b/crates/openhuman-core/src/integrations/composio/action_tool.rsindex efcccdc36c..db9ff1ad1a 100644--- a/crates/openhuman-core/src/integrations/composio/action_tool.rs+++ b/crates/openhuman-core/src/integrations/composio/action_tool.rs@@ -244,6 +244,16 @@ impl Tool for ComposioActionTool {}async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args)).await;+ match self.config.as_deref() {+ Some(config) => super::tools::redact_composio_outcome(config, outcome),+ None => outcome,+ }+ }+}++impl ComposioActionTool {+ async fn execute_unredacted(&self, args: Value) -> anyhow::Result<ToolResult> {// Agent-level sandbox gate (issue #685, CodeRabbit follow-up on// PR #904) — mirrors the check in// [`super::tools::ComposioExecuteTool::execute`] so a read-onlydiff --git a/crates/openhuman-core/src/integrations/composio/tools.rs b/crates/openhuman-core/src/integrations/composio/tools.rsindex 58f0dab3d3..0601365222 100644--- a/crates/openhuman-core/src/integrations/composio/tools.rs+++ b/crates/openhuman-core/src/integrations/composio/tools.rs@@ -33,6 +33,7 @@ mod list_connections;mod list_toolkits;mod list_tools;mod live_config;+mod redact;mod registry;mod visibility;@@ -44,8 +45,9 @@ mod tests;pub use direct::{ComposioAction, ComposioConnectedAccount, ComposioTool};pub use execute::ComposioExecuteTool;-pub use registry::all_composio_agent_tools;pub(crate) use live_config::live_composio_config;+pub(crate) use redact::redact_composio_outcome;+pub use registry::all_composio_agent_tools;// Brought into this module's own namespace (private `use`, not `pub use`)// so `tools_tests.rs` — declared as a direct child module of `tools` abovediff --git a/crates/openhuman-core/src/integrations/composio/tools/authorize.rs b/crates/openhuman-core/src/integrations/composio/tools/authorize.rsindex 466091560f..bdf94bcb36 100644--- a/crates/openhuman-core/src/integrations/composio/tools/authorize.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/authorize.rs@@ -6,6 +6,7 @@ use async_trait::async_trait;use serde_json::{json, Value};use super::live_config::live_composio_config;+use super::redact::redact_composio_outcome;use crate::config::Config;use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};@@ -54,6 +55,13 @@ impl Tool for ComposioAuthorizeTool {ToolCategory::Workflow}async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args)).await;+ redact_composio_outcome(&self.config, outcome)+ }+}++impl ComposioAuthorizeTool {+ async fn execute_unredacted(&self, args: Value) -> anyhow::Result<ToolResult> {let toolkit = args.get("toolkit").and_then(|v| v.as_str())@@ -72,16 +80,15 @@ impl Tool for ComposioAuthorizeTool {// the backend's `/agent-integrations/composio/authorize`// route, so we refuse this verb explicitly instead of// silently routing through the wrong tenant.- let live_config =- match live_composio_config(self.config.as_ref()).await {- Ok(c) => c,- Err(e) => {- tracing::warn!(error = %e, "[composio] tool: load_config failed");- return Ok(ToolResult::error(format!(- "composio: failed to load live config: {e}"- )));- }- };+ let live_config = match live_composio_config(self.config.as_ref()).await {+ Ok(c) => c,+ Err(e) => {+ tracing::warn!(error = %e, "[composio] tool: load_config failed");+ return Ok(ToolResult::error(format!(+ "composio: failed to load live config: {e}"+ )));+ }+ };let client = match create_composio_client(&live_config) {Ok(ComposioClientKind::Backend(client)) => {tracing::debug!("[composio] authorize.execute: backend variant");diff --git a/crates/openhuman-core/src/integrations/composio/tools/connect.rs b/crates/openhuman-core/src/integrations/composio/tools/connect.rsindex 96cec69440..fcab57deb8 100644--- a/crates/openhuman-core/src/integrations/composio/tools/connect.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/connect.rs@@ -9,6 +9,7 @@ use async_trait::async_trait;use serde_json::{json, Value};use super::live_config::live_composio_config;+use super::redact::redact_composio_outcome;use crate::config::Config;use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};@@ -163,6 +164,13 @@ impl Tool for ComposioConnectTool {// the toolkit slug into the card for the inline Connect button. The// engine's auto-gate is unconditional and would double-prompt.async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args)).await;+ redact_composio_outcome(&self.config, outcome)+ }+}++impl ComposioConnectTool {+ async fn execute_unredacted(&self, args: Value) -> anyhow::Result<ToolResult> {let raw_toolkit = args.get("toolkit").and_then(|v| v.as_str())@@ -192,14 +200,13 @@ impl Tool for ComposioConnectTool {}// Skip the card when the toolkit is already connected.- let live_config =- match live_composio_config(self.config.as_ref()).await {- Ok(c) => c,- Err(e) => {- tracing::warn!(error = %e, "[composio] connect.execute: load_config failed");- self.config.as_ref().clone()- }- };+ let live_config = match live_composio_config(self.config.as_ref()).await {+ Ok(c) => c,+ Err(e) => {+ tracing::warn!(error = %e, "[composio] connect.execute: load_config failed");+ self.config.as_ref().clone()+ }+ };let already_connected = super::super::fetch_connected_integrations(&live_config).await.into_iter()diff --git a/crates/openhuman-core/src/integrations/composio/tools/execute.rs b/crates/openhuman-core/src/integrations/composio/tools/execute.rsindex 657db7d007..5bf05341ea 100644--- a/crates/openhuman-core/src/integrations/composio/tools/execute.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/execute.rs@@ -7,10 +7,11 @@ use std::sync::Arc;use async_trait::async_trait;use serde_json::{json, Value};+use super::live_config::live_composio_config;+use super::redact::redact_composio_outcome;use crate::agent::harness::current_sandbox_mode;use crate::agent::harness::current_task_recency_window;use crate::agent::harness::definition::SandboxMode;-use super::live_config::live_composio_config;use crate::config::Config;use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};@@ -100,6 +101,13 @@ impl Tool for ComposioExecuteTool {ToolCategory::Workflow}async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args)).await;+ redact_composio_outcome(&self.config, outcome)+ }+}++impl ComposioExecuteTool {+ async fn execute_unredacted(&self, args: Value) -> anyhow::Result<ToolResult> {let tool = args.get("tool").and_then(|v| v.as_str())diff --git a/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs b/crates/openhuman-core/src/integrations/composio/tools/list_connections.rsindex 19e67427de..50583b410d 100644--- a/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs@@ -6,6 +6,7 @@ use async_trait::async_trait;use serde_json::{json, Value};use super::live_config::live_composio_config;+use super::redact::redact_composio_outcome;use crate::config::Config;use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};@@ -45,7 +46,14 @@ impl Tool for ComposioListConnectionsTool {fn category(&self) -> ToolCategory {ToolCategory::Workflow}- async fn execute(&self, _args: Value) -> anyhow::Result<ToolResult> {+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args)).await;+ redact_composio_outcome(&self.config, outcome)+ }+}++impl ComposioListConnectionsTool {+ async fn execute_unredacted(&self, _args: Value) -> anyhow::Result<ToolResult> {tracing::debug!("[composio] tool list_connections.execute");// Mirror `ops::composio_list_connections`: route through the mode-aware// factory so the agent sees the correct tenant's connections in bothdiff --git a/crates/openhuman-core/src/integrations/composio/tools/list_toolkits.rs b/crates/openhuman-core/src/integrations/composio/tools/list_toolkits.rsindex 864ba5a8b1..fd2399f63c 100644--- a/crates/openhuman-core/src/integrations/composio/tools/list_toolkits.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/list_toolkits.rs@@ -6,6 +6,7 @@ use async_trait::async_trait;use serde_json::{json, Value};use super::live_config::live_composio_config;+use super::redact::redact_composio_outcome;use crate::config::Config;use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};@@ -47,7 +48,14 @@ impl Tool for ComposioListToolkitsTool {// with `category_filter = "skill"`.ToolCategory::Workflow}- async fn execute(&self, _args: Value) -> anyhow::Result<ToolResult> {+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args)).await;+ redact_composio_outcome(&self.config, outcome)+ }+}++impl ComposioListToolkitsTool {+ async fn execute_unredacted(&self, _args: Value) -> anyhow::Result<ToolResult> {tracing::debug!("[composio] tool list_toolkits.execute");// Mirror the mode-aware pattern in// `ops::composio_list_toolkits`. In direct mode there is no@@ -55,16 +63,15 @@ impl Tool for ComposioListToolkitsTool {// governs availability, so we return an empty toolkits list// with an explanatory log instead of silently routing through// the backend tinyhumans tenant (#1710).- let live_config =- match live_composio_config(self.config.as_ref()).await {- Ok(c) => c,- Err(e) => {- tracing::warn!(error = %e, "[composio] tool: load_config failed");- return Ok(ToolResult::error(format!(- "composio: failed to load live config: {e}"- )));- }- };+ let live_config = match live_composio_config(self.config.as_ref()).await {+ Ok(c) => c,+ Err(e) => {+ tracing::warn!(error = %e, "[composio] tool: load_config failed");+ return Ok(ToolResult::error(format!(+ "composio: failed to load live config: {e}"+ )));+ }+ };let client = match create_composio_client(&live_config) {Ok(ComposioClientKind::Backend(client)) => {tracing::debug!("[composio] list_toolkits.execute: backend variant");diff --git a/crates/openhuman-core/src/integrations/composio/tools/list_tools.rs b/crates/openhuman-core/src/integrations/composio/tools/list_tools.rsindex 57dd631adb..981986247b 100644--- a/crates/openhuman-core/src/integrations/composio/tools/list_tools.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/list_tools.rs@@ -7,6 +7,7 @@ use async_trait::async_trait;use serde_json::{json, Value};use super::live_config::live_composio_config;+use super::redact::redact_composio_outcome;use crate::config::Config;use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolCategory, ToolResult};@@ -90,6 +91,21 @@ impl Tool for ComposioListToolsTool {&self,args: Value,options: ToolCallOptions,+ ) -> anyhow::Result<ToolResult> {+ let outcome = Box::pin(self.execute_unredacted(args, options)).await;+ redact_composio_outcome(&self.config, outcome)+ }++ fn supports_markdown(&self) -> bool {+ true+ }+}++impl ComposioListToolsTool {+ async fn execute_unredacted(+ &self,+ args: Value,+ options: ToolCallOptions,) -> anyhow::Result<ToolResult> {let toolkits = args.get("toolkits").and_then(|v| v.as_array()).map(|arr| {arr.iter()@@ -130,16 +146,15 @@ impl Tool for ComposioListToolsTool {// pattern. Surfacing the empty list explicitly is correct// fail-mode: the alternative — falling through to the backend// path — is exactly the bug we're closing (#1710).- let live_config =- match live_composio_config(self.config.as_ref()).await {- Ok(c) => c,- Err(e) => {- tracing::warn!(error = %e, "[composio] tool: load_config failed");- return Ok(ToolResult::error(format!(- "composio: failed to load live config: {e}"- )));- }- };+ let live_config = match live_composio_config(self.config.as_ref()).await {+ Ok(c) => c,+ Err(e) => {+ tracing::warn!(error = %e, "[composio] tool: load_config failed");+ return Ok(ToolResult::error(format!(+ "composio: failed to load live config: {e}"+ )));+ }+ };let client = match create_composio_client(&live_config) {Ok(ComposioClientKind::Backend(client)) => {tracing::debug!("[composio] list_tools.execute: backend variant");@@ -237,8 +252,4 @@ impl Tool for ComposioListToolsTool {))),}}-- fn supports_markdown(&self) -> bool {- true- }}diff --git a/crates/openhuman-core/src/integrations/composio/tools/redact.rs b/crates/openhuman-core/src/integrations/composio/tools/redact.rsnew file mode 100644index 0000000000..4925291f4c--- /dev/null+++ b/crates/openhuman-core/src/integrations/composio/tools/redact.rs@@ -0,0 +1,106 @@+//! [`redact_composio_outcome`]: keep a Composio API key out of what a+//! Composio tool returns to the model.++use serde_json::Value;+use tinytools::{ToolContent, ToolResult};++use crate::config::Config;++const REDACTED: &str = "[REDACTED]";+const MIN_SECRET_LEN: usize = 8;++/// The Composio keys `config` can resolve to: a host-pinned key, the inline+/// `composio.api_key`, and in unpinned direct mode the stored key.+pub(crate) fn composio_secrets(config: &Config) -> Vec<String> {+ let composio = &config.composio;+ let mut secrets: Vec<String> = Vec::new();+ if let Some(pinned) = composio.host_credential.as_ref() {+ secrets.push(pinned.api_key().to_string());+ }+ if let Some(inline) = composio.api_key.as_deref() {+ secrets.push(inline.trim().to_string());+ }+ if composio.host_credential.is_none()+ && composio.mode.trim() == crate::config::schema::COMPOSIO_MODE_DIRECT+ {+ if let Ok(Some(stored)) = crate::security::credentials::get_composio_api_key(config) {+ secrets.push(stored);+ }+ }+ secrets.retain(|s| s.len() >= MIN_SECRET_LEN);+ secrets.sort();+ secrets.dedup();+ secrets+}++pub(crate) fn redact_text(text: &str, secrets: &[String]) -> String {+ secrets.iter().fold(text.to_string(), |acc, secret| {+ acc.replace(secret.as_str(), REDACTED)+ })+}++fn redact_value(value: &mut Value, secrets: &[String]) {+ match value {+ Value::String(s) => {+ if secrets.iter().any(|secret| s.contains(secret.as_str())) {+ *s = redact_text(s, secrets);+ }+ }+ Value::Array(items) => items.iter_mut().for_each(|v| redact_value(v, secrets)),+ Value::Object(map) => map.values_mut().for_each(|v| redact_value(v, secrets)),+ _ => {}+ }+}++fn redact_content(content: &mut ToolContent, secrets: &[String]) {+ match content {+ ToolContent::Text { text } => *text = redact_text(text, secrets),+ ToolContent::Json { data } => redact_value(data, secrets),+ _ => {}+ }+}++pub(crate) fn redact_result(mut result: ToolResult, secrets: &[String]) -> ToolResult {+ if secrets.is_empty() {+ return result;+ }+ result+ .content+ .iter_mut()+ .for_each(|c| redact_content(c, secrets));+ result+ .follow_up+ .iter_mut()+ .for_each(|c| redact_content(c, secrets));+ if let Some(md) = result.markdown_formatted.as_mut() {+ *md = redact_text(md, secrets);+ }+ if let Some(meta) = result.metadata.as_mut() {+ redact_value(meta, secrets);+ }+ result+}++/// Redact every Composio key `config` resolves to from a tool's result or+/// error before it reaches the model.+pub(crate) fn redact_composio_outcome(+ config: &Config,+ outcome: anyhow::Result<ToolResult>,+) -> anyhow::Result<ToolResult> {+ let secrets = composio_secrets(config);+ if secrets.is_empty() {+ return outcome;+ }+ match outcome {+ Ok(result) => Ok(redact_result(result, &secrets)),+ Err(error) => {+ let rendered = format!("{error:#}");+ if secrets.iter().any(|s| rendered.contains(s.as_str())) {+ tracing::debug!("[composio] redacted a credential from a tool error");+ Err(anyhow::anyhow!(redact_text(&rendered, &secrets)))+ } else {+ Err(error)+ }+ }+ }+}