Skip to content

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

refactor(session_host): use shared HostOnlyToolPolicy from runtime

Steven Enamakel1184c5076391
diff --git a/crates/openhuman-core/src/agent/session_host/builder/host_policy.rs b/crates/openhuman-core/src/agent/session_host/builder/host_policy.rs
index 198c4ca82b..6f30a85c04 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/host_policy.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/host_policy.rs
@@ -19,87 +19,18 @@
//! refresh has nothing to add), no deferred tools, read-only sandbox, and
//! no memory context.
-use std::collections::HashSet;
use std::sync::Arc;
-use async_trait::async_trait;
-
use crate::agent_registry::host_definition::AgentDefinition;
-use tinyagents_harness::context::RunContext;
-use tinyagents_harness::middleware::{PolicyDecision, ToolCallPolicy};
-use tinyinference_llm::tool::ToolCall;
-
-use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::OpenHumanSessionHost;
use crate::config::Config;
use anyhow::Result;
use tinyagents_definition::{SandboxMode, ToolScope};
-/// Deny-by-default gate for a host-only session.
-///
-/// A name outside `allowed` is refused outright. A name inside it is then put
-/// to the host's own gate, when the host supplied one, so host-only narrows a
-/// host's policy and never widens it.
-pub struct HostOnlyToolPolicy {
- allowed: HashSet<String>,
- host: Option<
- Arc<
- dyn tinyagents_harness::middleware::ToolCallPolicy<
- crate::agent::tinyagents::host::OpenHumanRunContext,
- >,
- >,
- >,
-}
-
-impl HostOnlyToolPolicy {
- /// Admit exactly `allowed`, subject to `host`'s own decision.
- #[must_use]
- pub fn new(
- allowed: HashSet<String>,
- host: Option<
- Arc<
- dyn tinyagents_harness::middleware::ToolCallPolicy<
- crate::agent::tinyagents::host::OpenHumanRunContext,
- >,
- >,
- >,
- ) -> Self {
- Self { allowed, host }
- }
-}
-
-#[async_trait]
-impl ToolCallPolicy<OpenHumanRunContext> for HostOnlyToolPolicy {
- fn name(&self) -> &str {
- "host_only"
- }
-
- async fn check(
- &self,
- ctx: &RunContext<OpenHumanRunContext>,
- call: &ToolCall,
- ) -> PolicyDecision {
- if !self.allowed.contains(&call.name) {
- log::debug!(
- "[agent::host_only] denied tool outside the host belt: {}",
- call.name
- );
- return PolicyDecision::deny(format!(
- "tool `{}` is not available to this agent",
- call.name
- ));
- }
- match &self.host {
- Some(host) => host.check(ctx, call).await,
- None => PolicyDecision::Allow,
- }
- }
-}
-
/// The visible set of a host-only belt before the host's names are merged in:
/// explicitly zero tools (an empty set would mean "no filter").
-pub(super) fn empty_belt() -> HashSet<String> {
- HashSet::from([crate::agent_registry::host_definition::NO_TOOLS_SENTINEL.to_string()])
+pub(super) fn empty_belt() -> std::collections::HashSet<String> {
+ std::collections::HashSet::from([crate::agent_registry::host_definition::NO_TOOLS_SENTINEL.to_string()])
}
/// The session gate: on a host-only belt, [`HostOnlyToolPolicy`] over the
@@ -127,7 +58,9 @@ pub(super) fn session_policy(
return host;
}
let allowed = tools.iter().map(|tool| tool.name().to_string()).collect();
- Some(Arc::new(HostOnlyToolPolicy::new(allowed, host)))
+ Some(Arc::new(tinyagents_runtime::HostOnlyToolPolicy::new(
+ allowed, host,
+ )))
}
/// The definition a host-only session runs under: `definition` with every
diff --git a/crates/openhuman-core/src/agent/session_host/builder/mod.rs b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
index e3a043f453..fd5c380af4 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
@@ -12,13 +12,12 @@ pub(crate) use factory_resolution::provider_role_for_definition;
mod builder_build;
mod factory;
mod factory_resolution;
-mod host_only;
+mod host_policy;
mod host_tools;
mod iteration_cap;
mod profile_factory;
mod setters;
-pub use host_only::HostOnlyToolPolicy;
pub use host_tools::{HostTools, HostTurnTools, TurnContext};
#[cfg(test)]
diff --git a/crates/openhuman-core/src/agent/session_host/mod.rs b/crates/openhuman-core/src/agent/session_host/mod.rs
index 6f86407feb..689e4a5230 100644
--- a/crates/openhuman-core/src/agent/session_host/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/mod.rs
@@ -31,7 +31,7 @@
#[cfg(feature = "flows")]
pub(crate) use builder::provider_role_for_definition;
-pub use builder::{HostOnlyToolPolicy, HostTools, HostTurnTools, TurnContext};
+pub use builder::{HostTools, HostTurnTools, TurnContext};
mod builder;
mod builder_config;