Skip to content

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

fix(session_host): restore tool call state after failed execution

Steven Enamakel1c497a502a8b
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 aeddb9ef90..8dff4aecfa 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
@@ -75,38 +75,52 @@ impl SessionHostBuilder {
);
// Per-tool exposure: `Hidden` members of a collapsed tool (`memory_*`,
// `todo_*`) and `Deferred` tools leave the wire; they stay registered
- // and dispatchable. Only for a wildcard belt — a hand-written `[tools]
- // named` list is already the answer to "what should this agent see".
+ // and dispatchable. A wildcard belt always gets this; a hand-written
+ // `[tools] named` list is already the answer to "what should this
+ // agent see", so it opts into discovery by naming `tool_search` — the
+ // harness's intrinsic bridge, not a registered tool, so the name is
+ // taken off the allowlist here and stands for "every deferred
+ // registration is reachable through the bridge".
//
// Only the DURABLE registry is passed, never `synthesized_tools`: every
// `ArchetypeDelegationTool` reports `Hidden`, and on a wildcard belt the
// synthesised delegates are the agent's only hand-off routes. Stripping
// them would delete every `research`/`run_code`/… route.
- // `strip_deferred_from_visible` only looks at the tools it is given.
//
// This is the one site that turns the "all visible" sentinel into a
// concrete set for a session, so the refresh paths never re-admit a
// durable Hidden tool: `refresh_delegation_tools` (turn/tools.rs) only
// swaps synthesised names, and `OpenHumanSessionHost::hide_tools` only seeds a set
// that is still empty — see the matching strip there.
- let deferred = if belt_is_wildcard {
+ let discovery_opted_in =
+ visible_names.remove(crate::tools::implementations::meta::TOOL_SEARCH_NAME);
+ let deferred_names = if belt_is_wildcard {
crate::tools::implementations::meta::strip_deferred_from_visible(
&mut visible_names,
tools.as_slice(),
)
+ } else if discovery_opted_in {
+ let deferred = crate::tools::implementations::meta::deferred_tool_names(tools.as_slice());
+ visible_names.retain(|name| !deferred.contains(name));
+ deferred
} else {
- Vec::new()
+ std::collections::HashSet::new()
};
- if !deferred.is_empty() {
+ if !deferred_names.is_empty() {
tracing::info!(
agent = %agent_definition_name,
- deferred = deferred.len(),
- "[tools] withheld deferred tool schemas; reachable via tool_search"
+ deferred = deferred_names.len(),
+ "[tools] withheld deferred tool schemas; reachable via the harness tool_search bridge"
);
}
- // Index them where the model can find them again. Done here rather than
- // at registration because which tools are deferred depends on the belt.
- crate::tools::implementations::meta::bind_tool_search_index(tools.as_slice(), deferred);
+ // What the policy classifies and the harness registers: the advertised
+ // set plus the deferred set. A deferred tool outside this union would
+ // be `HideFromPrompt`, and the direct-call gate refuses those.
+ let reachable_names: std::collections::HashSet<String> = visible_names
+ .iter()
+ .chain(deferred_names.iter())
+ .cloned()
+ .collect();
let config = self.config.clone().unwrap_or_default();
let event_session_id = self
.event_session_id
@@ -128,7 +142,7 @@ impl SessionHostBuilder {
"session",
&config.channel_permissions,
&all_tools,
- &visible_names,
+ &reachable_names,
);
// A pack whose owner this agent can hand off to directly is that
// specialist's belt, not this agent's: close it (#6302).
@@ -282,6 +296,7 @@ impl SessionHostBuilder {
durable_tool_specs: Arc::new(durable_tool_specs),
visible_tool_specs: Arc::new(visible_tool_specs),
visible_tool_names: visible_names,
+ deferred_tool_names: deferred_names,
subagent_tool_ceiling_names,
tool_policy_session,
memory,
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 cfa0e687bd..a82afe2cba 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
@@ -431,14 +431,27 @@ impl OpenHumanSessionHost {
&mut self.visible_tool_names,
&self.agent_definition_name,
);
- let deferred = crate::tools::implementations::meta::strip_deferred_from_visible(
+ self.deferred_tool_names = crate::tools::implementations::meta::strip_deferred_from_visible(
&mut self.visible_tool_names,
self.tools.as_slice(),
);
- crate::tools::implementations::meta::bind_tool_search_index(
- self.tools.as_slice(),
- deferred,
- );
+ }
+
+ /// The names the harness registers for a turn: the advertised set plus
+ /// the deferred set the `tool_search` bridge can reach. The empty
+ /// wildcard sentinel stays empty — "no filter" already admits the
+ /// deferred tools.
+ pub(in crate::agent::session_host) fn reachable_tool_names(
+ &self,
+ ) -> std::collections::HashSet<String> {
+ if self.visible_tool_names.is_empty() {
+ return std::collections::HashSet::new();
+ }
+ self.visible_tool_names
+ .iter()
+ .chain(self.deferred_tool_names.iter())
+ .cloned()
+ .collect()
}
/// Remove `names` from the main agent's callable set for this session,
@@ -477,13 +490,14 @@ impl OpenHumanSessionHost {
// registry alone would leave every `delegate_*` tool with no decision
// at all.
let all_tools = self.all_tool_refs();
+ let reachable = self.reachable_tool_names();
let mut session = ToolPolicyEngine::build_session_from_refs(
&self.agent_definition_name,
&self.event_channel,
"session",
&self.config.channel_permissions,
&all_tools,
- &self.visible_tool_names,
+ &reachable,
);
// Same narrowing as the builder, re-applied on every rebuild so a
// delegation refresh cannot reopen a closed pack (#6302).
diff --git a/crates/openhuman-core/src/agent/session_host/turn/tools.rs b/crates/openhuman-core/src/agent/session_host/turn/tools.rs
index cace8565fd..99a359f40a 100644
--- a/crates/openhuman-core/src/agent/session_host/turn/tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn/tools.rs
@@ -116,7 +116,9 @@ impl OpenHumanSessionHost {
(
Arc::clone(&self.tools),
Arc::clone(&self.synthesized_tools),
- self.visible_tool_names.clone(),
+ // Advertised plus deferred: the harness advertises only the
+ // `Direct` registrations and reaches the rest through its bridge.
+ self.reachable_tool_names(),
)
}
diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rs
index 48eedaaef0..8c759d2d6d 100644
--- a/crates/openhuman-core/src/agent/session_host/types.rs
+++ b/crates/openhuman-core/src/agent/session_host/types.rs
@@ -150,6 +150,15 @@ pub struct OpenHumanSessionHost {
/// their per-definition scopes with the effective parent-visible set.
/// Empty = no filter (all tools visible, backward compat).
pub(super) visible_tool_names: std::collections::HashSet<String>,
+ /// Registered tools that left the wire under
+ /// [`ToolExposure::Deferred`](tinytools::ToolExposure): never in
+ /// [`Self::visible_tool_names`], never in the prompt's spec list, but
+ /// handed to the harness beside the visible set so its intrinsic
+ /// `tool_search` / `tool_call` bridge can find and run them. Empty for a
+ /// belt that did not opt into discovery. Classified `Allow` by the
+ /// policy session exactly like a visible tool — a found tool the gate
+ /// refused as "prompt-hidden" would be the old unusable find again.
+ pub(super) deferred_tool_names: std::collections::HashSet<String>,
/// Explicit profile/channel ceiling inherited by delegated agents.
///
/// This is deliberately separate from [`Self::visible_tool_names`]: a