Skip to content

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

feat(session): hide rule-withheld tools from the system prompt

Steven Enamakelbc97a1178335
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 2a753bcdfa..0db5f55c28 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -18,8 +18,8 @@ use std::sync::Arc;
use anyhow::Result;
use tinyagents_runtime::{
- CommitReceipt, ResumePreparation, SessionBuilder, SessionTerminal, SessionTurnRequest,
- ToolSnapshot, TranscriptTarget, TurnPreparation,
+ CommitReceipt, ResumePreparation, SessionBuilder, SessionTerminal, ToolSnapshot,
+ TranscriptTarget, TurnPreparation,
};
use tinyagents_session::transcript::TranscriptMeta;
use tinyinference_llm::message::Message;
@@ -259,14 +259,6 @@ impl OpenHumanTurnPrelude {
tools: Some(tools),
})
}
- fn begin_user_effects(&self, request: &SessionTurnRequest) {
- let user_text =
- crate::agent::turn_origin::current_is_user_authored().then(|| request.input.text());
- self.mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .pending_user_text = user_text;
- }
fn build_system_prompt_tiered(&self) -> Result<crate::agent::prompts::TieredPrompt> {
use crate::agent::prompts::{tool_call_format_from_dialect, PromptContext, PromptTool};
@@ -274,9 +266,11 @@ impl OpenHumanTurnPrelude {
.tool_surface
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
+ let withheld = self.rule_withheld_tools(&surface);
let specs = surface
.visible_tool_specs
.iter()
+ .filter(|spec| !withheld.contains(&spec.name))
.filter(|spec| {
self.thread_id.is_some()
|| !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(
@@ -300,7 +294,9 @@ impl OpenHumanTurnPrelude {
.collect::<Vec<_>>();
let mut prompt_tools = PromptTool::from_tool_refs(tool_refs.iter().copied());
prompt_tools.retain(|tool| !surface.permanent_tool_names.contains(tool.name.as_ref()));
+ prompt_tools.retain(|tool| !withheld.contains(tool.name.as_ref()));
let mut visible_tool_names = surface.tool_policy_session.visible_tool_names_for_prompt();
+ visible_tool_names.retain(|name| !withheld.contains(name));
visible_tool_names.retain(|name| !surface.permanent_tool_names.contains(name));
if self.thread_id.is_none() {
visible_tool_names.retain(|name| {
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 58a3f13e38..69791bc296 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
@@ -7,10 +7,12 @@
use std::sync::Arc;
-use super::{OpenHumanSessionHost, OpenHumanTurnPrelude};
+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};
impl OpenHumanSessionHost {
/// The session's rule layers, from its config and resolved definition.
@@ -23,6 +25,51 @@ impl OpenHumanSessionHost {
}
impl OpenHumanTurnPrelude {
+ /// Names the session's rules keep off a listing — the catalogue for a
+ /// direct tool, search for a deferred one — evaluated in the session's
+ /// channel/agent context. The host renders its own tool catalogue into
+ /// the system prompt, so it must drop these exactly as the harness drops
+ /// their schemas; a hidden tool stays callable, it is just not listed.
+ pub(super) fn rule_withheld_tools(
+ &self,
+ surface: &OpenHumanTurnToolSurface,
+ ) -> std::collections::HashSet<String> {
+ if self.tool_rules.is_permissive() {
+ return std::collections::HashSet::new();
+ }
+ let context = crate::tools::rules::rule_context(
+ Some(&surface.event_channel),
+ Some(&self.agent_definition_id),
+ None,
+ );
+ surface
+ .tools
+ .iter()
+ .chain(surface.synthesized_tools.iter())
+ .filter(|tool| {
+ let surface_kind = if surface.deferred_tool_names.contains(tool.name()) {
+ Surface::Search
+ } else {
+ Surface::Catalog
+ };
+ !self
+ .tool_rules
+ .visible(&ToolSubject::of(tool.as_ref()), &context, surface_kind)
+ })
+ .map(|tool| tool.name().to_string())
+ .collect()
+ }
+
+ /// Records the user text a turn begins with, for its user-side effects.
+ pub(super) fn begin_user_effects(&self, request: &SessionTurnRequest) {
+ let user_text =
+ crate::agent::turn_origin::current_is_user_authored().then(|| request.input.text());
+ self.mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .pending_user_text = user_text;
+ }
+
/// This turn's rule policy: the session's layers in the turn's context.
/// `None` when the session's rules restrict nothing.
pub(super) fn turn_tool_rules(