Skip to content

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

chore: files changed crates/openhuman-core/src/channels/runtime/dispatch/host_agent/guard_tool.rs,cr

Steven Enamakel1bfda9199a5a
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/guard_tool.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/guard_tool.rs
index bc15b03185..798f474e9f 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/guard_tool.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/guard_tool.rs
@@ -22,6 +22,9 @@ impl Tool for CeilingGuard {
self.inner.parameters_schema()
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ if let Some(refused) = self.refusal(&args) {
+ return Ok(refused);
+ }
self.inner.execute(args).await
}
async fn execute_with_options(
@@ -29,6 +32,9 @@ impl Tool for CeilingGuard {
args: Value,
options: ToolCallOptions,
) -> anyhow::Result<ToolResult> {
+ if let Some(refused) = self.refusal(&args) {
+ return Ok(refused);
+ }
self.inner.execute_with_options(args, options).await
}
async fn execute_with_context(
@@ -37,6 +43,9 @@ impl Tool for CeilingGuard {
options: ToolCallOptions,
context: Option<&dyn ToolRunContext>,
) -> anyhow::Result<ToolResult> {
+ if let Some(refused) = self.refusal(&args) {
+ return Ok(refused);
+ }
self.inner.execute_with_context(args, options, context).await
}
fn policy(&self) -> ToolPolicy {
@@ -69,11 +78,14 @@ impl Tool for CeilingGuard {
fn is_concurrency_safe(&self, args: &Value) -> bool {
self.inner.is_concurrency_safe(args)
}
+ // The guard answers an external-effect call itself (by refusing it), so
+ // it reports none: the approval gate must not park a call that will be
+ // refused anyway.
fn external_effect(&self) -> bool {
- self.inner.external_effect()
+ false
}
- fn external_effect_with_args(&self, args: &Value) -> bool {
- self.inner.external_effect_with_args(args)
+ fn external_effect_with_args(&self, _args: &Value) -> bool {
+ false
}
fn max_result_size_chars(&self) -> Option<usize> {
self.inner.max_result_size_chars()
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.rs
index d128aa0d62..897b06d53f 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
@@ -18,19 +18,50 @@ use crate::config::Config;
/// The most a host agent may do on a turn from `origin`; `None` leaves the
/// agent's own limits alone.
pub(crate) fn tool_ceiling(origin: &AgentTurnOrigin) -> Option<PermissionLevel> {
- let _ = origin;
- None
+ match origin {
+ AgentTurnOrigin::ExternalChannel { .. } => Some(PermissionLevel::ReadOnly),
+ _ => None,
+ }
}
/// Cap `channel` at `ceiling` in this turn's `config`.
+///
+/// The session's tool-policy snapshot reads this map, so every tool on the
+/// belt -- built-in or host -- above the ceiling is denied before it runs,
+/// per call. Only ever narrows: an operator's `none` is kept.
pub(crate) fn cap_channel(config: &mut Config, channel: &str, ceiling: PermissionLevel) {
- let _ = (config, channel, ceiling);
+ let entry = config
+ .agent
+ .channel_permissions
+ .entry(channel.to_string())
+ .or_default();
+ if entry.trim().eq_ignore_ascii_case("none") {
+ return;
+ }
+ *entry = permission_token(ceiling).to_string();
+}
+
+/// The `channel_permissions` spelling of `level`.
+fn permission_token(level: PermissionLevel) -> &'static str {
+ match level {
+ PermissionLevel::None => "none",
+ PermissionLevel::ReadOnly => "readonly",
+ PermissionLevel::Write => "write",
+ PermissionLevel::Execute => "execute",
+ PermissionLevel::Dangerous => "dangerous",
+ }
}
/// `host` with every tool it builds refusing calls above `ceiling`.
pub(crate) fn guard_host_tools(host: HostTools, ceiling: PermissionLevel) -> HostTools {
- let _ = ceiling;
- host
+ std::sync::Arc::new(move |turn| {
+ let mut belt = host(turn);
+ belt.tools = std::mem::take(&mut belt.tools)
+ .into_iter()
+ .map(|tool| Box::new(CeilingGuard::new(tool, ceiling)) as Box<dyn Tool>)
+ .collect();
+ belt
+ })
}
/// A tool that refuses calls above its ceiling instead of running them.
@@ -43,6 +74,29 @@ impl CeilingGuard {
pub(crate) fn new(inner: Box<dyn Tool>, ceiling: PermissionLevel) -> Self {
Self { inner, ceiling }
}
+
+ /// The refusal for a call with `args`, or `None` when it may run.
+ fn refusal(&self, args: &serde_json::Value) -> Option<tinytools::ToolResult> {
+ let required = self.inner.permission_level_with_args(args);
+ let effect = self.inner.external_effect_with_args(args);
+ if required <= self.ceiling && !effect {
+ return None;
+ }
+ let name = self.inner.name();
+ tracing::info!(
+ tool = name,
+ %required,
+ external_effect = effect,
+ ceiling = %self.ceiling,
+ "[channels::dispatch::host_agent] refused tool call on an external channel turn"
+ );
+ Some(tinytools::ToolResult::error(format!(
+ "Tool '{name}' is not available in this chat: messages here come from people \
+ outside this deployment, so actions that change anything (required: {required}, \
+ allowed: {}) are refused. Answer with what you can do without it.",
+ self.ceiling
+ )))
+ }
}
#[path = "guard_tool.rs"]