Skip to content

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

refactor(subagent_host): reuse shared tool-spec dedup helper

Steven Enamakelfee26c5e717e
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
index 7f7cb13b00..f48b88eb72 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
@@ -212,8 +212,8 @@ pub(in super::super) async fn run_subagent_via_graph(
history: dispatch_history,
// Dynamic (per-spawn) tools first so a dynamic tool that intentionally
// shadows a parent-registry tool of the same name is the one that
- // *executes* — matching the advertisement order (`dedup_tool_specs_by_name`
- // lists dynamic specs before parent specs in `runner.rs`). The shared
+ // *executes* — matching the advertisement order (`dedup_visible_tool_specs`
+ // keeps the first dynamic spec before parent specs in `runner.rs`). The shared
// adapter resolves a name by scanning the sets in order, so a
// parent-first order would run the parent impl for a shadowed name.
tool_sets: vec![Arc::new(dynamic_tools), parent_tools],
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs b/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs
index 0e701ceae9..cb4b2234a9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs
@@ -36,12 +36,6 @@ pub(crate) use provider::resolve_subagent_source;
// Re-exports for test companion modules that use `use super::*`.
// These provide the same flat namespace the original ops.rs had.
-// `dedup_tool_specs_by_name` is private in its source
-// module and cannot be `pub`-re-exported; a plain `use` still makes them
-// reachable from the `#[cfg(test)]` companion modules via their `use super::*`
-// (descendants can name ancestor-private imports).
-#[cfg(test)]
-use prompt::dedup_tool_specs_by_name;
// filter_tool_indices lives in tool_prep (sibling of ops).
#[cfg(test)]
pub(super) use super::tool_prep::filter_tool_indices;
@@ -64,6 +58,3 @@ use tinytools::ToolSpec;
#[path = "../ops_tests.rs"]
mod tests;
-#[cfg(test)]
-#[path = "../ops_dedup_tests.rs"]
-mod dedup_tests;
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs b/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs
index cc8fac677e..9304f8450f 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs
@@ -1,14 +1,13 @@
//! System-prompt helpers for sub-agent typed mode.
//!
-//! Includes the artifact-offload contract and the tool-spec deduplication
-//! helper used before sending specs to the provider.
+//! Includes the artifact-offload contract used before sending specs to the
+//! provider.
use crate::agent::harness::artifact_offload::OFFLOAD_WRITE_TOOL;
use std::collections::HashSet;
use tinyagents_harness::artifacts::{
render_artifact_offload_contract, should_render_offload_contract, ARTIFACT_OFFLOAD_HEADING,
};
-use tinytools::ToolSpec;
/// Compose the leaf role framing with the host's artifact-tool prompt policy.
pub(crate) fn compose_subagent_system_prompt(
@@ -77,44 +76,3 @@ pub(crate) fn append_artifact_offload_contract(
prompt
}
-// ─────────────────────────────────────────────────────────────────────────────
-// Tool-spec deduplication
-// ─────────────────────────────────────────────────────────────────────────────
-
-/// Deduplicate assembled tool specs by name, keeping the first occurrence.
-///
-/// The sub-agent's `filtered_specs` is a `Vec` assembled from
-/// `parent.all_tool_specs` indices plus dynamic tools, so a delegation tool can
-/// shadow a same-named skill/integration tool (common for the wide-set
-/// `tools_agent`), leaving two specs with the same name. Strict providers reject
-/// such a request with `400 "Tool names must be unique."` The main-agent path
-/// dedups via [`session::builder::dedup_visible_tool_specs`]; this separate
-/// sub-agent assembly must do the same.
-///
-/// First occurrence wins so registration-order semantics are preserved (tool
-/// dispatch still resolves by name). Dropped duplicates are logged at `debug`
-/// (diagnostic instrumentation, per the repo Rust logging guideline).
-///
-/// Extracted as a free function so the regression suite can exercise the dedup
-/// without standing up the full `run_typed_mode` plumbing.
-pub(super) fn dedup_tool_specs_by_name(agent_id: &str, specs: Vec<ToolSpec>) -> Vec<ToolSpec> {
- let mut seen: HashSet<String> = HashSet::with_capacity(specs.len());
- let mut deduped: Vec<ToolSpec> = Vec::with_capacity(specs.len());
- let mut dropped: Vec<String> = Vec::new();
- for spec in specs {
- if seen.insert(spec.name.clone()) {
- deduped.push(spec);
- } else {
- dropped.push(spec.name);
- }
- }
- if !dropped.is_empty() {
- tracing::debug!(
- agent_id = %agent_id,
- "[subagent_host] dropped {} duplicate tool spec(s) before sending to provider: {:?}",
- dropped.len(),
- dropped
- );
- }
- deduped
-}
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 50dc046623..6f0d23a254 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -14,6 +14,7 @@ use crate::agent::harness::fork_context::ParentExecutionContext;
use crate::agent::prompts::render_subagent_system_prompt_with_format;
use crate::agent::prompts::{PromptContext, SubagentRenderOptions};
use crate::agent::subagent_host::definition_iter_cap;
+use crate::agent::session_host::dedup_visible_tool_specs;
use crate::agent::subagent_host::tool_prep::{
filter_tool_indices, is_subagent_spawn_tool, load_prompt_source, subagent_prompt_protocol,
};
@@ -35,7 +36,7 @@ use tinyagents_harness::context::{current_run_depth, with_run_depth, RunConfig,
use tinytools::{SandboxMode as TinyagentsSandboxMode, ToolSpec, WorkspaceDescriptor};
use tinytools_std::file_state::with_file_state_agent_id;
-use super::prompt::{compose_subagent_system_prompt, dedup_tool_specs_by_name};
+use super::prompt::compose_subagent_system_prompt;
use super::provider::resolve_subagent_source;
/// Runtime spawn-hierarchy gate decision for one delegation hop.
@@ -701,8 +702,7 @@ async fn run_typed_mode(
.iter()
.map(|&i| parent.all_tools[i].name().to_string())
.collect();
- let filtered_specs = crate::agent::session_host::dedup_visible_tool_specs(filtered_specs);
- let filtered_specs = dedup_tool_specs_by_name(&definition.id, filtered_specs);
+ let filtered_specs = dedup_visible_tool_specs(filtered_specs);
tracing::debug!(
agent_id = %definition.id,