Skip to content

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

fix(agent): allow tool rules to match on tool arguments

Steven Enamakel6a05e0258aca
diff --git a/crates/openhuman-core/src/agent/registry/rpc.rs b/crates/openhuman-core/src/agent/registry/rpc.rs
index 3d5efe1247..83966c28cc 100644
--- a/crates/openhuman-core/src/agent/registry/rpc.rs
+++ b/crates/openhuman-core/src/agent/registry/rpc.rs
@@ -105,7 +105,8 @@ impl CreateCustomRequest {
system_prompt: self.system_prompt,
tool_allowlist: self.tool_allowlist,
tool_denylist: self.tool_denylist,
- tool_rules: self.tool_rules.filter(|rules| !rules.is_permissive()),
+ // Passed through: an empty set clears the entry's rules (`apply_patch`).
+ tool_rules: self.tool_rules,
subagents: self.subagents,
tags: self.tags,
metadata: self.metadata.unwrap_or(Value::Null),
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs
index 69791bc296..79691e3c82 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs
@@ -2,14 +2,13 @@
//!
//! A session composes its rule layers once — the operator's `[tool_rules]`
//! and its agent definition's layer — and every turn evaluates them in that
-//! turn's own context (channel, agent, origin), installed on
+//! session's context (channel, agent), installed on
//! `OpenHumanRunContext::tool_rules` for the harness gate.
use std::sync::Arc;
use super::{OpenHumanSessionHost, OpenHumanTurnPrelude, OpenHumanTurnToolSurface};
use crate::agent::tinyagents::host::OpenHumanRunContext;
-use crate::agent::turn_origin::AgentTurnOrigin;
use tinyagents_harness::tool::ToolRulePolicy;
use tinyagents_runtime::SessionTurnRequest;
use tinytools::{Surface, ToolSubject};
@@ -80,12 +79,12 @@ impl OpenHumanTurnPrelude {
if self.tool_rules.is_permissive() {
return None;
}
- let origin = run_context.origin.as_ref().map(AgentTurnOrigin::class);
- let context = crate::tools::rules::rule_context(
- Some(channel),
- Some(&self.agent_definition_id),
- origin.as_deref(),
- );
+ // The session's own context only (channel, agent), never the turn's
+ // origin: the host-rendered catalogue is cached for the session, and
+ // it must list exactly what this policy admits on every turn.
+ let _ = run_context;
+ let context =
+ crate::tools::rules::rule_context(Some(channel), Some(&self.agent_definition_id), None);
Some(Arc::new(crate::tools::rules::turn_rule_policy(
self.tool_rules.clone(),
context,
diff --git a/crates/openhuman-core/src/tools/rules/ops.rs b/crates/openhuman-core/src/tools/rules/ops.rs
index 1fe5bc438c..39f612fcf6 100644
--- a/crates/openhuman-core/src/tools/rules/ops.rs
+++ b/crates/openhuman-core/src/tools/rules/ops.rs
@@ -24,6 +24,11 @@ pub fn glob_list_matches(patterns: &[String], name: &str) -> bool {
/// Name prefix of every layer an agent definition contributes.
const AGENT_LAYER_PREFIX: &str = "agent:";
+/// Name of the operator's `[tool_rules]` layer; an author's own name is kept
+/// as a `config:<own>` suffix. Composition sets both prefixes itself, so an
+/// operator cannot name a layer into looking like an agent's (or back).
+const OPERATOR_LAYER: &str = "config";
+
/// The rule layer an agent definition contributes: its `tool_rules`, plus a
/// `deny` for its `disallowed_tools`, so a denied tool is refused on every
/// surface — including `tool_search` and a call by a guessed name — not only
@@ -58,9 +63,10 @@ pub fn session_rule_set(config: Option<&Config>, def: Option<&AgentDefinition>)
let mut set = ToolRuleSet::new();
if let Some(config) = config {
let mut layer = config.tool_rules.clone();
- if layer.name.is_none() {
- layer.name = Some("config".to_string());
- }
+ layer.name = Some(match layer.name.take() {
+ Some(own) => format!("{OPERATOR_LAYER}:{own}"),
+ None => OPERATOR_LAYER.to_string(),
+ });
set.push(layer);
}
if let Some(layer) = def.and_then(agent_rule_layer) {
@@ -111,11 +117,12 @@ pub fn child_rule_policy(
Some(parent) => {
let mut inherited = ToolRuleSet::new();
for layer in &parent.rules.layers {
- let is_agent_layer = layer
- .name
- .as_deref()
- .is_some_and(|name| name.starts_with(AGENT_LAYER_PREFIX));
- if !is_agent_layer {
+ // Only the operator's layer is inherited; its name is set by
+ // `session_rule_set`, never taken verbatim from the author.
+ let is_operator_layer = layer.name.as_deref().is_some_and(|name| {
+ name == OPERATOR_LAYER || name.starts_with(&format!("{OPERATOR_LAYER}:"))
+ });
+ if is_operator_layer {
inherited.push(layer.clone());
}
}