Skip to content

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

feat(agent): add per-agent deferred tool configuration

Steven Enamakel4c274f65ed31
diff --git a/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs b/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs
index 317c1a5204..69ceed2b05 100644
--- a/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs
+++ b/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs
@@ -146,6 +146,15 @@ pub struct AgentDefinition {
#[serde(default)]
pub extra_tools: Vec<String>,
+ /// Tools in this agent's scope that should leave its wire and be served
+ /// through `tool_search` instead: still registered, found by a search,
+ /// and callable by their own name. Unlike `ToolExposure::Deferred`, which
+ /// defers a tool for every agent, this defers it for this agent only.
+ /// Takes effect only on a belt that opted into discovery (a wildcard
+ /// belt, or `named` listing `tool_search`).
+ #[serde(default)]
+ pub deferred_tools: Vec<String>,
+
// ── runtime limits ──────────────────────────────────────────────────
/// Maximum number of tool iterations for this sub-agent's task.
#[serde(default = "defaults::max_iterations")]
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.rs
index cca2435cf2..cc6642be10 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
@@ -133,11 +133,12 @@ impl SessionHostBuilder {
// synthesised per session (`collect_orchestrator_tools`) and
// declares `Deferred` too. The synthesised set's `Hidden` members
// are left alone on purpose — see the comment above.
- deferred_names.extend(crate::tools::implementations::meta::deferred_tool_names(
+ // Plus the tools this agent's definition defers for itself
+ // (`deferred_tools`); see `meta::deferred_set`.
+ deferred_names.extend(crate::tools::implementations::meta::deferred_set(
tools.as_slice(),
- ));
- deferred_names.extend(crate::tools::implementations::meta::deferred_tool_names(
synthesized_tools.as_slice(),
+ &self.deferred_tools,
));
visible_names.retain(|name| !deferred_names.contains(name));
} else {
@@ -365,6 +366,7 @@ impl SessionHostBuilder {
visible_tool_names: visible_names,
deferred_tool_names: deferred_names,
discovery_enabled,
+ requested_deferred_tools: Arc::from(self.deferred_tools.clone()),
subagent_tool_ceiling_names,
tool_policy_session,
memory,
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
index 40f5645ca9..c9c78f7047 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -1007,6 +1007,7 @@ impl OpenHumanSessionHost {
.tools(tools)
.synthesized_tools(delegation_tools)
.visible_tool_names(visible)
+ .deferred_tools(target_def.map(|def| def.deferred_tools.clone()).unwrap_or_default())
.memory(memory)
.auto_recall(Some(auto_recall))
.tool_dispatcher(tool_dispatcher)
diff --git a/crates/openhuman-core/src/agent/session_host/builder/setters.rs b/crates/openhuman-core/src/agent/session_host/builder/setters.rs
index a4dcb1f21d..45e6c0734f 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/setters.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/setters.rs
@@ -16,6 +16,7 @@ impl SessionHostBuilder {
tools: None,
synthesized_tools: None,
visible_tool_names: None,
+ deferred_tools: Vec::new(),
subagent_tool_ceiling_names: None,
memory: None,
auto_recall: None,
@@ -98,6 +99,14 @@ impl SessionHostBuilder {
self
}
+ /// Tools to take off this agent's wire and serve through `tool_search`
+ /// instead (the definition's `deferred_tools`). Applies only to a belt
+ /// that opted into discovery; see `meta::deferred_set`.
+ pub fn deferred_tools(mut self, names: Vec<String>) -> Self {
+ self.deferred_tools = names;
+ self
+ }
+
/// Restrict the tool names that delegated agents may inherit from the full
/// registry. Empty/`None` keeps delegation governed by each child
/// definition unless the channel policy adds a ceiling.
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
index 8fc072e381..1f560cea1e 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
@@ -504,11 +504,11 @@ impl OpenHumanSessionHost {
self.deferred_tool_names.clear();
return;
}
- let mut deferred =
- crate::tools::implementations::meta::deferred_tool_names(self.tools.as_slice());
- deferred.extend(crate::tools::implementations::meta::deferred_tool_names(
+ let deferred = crate::tools::implementations::meta::deferred_set(
+ self.tools.as_slice(),
self.synthesized_tools.as_slice(),
- ));
+ &self.requested_deferred_tools,
+ );
self.visible_tool_names
.retain(|name| !deferred.contains(name));
self.deferred_tool_names = deferred;
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 bad9d39cf0..86c6e6a309 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -123,6 +123,8 @@ struct OpenHumanTurnToolSurface {
deferred_tool_names: std::collections::HashSet<String>,
/// Whether this belt reaches deferred tools at all; fixed at build.
discovery_enabled: bool,
+ /// The definition's own `deferred_tools`; see `meta::deferred_set`.
+ requested_deferred_tools: Arc<[String]>,
/// Whether newly connected delegates may enter the visible belt without a
/// caller explicitly allowing them. A hide/named restriction turns this
/// off so refresh cannot reopen withdrawn authority.
@@ -485,11 +487,11 @@ impl OpenHumanTurnPrelude {
// a `Deferred` synthesised tool leaves the wire and joins the
// searchable set, on a belt that opted into discovery.
if surface.discovery_enabled {
- let mut deferred =
- crate::tools::implementations::meta::deferred_tool_names(surface.tools.as_slice());
- deferred.extend(crate::tools::implementations::meta::deferred_tool_names(
+ let deferred = crate::tools::implementations::meta::deferred_set(
+ surface.tools.as_slice(),
synthesized.as_slice(),
- ));
+ &surface.requested_deferred_tools,
+ );
surface
.visible_tool_names
.retain(|name| !deferred.contains(name));
@@ -1526,6 +1528,7 @@ impl OpenHumanSessionHost {
visible_tool_names: self.visible_tool_names.clone(),
deferred_tool_names: self.deferred_tool_names.clone(),
discovery_enabled: self.discovery_enabled,
+ requested_deferred_tools: self.requested_deferred_tools.clone(),
auto_include_new_synthesized_tools: true,
synthesized_tool_names: self.synthesized_tool_names.clone(),
tool_policy_session: self.tool_policy_session.clone(),
@@ -1896,6 +1899,7 @@ impl OpenHumanSessionHost {
visible_tool_names: self.visible_tool_names.clone(),
deferred_tool_names: self.deferred_tool_names.clone(),
discovery_enabled: self.discovery_enabled,
+ requested_deferred_tools: self.requested_deferred_tools.clone(),
auto_include_new_synthesized_tools: auto_include_new_synthesized_tools
.unwrap_or(prior_auto_include),
synthesized_tool_names: self.synthesized_tool_names.clone(),
diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rs
index c9f77edb1b..1f5cca85c7 100644
--- a/crates/openhuman-core/src/agent/session_host/types.rs
+++ b/crates/openhuman-core/src/agent/session_host/types.rs
@@ -164,6 +164,10 @@ pub struct OpenHumanSessionHost {
/// Fixed at build; the refresh paths use it to recompute
/// [`Self::deferred_tool_names`] when the synthesised set changes.
pub(super) discovery_enabled: bool,
+ /// The agent definition's `deferred_tools`: `Direct` tools this agent
+ /// reaches through `tool_search` instead of its wire. Kept so every
+ /// recompute of [`Self::deferred_tool_names`] applies it again.
+ pub(super) requested_deferred_tools: Arc<[String]>,
/// Explicit profile/channel ceiling inherited by delegated agents.
///
/// This is deliberately separate from [`Self::visible_tool_names`]: a
@@ -506,6 +510,8 @@ pub struct SessionHostBuilder {
pub(super) synthesized_tools: Option<Vec<Box<dyn Tool>>>,
/// When set, restricts which tools the main agent sees/calls.
pub(super) visible_tool_names: Option<std::collections::HashSet<String>>,
+ /// See [`SessionHostBuilder::deferred_tools`].
+ pub(super) deferred_tools: Vec<String>,
/// Optional explicit profile ceiling for tools delegated agents may inherit.
/// Channel-policy restrictions are intersected during [`Self::build`].
pub(super) subagent_tool_ceiling_names: Option<std::collections::HashSet<String>>,
diff --git a/crates/openhuman-core/src/tools/impl/meta/deferred.rs b/crates/openhuman-core/src/tools/impl/meta/deferred.rs
index 00208f4e33..905e030d0c 100644
--- a/crates/openhuman-core/src/tools/impl/meta/deferred.rs
+++ b/crates/openhuman-core/src/tools/impl/meta/deferred.rs
@@ -83,6 +83,31 @@ pub fn deferred_tool_names(tools: &[Box<dyn Tool>]) -> HashSet<String> {
.collect()
}
+/// The deferred set of a belt that opted into discovery: every
+/// [`ToolExposure::Deferred`] tool in `durable` and `synthesized`, plus the
+/// `Direct` tools its agent definition lists in `deferred_tools`.
+///
+/// Exposure is a property of the tool and applies to every agent; a
+/// definition's `deferred_tools` is the per-agent half. It takes a tool that
+/// other belts keep advertised (`file_read` for a coding worker) off this
+/// agent's wire only, where it stays registered, searchable through
+/// `tool_search`, and callable by its own name. A requested name that is not
+/// registered, or is `Hidden`, is ignored: deferral only ever subtracts.
+pub fn deferred_set(
+ durable: &[Box<dyn Tool>],
+ synthesized: &[Box<dyn Tool>],
+ requested: &[String],
+) -> HashSet<String> {
+ let mut deferred = deferred_tool_names(durable);
+ deferred.extend(deferred_tool_names(synthesized));
+ for tool in durable.iter().chain(synthesized.iter()) {
+ if tool.exposure() == ToolExposure::Direct && requested.iter().any(|r| r == tool.name()) {
+ deferred.insert(tool.name().to_string());
+ }
+ }
+ deferred
+}
+
#[cfg(test)]
#[path = "deferred_tests.rs"]
mod tests;