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
style(channels): reorder imports and reformat dispatch code
Steven Enamakel410e67a7afa0
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rsindex 953820343e..31047af8e4 100644--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs@@ -3,15 +3,15 @@use std::collections::HashMap;use std::sync::Arc;-use serde_json::{json, Value};+use serde_json::{Value, json};use super::channel::RelayChannel;use super::params::RelayInboundParams;use super::store::{self, Recorded};use crate::channels::context::MAX_CHANNEL_HISTORY;use crate::channels::runtime::{- build_channel_turn_parts, prepare_runtime_limits, process_channel_runtime_message,- runtime_context, PromptToolDescs,+ PromptToolDescs, build_channel_turn_parts, prepare_runtime_limits,+ process_channel_runtime_message, runtime_context,};use crate::config::Config;use crate::core::Outcome;@@ -114,27 +114,23 @@ pub(crate) async fn run_relay_turn());let client = crate::modules::client::ModuleClient::new(config.clone());- let (message_timeout_secs, _) = match prepare_runtime_limits(- &client,- config.channels_config.message_timeout_secs,- 1,- )- .await- {- Ok(limits) => limits,- Err(error) => {- tracing::warn!("relayed channel runtime limits unavailable: {error}");- let reply =- "⚠️ This chat's assistant is not available right now. Please try again later.";- let _ = crate::channels::traits::Channel::send(- channel.as_ref(),- &crate::channels::SendMessage::new(reply, ¶ms.chat_id),- )- .await;- record(&workspace_dir, ¶ms, &thread_id, &channel.sent()).await;- return channel.sent();- }- };+ let (message_timeout_secs, _) =+ match prepare_runtime_limits(&client, config.channels_config.message_timeout_secs, 1).await+ {+ Ok(limits) => limits,+ Err(error) => {+ tracing::warn!("relayed channel runtime limits unavailable: {error}");+ let reply =+ "⚠️ This chat's assistant is not available right now. Please try again later.";+ let _ = crate::channels::traits::Channel::send(+ channel.as_ref(),+ &crate::channels::SendMessage::new(reply, ¶ms.chat_id),+ )+ .await;+ record(&workspace_dir, ¶ms, &thread_id, &channel.sent()).await;+ return channel.sent();+ }+ };let security = Arc::new(SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir)diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rsindex 1c1be030a1..064596391b 100644--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs@@ -1,6 +1,6 @@use super::super::channel::CHANNEL_OUTBOUND_EVENT;use super::*;-use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};+use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, mock_agent_run_turn};use crate::agent::turn_origin::AgentTurnOrigin;use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};use std::sync::Mutex;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/helpers.rs b/crates/openhuman-core/src/channels/runtime/dispatch/helpers.rsindex cc1c43d933..712b5199e8 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/helpers.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/helpers.rs@@ -10,7 +10,9 @@ pub(super) const REPLY_LOG_TRUNCATE_CHARS: usize = 200;pub(super) use tinychannels::runtime::select_acknowledgment_reaction;pub(super) fn log_worker_join_result(result: Result<(), tokio::task::JoinError>) {- if let Err(error) = result { tracing::warn!("channel worker failed: {error}"); }+ if let Err(error) = result {+ tracing::warn!("channel worker failed: {error}");+ }}/// Start the portable typing lifecycle with OpenHuman's configured interval.@@ -23,7 +25,10 @@ pub(super) fn spawn_scoped_typing_task(// The worker retains ownership across cancellation of the caller while// StartTypingRefresh is in flight, then closes the returned module handle.tokio::spawn(async move {- match channel.begin_typing_refresh(&recipient, CHANNEL_TYPING_REFRESH_INTERVAL_SECS).await {+ match channel+ .begin_typing_refresh(&recipient, CHANNEL_TYPING_REFRESH_INTERVAL_SECS)+ .await+ {Ok(Some(handle)) => {cancellation_token.cancelled().await;if channel.end_typing_refresh(&handle).await.is_err() {@@ -38,7 +43,9 @@ pub(super) fn spawn_scoped_typing_task(}let _ = finished_tx.send(());});- tokio::spawn(async move { let _ = finished_rx.await; })+ tokio::spawn(async move {+ let _ = finished_rx.await;+ })}/// Build the `[Channel context]` block for a channel turn.diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rsindex 6bb1f945a1..acf359e943 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs@@ -3,13 +3,13 @@//! still goes to the orchestrator over the bus.use super::*;-use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};+use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, mock_agent_run_turn};use crate::agent::host_agents::{self, HostAgent, HostAgentResolver};-use crate::channels::context::{ChannelRuntimeContext, CHANNEL_MESSAGE_TIMEOUT_SECS};+use crate::channels::context::{CHANNEL_MESSAGE_TIMEOUT_SECS, ChannelRuntimeContext};use crate::channels::runtime::process_channel_message;-use crate::channels::{traits, Channel, SendMessage};+use crate::channels::{Channel, SendMessage, traits};use crate::core::runtime::{CoreContext, DomainSet};-use serde_json::{json, Value};+use serde_json::{Value, json};use std::collections::HashMap;use std::sync::atomic::{AtomicUsize, Ordering};use std::sync::{Arc, Mutex};diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rsindex bf70522fad..3756d37dbd 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs@@ -29,7 +29,7 @@ use crate::core::events::DomainEvent;pub(crate) mod posture;mod turn;-pub(crate) use turn::{run_host_agent_turn, seed_rows, HostChannelTurn};+pub(crate) use turn::{HostChannelTurn, run_host_agent_turn, seed_rows};/// What a channel's binding resolves to for one message.pub(crate) enum HostRoute {diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rsindex 897b06d53f..512bb00296 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rs@@ -11,8 +11,8 @@use tinytools::{PermissionLevel, Tool};-use crate::agent::turn_origin::AgentTurnOrigin;use crate::agent::HostTools;+use crate::agent::turn_origin::AgentTurnOrigin;use crate::config::Config;/// The most a host agent may do on a turn from `origin`; `None` leaves thediff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rsindex a7df3a5833..a73e103e55 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs@@ -1,8 +1,8 @@use super::*;use crate::agent::HostTurnTools;-use serde_json::{json, Value};-use std::sync::atomic::{AtomicUsize, Ordering};+use serde_json::{Value, json};use std::sync::Arc;+use std::sync::atomic::{AtomicUsize, Ordering};use tinytools::{ToolCallOptions, ToolResult};fn external() -> AgentTurnOrigin {diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rsindex 433662df47..3374999e44 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs@@ -16,8 +16,8 @@ mod processor;mod routing;pub(crate) use processor::{- process_channel_message, process_channel_runtime_message, run_message_dispatch_loop,- RuntimeChannelMessage,+ RuntimeChannelMessage, process_channel_message, process_channel_runtime_message,+ run_message_dispatch_loop,};// `channel_has_approval_surface` stays pub(crate) on processor; re-export so@@ -33,7 +33,7 @@ use helpers::build_channel_context_block;use helpers::select_acknowledgment_reaction;#[cfg(test)]-use routing::{build_visible_tool_set, AgentScoping};+use routing::{AgentScoping, build_visible_tool_set};#[cfg(any(test, debug_assertions))]use crate::channels::traits;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rsindex 79e4bfa101..ca20bbb05f 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs@@ -1,7 +1,7 @@//! The orchestrator path: an unbound channel's turn goes over the native bus//! to the `agent.run_turn` handler, with the orchestrator's tool scoping.-use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, AGENT_RUN_TURN_METHOD};+use crate::agent::bus::{AGENT_RUN_TURN_METHOD, AgentTurnRequest, AgentTurnResponse};use crate::agent::progress::AgentProgress;use crate::agent::turn_origin::AgentTurnOrigin;use crate::channels::context::{ChannelRouteSelection, ChannelRuntimeContext};diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rsindex 1bf21a7c7e..a97e7318bc 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs@@ -5,7 +5,7 @@use crate::agent::bus::AgentTurnResponse;use crate::agent::progress::AgentProgress;use crate::channels::context::{- compact_sender_history, is_context_window_overflow_error, ChannelRuntimeContext,+ ChannelRuntimeContext, compact_sender_history, is_context_window_overflow_error,};use crate::channels::routes::{get_or_create_turn_model_source, get_route_selection, handle_runtime_command_if_needed,@@ -22,12 +22,13 @@ use tokio_util::sync::CancellationToken;use tokio_util::task::AbortOnDropHandle;use super::super::helpers::{- build_channel_context_block, log_worker_join_result, spawn_scoped_typing_task, REPLY_LOG_TRUNCATE_CHARS,+ REPLY_LOG_TRUNCATE_CHARS, build_channel_context_block, log_worker_join_result,+ spawn_scoped_typing_task,};-use super::super::host_agent::{self, run_host_agent_turn, seed_rows, HostChannelTurn, HostRoute};+use super::super::host_agent::{self, HostChannelTurn, HostRoute, run_host_agent_turn, seed_rows};+use super::RuntimeChannelMessage;use super::approval::{channel_has_approval_surface, try_route_approval_reply};use super::bus_turn::dispatch_bus_turn;-use super::RuntimeChannelMessage;pub(crate) async fn process_channel_message(ctx: Arc<ChannelRuntimeContext>,@@ -106,7 +107,9 @@ pub(crate) async fn process_channel_runtime_message(});let target_channel = ctx.channels_by_name.get(&msg.channel).cloned();- if handle_runtime_command_if_needed(ctx.as_ref(), &msg, target_channel.as_ref(), &history_key).await {+ if handle_runtime_command_if_needed(ctx.as_ref(), &msg, target_channel.as_ref(), &history_key)+ .await+ {return;}@@ -157,30 +160,46 @@ pub(crate) async fn process_channel_runtime_message(let mut _acknowledgment_task = None;if let Some(channel) = target_channel.as_ref() {if channel.supports_reactions() && msg.thread_ts.is_some() {- let ack_result = crate::channels::context::module_client(&ctx).await.call_confidential::<tinychannels_bus::module_control::ChannelControlResult>("tinychannels", tinychannels_bus::methods::PREPARE_CHANNEL_CONTROL, (tinychannels_bus::module_control::ChannelControlRequest::Acknowledgment { content: msg.content.clone() },)).await;+ let ack_result = crate::channels::context::module_client(&ctx)+ .await+ .call_confidential::<tinychannels_bus::module_control::ChannelControlResult>(+ "tinychannels",+ tinychannels_bus::methods::PREPARE_CHANNEL_CONTROL,+ (+ tinychannels_bus::module_control::ChannelControlRequest::Acknowledgment {+ content: msg.content.clone(),+ },+ ),+ )+ .await;let ack_emoji = match ack_result {- Ok(tinychannels_bus::module_control::ChannelControlResult::Acknowledgment(emoji)) => Some(emoji),- Ok(_) => { crate::modules::client::ModuleClient::report_malformed_reply("tinychannels"); None },+ Ok(tinychannels_bus::module_control::ChannelControlResult::Acknowledgment(+ emoji,+ )) => Some(emoji),+ Ok(_) => {+ crate::modules::client::ModuleClient::report_malformed_reply("tinychannels");+ None+ }Err(_) => None,};if let Some(ack_emoji) = ack_emoji {- tracing::debug!(- channel = msg.channel,- emoji = ack_emoji,- "[dispatch] Sending acknowledgment reaction"- );- let react_content = format!("[REACTION:{ack_emoji}]");- let channel_for_react = Arc::clone(channel);- let react_msg =- SendMessage::new(react_content, &msg.reply_target).in_thread(msg.thread_ts.clone());- _acknowledgment_task = Some(AbortOnDropHandle::new(tokio::spawn(async move {- if let Err(e) = channel_for_react- .send_with_outbound_intent(&react_msg)- .await- {- tracing::debug!("[dispatch] Acknowledgment reaction failed: {e}");- }- })));+ tracing::debug!(+ channel = msg.channel,+ emoji = ack_emoji,+ "[dispatch] Sending acknowledgment reaction"+ );+ let react_content = format!("[REACTION:{ack_emoji}]");+ let channel_for_react = Arc::clone(channel);+ let react_msg = SendMessage::new(react_content, &msg.reply_target)+ .in_thread(msg.thread_ts.clone());+ _acknowledgment_task = Some(AbortOnDropHandle::new(tokio::spawn(async move {+ if let Err(e) = channel_for_react+ .send_with_outbound_intent(&react_msg)+ .await+ {+ tracing::debug!("[dispatch] Acknowledgment reaction failed: {e}");+ }+ })));}}}@@ -201,9 +220,9 @@ pub(crate) async fn process_channel_runtime_message();let safe_err = tinyinference_core::sanitize::sanitize_api_error(&err.to_string());let message = format!(- "⚠️ Failed to initialize provider `{}`. Please run `/models` to choose another provider.\nDetails: {safe_err}",- route.provider- );+ "⚠️ Failed to initialize provider `{}`. Please run `/models` to choose another provider.\nDetails: {safe_err}",+ route.provider+ );if let Some(channel) = target_channel.as_ref() {let _ = channel.send_with_outbound_intent(@@ -351,7 +370,9 @@ pub(crate) async fn process_channel_runtime_message(};let typing_cancellation = target_channel.as_ref().map(|_| CancellationToken::new());- let _typing_cancel_on_drop = typing_cancellation.as_ref().map(|token| token.clone().drop_guard());+ let _typing_cancel_on_drop = typing_cancellation+ .as_ref()+ .map(|token| token.clone().drop_guard());// Typing was already started early (before memory/provider setup). Here we only// spawn the background refresh task that keeps the indicator alive during long turns.let typing_task = match (target_channel.as_ref(), typing_cancellation.as_ref()) {@@ -504,7 +525,10 @@ pub(crate) async fn process_channel_runtime_message((true, response_text, resolved_provider, resolved_model)}Ok(Err(e)) => {- if is_context_window_overflow_error(&ctx, &e).await.unwrap_or(false) {+ if is_context_window_overflow_error(&ctx, &e)+ .await+ .unwrap_or(false)+ {let compacted = compact_sender_history(ctx.as_ref(), &history_key);let error_text = if compacted {"⚠️ Context window exceeded for this conversation. I compacted recent history and kept the latest context. Please resend your last message."diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/routing.rs b/crates/openhuman-core/src/channels/runtime/dispatch/routing.rsindex 55fc6543bc..849fcc08c0 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/routing.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/routing.rs@@ -10,8 +10,8 @@ use crate::agent::harness::definition::{AgentDefinition, AgentDefinitionRegistryuse crate::agent::prompts::ConnectedIntegration;use crate::config::Config;use crate::integrations::composio::{- cached_active_integrations, fetch_connected_integrations_status,- FetchConnectedIntegrationsStatus,+ FetchConnectedIntegrationsStatus, cached_active_integrations,+ fetch_connected_integrations_status,};use crate::tools::orchestrator_tools;use std::collections::HashSet;diff --git a/crates/openhuman-core/src/channels/runtime/mod.rs b/crates/openhuman-core/src/channels/runtime/mod.rsindex 205035a9e0..24fcf1af7e 100644--- a/crates/openhuman-core/src/channels/runtime/mod.rs+++ b/crates/openhuman-core/src/channels/runtime/mod.rs@@ -12,13 +12,13 @@ pub(crate) use startup::start_channels_with_session;// The hosted-channel relay (`channels::providers::relay`) runs one message// through the same pipeline, with a context built from the caller's config.pub(crate) use dispatch::process_channel_message;-pub(crate) use startup::{build_channel_turn_parts, runtime_context, PromptToolDescs};+pub(crate) use startup::{PromptToolDescs, build_channel_turn_parts, runtime_context};#[cfg(any(test, debug_assertions))]pub mod test_support;// Re-exported for `channels::tests` only; omit in normal lib builds to avoid unused-import warnings.#[cfg(test)]-pub(crate) use dispatch::{run_message_dispatch_loop, RuntimeChannelMessage};+pub(crate) use dispatch::{RuntimeChannelMessage, run_message_dispatch_loop};#[cfg(test)]pub(crate) use supervision::spawn_supervised_listener;diff --git a/crates/openhuman-core/src/channels/runtime/session_tests.rs b/crates/openhuman-core/src/channels/runtime/session_tests.rsindex 4e80f01002..5438f6ccef 100644--- a/crates/openhuman-core/src/channels/runtime/session_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/session_tests.rs@@ -1,6 +1,6 @@use super::*;-use std::sync::atomic::{AtomicBool, Ordering};use std::sync::Arc;+use std::sync::atomic::{AtomicBool, Ordering};#[tokio::test]async fn independent_local_runtime_does_not_need_an_account_session() {diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rsindex 05b7bf1529..b3f4b44b57 100644--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs@@ -441,8 +441,7 @@ impl ModuleChannel {.await.map_err(anyhow::Error::new)?;if let Some(relay) = self.relay.as_ref().filter(|_| self.relay_fronted) {- self- .object+ self.object.call_confidential::<tinychannels_bus::controllers::ChannelSendMessageResult>(tinychannels_bus::methods::SEND_RELAY_INTENT,(relay.clone(), prepared.intent),diff --git a/crates/openhuman-core/src/channels/runtime/supervision.rs b/crates/openhuman-core/src/channels/runtime/supervision.rsindex 707d40a51b..bda8b630fb 100644--- a/crates/openhuman-core/src/channels/runtime/supervision.rs+++ b/crates/openhuman-core/src/channels/runtime/supervision.rs@@ -1,7 +1,7 @@//! OpenHuman observer adapter for TinyChannels listener supervision.-use super::super::traits;use super::super::Channel;+use super::super::traits;use crate::core::bus::BUS;use crate::core::events::DomainEvent;use std::sync::Arc;@@ -60,7 +60,7 @@ pub(crate) fn spawn_supervised_listener(}#[cfg(test)]-pub(crate) use tinychannels::runtime::{jitter_millis, MAX_JITTER_MS};+pub(crate) use tinychannels::runtime::{MAX_JITTER_MS, jitter_millis};#[cfg(test)]#[path = "supervision_tests.rs"]diff --git a/crates/openhuman-core/src/channels/runtime/supervision_tests.rs b/crates/openhuman-core/src/channels/runtime/supervision_tests.rsindex bacab56eaa..e679a59d81 100644--- a/crates/openhuman-core/src/channels/runtime/supervision_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/supervision_tests.rs@@ -1,5 +1,5 @@-use super::super::super::{traits, Channel};-use super::{jitter_millis, spawn_supervised_listener, MAX_JITTER_MS};+use super::super::super::{Channel, traits};+use super::{MAX_JITTER_MS, jitter_millis, spawn_supervised_listener};use std::sync::{Arc, Mutex};use tokio::time::Instant;diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rsindex ee577adbb4..1726a3042c 100644--- a/crates/openhuman-core/src/channels/runtime/test_support.rs+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs@@ -2,15 +2,15 @@pub use super::dispatch::test_support::build_channel_context_block_for_test;use super::dispatch::{- process_channel_message, process_channel_runtime_message, RuntimeChannelMessage,+ RuntimeChannelMessage, process_channel_message, process_channel_runtime_message,};pub use super::startup::test_support::resolve_yuanbao_app_secret_for_test;-use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, AGENT_RUN_TURN_METHOD};+use crate::agent::bus::{AGENT_RUN_TURN_METHOD, AgentTurnRequest, AgentTurnResponse};use crate::agent::progress::AgentProgress;-use crate::channels::context::{ChannelRuntimeContext, CHANNEL_MESSAGE_TIMEOUT_SECS};-use crate::channels::traits::{ChannelMessage, SendMessage};use crate::channels::Channel;use crate::channels::ChannelSystemPrompt;+use crate::channels::context::{CHANNEL_MESSAGE_TIMEOUT_SECS, ChannelRuntimeContext};+use crate::channels::traits::{ChannelMessage, SendMessage};use crate::config::{MultimodalConfig, MultimodalFileConfig, ReliabilityConfig};use crate::core::bus::BUS;use crate::core::events::DomainEvent;