Skip to content

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

refactor(tinyagents): extract runner and middleware blocks into separate files\n\nMove the `filter_cached_toolkit_actions_with_current_scope` function from the subagent runner into a new `runner_part_01.rs` file, and relocate the `channel_permission_block` and `generated_context` methods from `middleware_part_02.rs` into a new `middleware_part_07.rs` file. This reduces file sizes and improves maintainability by keeping related logic together.\n\nAuto-committed-on: dragonfly\n

Steven Enamakelb46bc2a654ae
diff --git a/src/core/jsonrpc_tests.rs b/src/core/jsonrpc_tests.rs
index c8c16b7ccc..fc0081e1e1 100644
--- a/src/core/jsonrpc_tests.rs
+++ b/src/core/jsonrpc_tests.rs
@@ -178,11 +178,11 @@ fn learning_subscriber_registration_is_idempotent_after_success() {
assert!(!learning_first_time_when_bus_ready(&completed, true));
}
-#[test]
-fn domain_subscriber_registration_wrapper_uses_the_global_bus() {
+#[tokio::test]
+async fn domain_subscriber_registration_wrapper_uses_the_global_bus() {
use crate::core::all::DomainGroup;
- crate::core::event_bus::init_global(crate::core::event_bus::DEFAULT_CAPACITY);
+ crate::core::bus::init().await.expect("bus init");
assert!(group_first_time(DomainGroup::Media));
assert!(!group_first_time(DomainGroup::Media));
}
diff --git a/src/openhuman/agent/agent_tests_part_03_tests.rs b/src/openhuman/agent/agent_tests_part_03_tests.rs
index 27c304219a..d26588ee5f 100644
--- a/src/openhuman/agent/agent_tests_part_03_tests.rs
+++ b/src/openhuman/agent/agent_tests_part_03_tests.rs
@@ -54,7 +54,7 @@ async fn poll_for_stored_user_message(mem: &Arc<dyn Memory>) -> Vec<String> {
async fn an_external_channel_turn_stores_the_user_message() {
use crate::openhuman::agent::turn_origin::{with_origin, AgentTurnOrigin};
- let (mem, _tmp) = make_sqlite_memory();
+ let (mem, _tmp) = make_retaining_memory();
let provider = Arc::new(ScriptedProvider::new(vec![text_response("got it")]));
let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);
@@ -83,7 +83,7 @@ async fn an_external_channel_turn_stores_the_user_message() {
async fn a_direct_chat_turn_stores_the_user_message() {
use crate::openhuman::agent::turn_origin::{with_origin, AgentTurnOrigin};
- let (mem, _tmp) = make_sqlite_memory();
+ let (mem, _tmp) = make_retaining_memory();
let provider = Arc::new(ScriptedProvider::new(vec![text_response("noted")]));
let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);
@@ -112,7 +112,7 @@ async fn an_automation_turn_does_not_store_its_prompt_as_the_users_memory() {
with_origin, AgentTurnOrigin, TrustedAutomationSource,
};
- let (mem, _tmp) = make_sqlite_memory();
+ let (mem, _tmp) = make_retaining_memory();
let provider = Arc::new(ScriptedProvider::new(vec![text_response("goals updated")]));
let (mut agent, _tmp2) = build_agent_with_memory(
provider,
@@ -145,7 +145,7 @@ async fn an_automation_turn_does_not_store_its_prompt_as_the_users_memory() {
/// quietly write host text into the user's memory.
#[tokio::test]
async fn an_unscoped_turn_stores_no_user_message() {
- let (mem, _tmp) = make_sqlite_memory();
+ let (mem, _tmp) = make_retaining_memory();
let provider = Arc::new(ScriptedProvider::new(vec![text_response("ok")]));
let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);
diff --git a/src/openhuman/agent/harness/subagent_runner/ops/runner.rs b/src/openhuman/agent/harness/subagent_runner/ops/runner.rs
index 4d623ff552..4707f5082a 100644
--- a/src/openhuman/agent/harness/subagent_runner/ops/runner.rs
+++ b/src/openhuman/agent/harness/subagent_runner/ops/runner.rs
@@ -48,6 +48,8 @@ use crate::openhuman::memory::api::provider::retrieval::{FastRetrieveQuery, Retr
use crate::openhuman::memory::source_scope::as_bus_scope;
use crate::openhuman::tools::{Tool, ToolCategory, ToolSpec};
use tinyagents_harness::tool::SandboxMode as TinyagentsSandboxMode;
+
+include!("runner_part_01.rs");
use tinyagents_harness::workspace::WorkspaceDescriptor;
use super::prompt::{
@@ -109,39 +111,6 @@ pub(super) fn tier_gate_decision(
Ok(())
}
-async fn filter_cached_toolkit_actions_with_current_scope(
- agent_id: &str,
- toolkit: &str,
- config: &crate::openhuman::config::Config,
- actions: &[crate::openhuman::agent::context::prompt::ConnectedIntegrationTool],
-) -> Vec<crate::openhuman::agent::context::prompt::ConnectedIntegrationTool> {
- let pref =
- crate::openhuman::integrations::composio::ops::load_user_scope_pref(config, toolkit).await;
- let before = actions.len();
- let filtered: Vec<_> = actions
- .iter()
- .filter(|action| {
- crate::openhuman::integrations::composio::providers::is_action_visible_with_pref(
- &action.name,
- &pref,
- )
- })
- .cloned()
- .collect();
- tracing::debug!(
- agent_id = %agent_id,
- toolkit = %toolkit,
- cached_actions = before,
- visible_actions = filtered.len(),
- hidden_actions = before.saturating_sub(filtered.len()),
- read = pref.read,
- write = pref.write,
- admin = pref.admin,
- "[subagent_runner:typed] re-filtered cached toolkit catalogue with current user scope"
- );
- filtered
-}
-
/// Definition id of the pure-retrieval memory agent, reached from chat as the
/// `retrieve_memory` delegate and from other agents as `call_memory_agent`.
const AGENT_MEMORY_ID: &str = "agent_memory";
diff --git a/src/openhuman/agent/harness/subagent_runner/ops/runner_part_01.rs b/src/openhuman/agent/harness/subagent_runner/ops/runner_part_01.rs
new file mode 100644
index 0000000000..402ccbc9f0
--- /dev/null
+++ b/src/openhuman/agent/harness/subagent_runner/ops/runner_part_01.rs
@@ -0,0 +1,32 @@
+async fn filter_cached_toolkit_actions_with_current_scope(
+ agent_id: &str,
+ toolkit: &str,
+ config: &crate::openhuman::config::Config,
+ actions: &[crate::openhuman::agent::context::prompt::ConnectedIntegrationTool],
+) -> Vec<crate::openhuman::agent::context::prompt::ConnectedIntegrationTool> {
+ let pref =
+ crate::openhuman::integrations::composio::ops::load_user_scope_pref(config, toolkit).await;
+ let before = actions.len();
+ let filtered: Vec<_> = actions
+ .iter()
+ .filter(|action| {
+ crate::openhuman::integrations::composio::providers::is_action_visible_with_pref(
+ &action.name,
+ &pref,
+ )
+ })
+ .cloned()
+ .collect();
+ tracing::debug!(
+ agent_id = %agent_id,
+ toolkit = %toolkit,
+ cached_actions = before,
+ visible_actions = filtered.len(),
+ hidden_actions = before.saturating_sub(filtered.len()),
+ read = pref.read,
+ write = pref.write,
+ admin = pref.admin,
+ "[subagent_runner:typed] re-filtered cached toolkit catalogue with current user scope"
+ );
+ filtered
+}
diff --git a/src/openhuman/agent/tinyagents/middleware.rs b/src/openhuman/agent/tinyagents/middleware.rs
index eb2fd08dc3..36e7612e88 100644
--- a/src/openhuman/agent/tinyagents/middleware.rs
+++ b/src/openhuman/agent/tinyagents/middleware.rs
@@ -25,6 +25,7 @@
mod tests;
include!("middleware_part_01.rs");
include!("middleware_part_02.rs");
+include!("middleware_part_07.rs");
include!("middleware_part_03.rs");
include!("middleware_part_04.rs");
include!("middleware_part_05.rs");
diff --git a/src/openhuman/agent/tinyagents/middleware_part_02.rs b/src/openhuman/agent/tinyagents/middleware_part_02.rs
index f507e275dc..477695e937 100644
--- a/src/openhuman/agent/tinyagents/middleware_part_02.rs
+++ b/src/openhuman/agent/tinyagents/middleware_part_02.rs
@@ -695,82 +695,4 @@ impl ToolPolicyMiddleware {
})
}
- /// The channel-permission gate the engine ran before the builder policy: a
- /// session-level deny, then a per-call permission-level ceiling check. Returns
- /// the blocking message when the call must not execute.
- fn channel_permission_block(&self, call: &TaToolCall) -> Option<String> {
- let decision = self.session.decision_for(&call.name);
- if decision.is_denied() {
- return Some(
- PolicyDenial::SessionForbidden {
- tool: &call.name,
- required: decision.required_permission,
- allowed: decision.allowed_permission,
- channel: &self.channel,
- }
- .render(),
- );
- }
- let tool = self.resolve_tool(&call.name)?;
- let call_required = tool.permission_level_with_args(&call.arguments);
- if call_required > decision.allowed_permission {
- return Some(
- PolicyDenial::PermissionTooLow {
- tool: &call.name,
- required: call_required,
- allowed: decision.allowed_permission,
- channel: &self.channel,
- }
- .render(),
- );
- }
- // For `use_skill`, also validate the resolved inner tool against the
- // session allowlist. Role-hidden packed tools are not checked by the
- // outer policy name; without this check `use_skill` would bypass the
- // session's effective allowlist for any packed tool.
- if call.name == "use_skill" {
- if let Some(inner_tool) = call
- .arguments
- .get("tool")
- .and_then(serde_json::Value::as_str)
- {
- // `blocks_execution`, NOT `is_denied`. Every withheld packed
- // tool is `HideFromPrompt`, and `use_skill` is the only route it
- // has — gating that route on `is_denied` refused all of them.
- let inner_decision = self.session.decision_for(inner_tool);
- if inner_decision.blocks_execution() {
- // Name the route. A bare denial gives the model nothing to
- // do differently, and a model with no next step retries the
- // same call: one live turn burned its whole budget on six
- // identical `use_skill` denials and died on the
- // repeated-failure breaker. Same sentence the listing uses,
- // resolved against the same session, so the two cannot
- // tell the model different stories.
- let hint = crate::openhuman::tools::toolpacks::pack_for_tool(inner_tool)
- .map(|pack| self.route_for_pack(pack))
- .filter(|h| !h.is_empty())
- .map(|h| format!(" {h}"))
- .unwrap_or_default();
- return Some(format!(
- "Tool `{inner_tool}` is not allowed in the current session and cannot be used through `use_skill`.{hint}"
- ));
- }
- }
- }
- None
- }
-
- fn generated_context(
- &self,
- name: &str,
- args: &serde_json::Value,
- ) -> Option<crate::openhuman::agent::tool_policy::GeneratedToolRuntimeContext> {
- self.tool_sets
- .iter()
- .flat_map(|set| set.iter())
- .find(|t| t.name() == name)
- .and_then(|t| {
- crate::openhuman::tools::traits::generated_runtime_context(t.as_ref(), args)
- })
- }
}
diff --git a/src/openhuman/agent/tinyagents/middleware_part_07.rs b/src/openhuman/agent/tinyagents/middleware_part_07.rs
new file mode 100644
index 0000000000..11f6f25f82
--- /dev/null
+++ b/src/openhuman/agent/tinyagents/middleware_part_07.rs
@@ -0,0 +1,32 @@
+ /// The channel-permission gate the engine ran before the builder policy: a
+ /// session-level deny, then a per-call permission-level ceiling check. Returns
+ /// the blocking message when the call must not execute.
+ fn channel_permission_block(&self, call: &TaToolCall) -> Option<String> {
+ let decision = self.session.decision_for(&call.name);
+ if decision.is_denied() {
+ return Some(PolicyDenial::SessionForbidden { tool: &call.name, required: decision.required_permission, allowed: decision.allowed_permission, channel: &self.channel }.render());
+ }
+ let tool = self.resolve_tool(&call.name)?;
+ let call_required = tool.permission_level_with_args(&call.arguments);
+ if call_required > decision.allowed_permission {
+ return Some(PolicyDenial::PermissionTooLow { tool: &call.name, required: call_required, allowed: decision.allowed_permission, channel: &self.channel }.render());
+ }
+ if call.name == "use_skill" {
+ if let Some(inner_tool) = call.arguments.get("tool").and_then(serde_json::Value::as_str) {
+ let inner_decision = self.session.decision_for(inner_tool);
+ if inner_decision.blocks_execution() {
+ let hint = crate::openhuman::tools::toolpacks::pack_for_tool(inner_tool)
+ .map(|pack| self.route_for_pack(pack)).filter(|h| !h.is_empty())
+ .map(|h| format!(" {h}")).unwrap_or_default();
+ return Some(format!("Tool `{inner_tool}` is not allowed in the current session and cannot be used through `use_skill`.{hint}"));
+ }
+ }
+ }
+ None
+ }
+
+ fn generated_context(&self, name: &str, args: &serde_json::Value) -> Option<crate::openhuman::agent::tool_policy::GeneratedToolRuntimeContext> {
+ self.tool_sets.iter().flat_map(|set| set.iter()).find(|t| t.name() == name)
+ .and_then(|t| crate::openhuman::tools::traits::generated_runtime_context(t.as_ref(), args))
+ }
+}