Skip to content

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

refactor: keep session factory within layout limit

Steven Enamakel74a1d0db3c1e
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 897656e37b..aa503584ed 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -771,9 +771,6 @@ impl OpenHumanSessionHost {
);
}
effective_agent_config.max_tool_iterations = effective_cap;
- // Host-first, so a host tool wins a name collision -- see
- // `HostTurnTools::merge_into`, which owns that rule and why.
- let visible_before_host_tools = visible.clone();
let merged_host_tools = super::host_tools::merge_for_turn(
host,
agent_id,
@@ -781,25 +778,7 @@ impl OpenHumanSessionHost {
&mut tools,
&mut visible,
)?;
- // Named definitions enforce their provider-visible allowlist through
- // the hosted definition adapter as well as the session's visible set.
- // Carry host-added names into that same definition, or the adapter
- // drops an attached tool from the model schema while its prompt marker
- // still advertises it. Wildcard definitions already include every
- // registered host tool.
- let host_scope_additions: Vec<String> = visible
- .difference(&visible_before_host_tools)
- .filter(|name| !merged_host_tools.withheld.contains(*name))
- .cloned()
- .collect();
- let mut session_definition = target_def.cloned();
- if let Some(definition) = session_definition.as_mut() {
- if matches!(definition.tools, ToolScope::Named(_)) {
- definition.extra_tools.extend(host_scope_additions);
- definition.extra_tools.sort();
- definition.extra_tools.dedup();
- }
- }
+ let session_definition = super::host_tools::scope_def(target_def, &merged_host_tools);
let host_policy = merged_host_tools.policy;
let withheld_tool_names = merged_host_tools.withheld;
let mut builder = OpenHumanSessionHost::builder()
diff --git a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
index b223fc580c..5fc7876ad8 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
@@ -109,6 +109,7 @@ impl HostTurnTools {
policy: None,
withheld: HashSet::new(),
permanent: HashSet::new(),
+ scope_additions: HashSet::new(),
});
}
log::debug!(
@@ -144,12 +145,14 @@ impl HostTurnTools {
// Filling it with an attached source's names would turn it into a
// literal allowlist and silently discard the native registry.
if !visible.is_empty() {
- visible.extend(self.visible);
+ visible.extend(self.visible.iter().cloned());
}
+ let scope_additions = self.visible.difference(&self.withheld).cloned().collect();
Ok(MergedHostTurnTools {
policy: self.policy,
withheld: self.withheld,
permanent: self.permanent,
+ scope_additions,
})
}
@@ -190,6 +193,25 @@ pub(super) struct MergedHostTurnTools {
pub policy: Option<Arc<dyn ToolPolicy>>,
pub withheld: HashSet<String>,
pub permanent: HashSet<String>,
+ pub scope_additions: HashSet<String>,
+}
+
+pub(super) fn scope_def(
+ definition: Option<&crate::agent::harness::definition::AgentDefinition>,
+ host_tools: &MergedHostTurnTools,
+) -> Option<crate::agent::harness::definition::AgentDefinition> {
+ let mut definition = definition.cloned()?;
+ if matches!(
+ definition.tools,
+ crate::agent::harness::definition::ToolScope::Named(_)
+ ) {
+ definition
+ .extra_tools
+ .extend(host_tools.scope_additions.iter().cloned());
+ definition.extra_tools.sort();
+ definition.extra_tools.dedup();
+ }
+ Some(definition)
}
pub(super) fn merge_for_turn(
@@ -208,6 +230,7 @@ pub(super) fn merge_for_turn(
policy: None,
withheld: HashSet::new(),
permanent: HashSet::new(),
+ scope_additions: HashSet::new(),
}),
}
}
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index f7ac17d052..ae041f30b4 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -43,7 +43,7 @@ const LEGACY_LIMIT_ENTRIES = [
// provider, security, memory, tool and prompt policy. Generic session
// state moved to tinyagents-runtime; this remaining composition is split in
// a follow-up without reintroducing an old harness/session exception.
- ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 1004],
+ ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 1003],
["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1309],
["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1152],
["crates/openhuman-core/src/tools/ops.rs", 1209],