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(tools): route policy session construction through local module
Steven Enamakelcfe3f970c4ed
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rsindex 94aecb31f8..9c115e37c6 100644--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs@@ -5,7 +5,6 @@ use crate::agent::context::ContextManager;use crate::agent::session_host::types::{OpenHumanSessionHost, SessionHostBuilder};use anyhow::Result;use std::sync::Arc;-use tinytools::ToolPolicyEngine;use tinytools::{Tool, ToolSpec};impl SessionHostBuilder {@@ -214,7 +213,7 @@ impl SessionHostBuilder {.chain(synthesized_tools.iter()).map(|tool| tool.as_ref()).collect();- let mut tool_policy_session = ToolPolicyEngine::build_session_from_refs(+ let mut tool_policy_session = crate::tools::policy_session::build_policy_session(&agent_definition_name,&event_channel,"session",@@ -240,7 +239,7 @@ impl SessionHostBuilder {// `tool_policy_session` marks both channel-blocked and role-hidden tools// as restricted, so deriving the child ceiling from it would reintroduce// exactly that conflation.- let channel_policy_session = ToolPolicyEngine::build_session_from_refs(+ let channel_policy_session = crate::tools::policy_session::build_policy_session(&agent_definition_name,&event_channel,"session",diff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rsindex cdd9f423bd..d0d1ebf413 100644--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs@@ -5,7 +5,6 @@use super::super::types::{OpenHumanSessionHost, SessionHostBuilder};use std::collections::HashSet;use std::sync::Arc;-use tinytools::ToolPolicyEngine;use tinytools::{Tool, ToolSpec};use tinytools_agent::dialect::TranscriptEntry;@@ -506,7 +505,7 @@ impl OpenHumanSessionHost {// at all.let all_tools = self.all_tool_refs();let reachable = self.reachable_tool_names();- let mut session = ToolPolicyEngine::build_session_from_refs(+ let mut session = crate::tools::policy_session::build_policy_session(&self.agent_definition_name,&self.event_channel,"session",diff --git a/crates/openhuman-core/src/tools/mod.rs b/crates/openhuman-core/src/tools/mod.rsindex 94cf92bdca..967fed8308 100644--- a/crates/openhuman-core/src/tools/mod.rs+++ b/crates/openhuman-core/src/tools/mod.rs@@ -3,6 +3,7 @@ pub(crate) mod native_ops;mod native_ops_types;pub mod ops;pub mod orchestrator_tools;+pub(crate) mod policy_session;pub mod registry;pub mod rules;pub(crate) mod schema_cache;diff --git a/crates/openhuman-core/src/tools/policy_session.rs b/crates/openhuman-core/src/tools/policy_session.rsnew file mode 100644index 0000000000..bbe3f68250--- /dev/null+++ b/crates/openhuman-core/src/tools/policy_session.rs@@ -0,0 +1,73 @@+//! Host entry point for building a tool-policy snapshot.+//!+//! The classification engine lives in `tinytools::ToolPolicyEngine`; this file+//! keeps the host-side trace logging that used to sit inside it, so a policy+//! snapshot stays greppable under `[tool-policy]`.++use std::collections::{BTreeSet, HashMap, HashSet};++use tinytools::{Tool, ToolPolicyEngine, ToolPolicySession};++const LOG_TARGET: &str = "openhuman::tools::agent_policy";++/// Build a [`ToolPolicySession`] over borrowed tools and trace the outcome.+pub(crate) fn build_policy_session(+ agent_id: &str,+ channel: &str,+ entrypoint: &str,+ channel_permissions: &HashMap<String, String>,+ tools: &[&dyn Tool],+ visible_tool_names: &HashSet<String>,+) -> ToolPolicySession {+ log::debug!(+ target: LOG_TARGET,+ "[tool-policy] build_session start agent={} channel={} entrypoint={} tools={} visible={} channel_permissions={}",+ agent_id,+ channel,+ entrypoint,+ tools.len(),+ visible_tool_names.len(),+ channel_permissions.len()+ );+ if channel_permissions.is_empty() {+ log::debug!(+ target: LOG_TARGET,+ "[tool-policy] channel permissions empty; engine preserves the legacy unrestricted surface channel={channel}"+ );+ } else if !channel_permissions.contains_key(channel) {+ log::debug!(+ target: LOG_TARGET,+ "[tool-policy] channel permission missing; engine falls back to readonly channel={channel}"+ );+ }+ let session = ToolPolicyEngine::build_session_from_refs(+ agent_id,+ channel,+ entrypoint,+ channel_permissions,+ tools,+ visible_tool_names,+ );+ log::debug!(+ target: LOG_TARGET,+ "[tool-policy] build_session done agent={} channel={} allowed={} blocked={} hidden={} permission={}",+ agent_id,+ channel,+ session.allowed_tool_names.len(),+ session.blocked_tool_names.len(),+ session.hidden_tool_names.len(),+ session.profile.allowed_permission+ );+ if log::log_enabled!(target: LOG_TARGET, log::Level::Trace) {+ let blocked: BTreeSet<&String> = session.blocked_tool_names.iter().collect();+ log::trace!(+ target: LOG_TARGET,+ "[tool-policy] blocked tools agent={agent_id} channel={channel} names={blocked:?}"+ );+ }+ session+}++#[cfg(test)]+#[path = "policy_session_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/tools/policy_session_tests.rs b/crates/openhuman-core/src/tools/policy_session_tests.rsnew file mode 100644index 0000000000..5198868440--- /dev/null+++ b/crates/openhuman-core/src/tools/policy_session_tests.rs@@ -0,0 +1,36 @@+use super::*;++#[test]+fn empty_tool_set_yields_an_unrestricted_session() {+ let session = build_policy_session(+ "orchestrator",+ "web",+ "session",+ &HashMap::new(),+ &[],+ &HashSet::new(),+ );+ assert!(!session.has_restrictions());+ assert!(session.allowed_tool_names.is_empty());+ assert_eq!(session.profile.agent_id, "orchestrator");+ assert_eq!(session.profile.channel, "web");+}++#[test]+fn matches_the_engine_for_a_restricted_channel() {+ let mut perms = HashMap::new();+ perms.insert("web".to_string(), "readonly".to_string());+ let ours = build_policy_session("a", "web", "session", &perms, &[], &HashSet::new());+ let engine = ToolPolicyEngine::build_session_from_refs(+ "a",+ "web",+ "session",+ &perms,+ &[],+ &HashSet::new(),+ );+ assert_eq!(+ ours.profile.allowed_permission,+ engine.profile.allowed_permission+ );+}