Skip to content

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

refactor(session_host): extract profile agent factory into its own module

Steven Enamakel761bb234426f
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 596198b53e..0a2924c8a2 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -78,24 +78,9 @@ impl OpenHumanSessionHost {
/// The welcome agent uses this entry point when routed from the
/// Tauri web channel (see `channels::provider::web::build_session_agent`).
pub fn from_config_for_agent(config: &Config, agent_id: &str) -> Result<Self> {
- Self::from_config_for_agent_session(config, agent_id, None)
- }
-
- /// Build a config-routed agent with its caller's exact conversation key.
- ///
- /// # Errors
- /// As [`Self::from_config_for_agent`].
- pub fn from_config_for_agent_session(
- config: &Config,
- agent_id: &str,
- session_id: Option<&str>,
- ) -> Result<Self> {
- // Look up the target definition up front so we can fail fast
- // with a clear error instead of building half an agent and then
- // discovering the id is unknown. See `resolve_target_definition`
- // for the full resolution order (harness registry, then the
- // config-backed custom agent registry, then the orchestrator's
- // legacy pre-startup fallback).
+ if crate::profiles::capabilities::ProfileCapabilities::current().is_some() {
+ return Self::from_config_for_agent_session(config, agent_id, None);
+ }
let target_def = resolve_target_definition(config, agent_id)?;
log::info!(
@@ -123,20 +108,7 @@ impl OpenHumanSessionHost {
.unwrap_or(config.default_temperature)
);
- if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::current() {
- let definition = target_def
- .ok_or_else(|| anyhow::anyhow!("profile agent definition is unavailable"))?;
- let factory = capabilities.factory(config);
- return Self::from_config_host_only(config, &definition, Some(&factory), session_id);
- }
- Self::build_session_agent_inner(
- config,
- agent_id,
- target_def.as_ref(),
- false,
- None,
- session_id,
- )
+ Self::build_session_agent_inner(config, agent_id, target_def.as_ref(), false, None, None)
}
/// Build a session agent from a definition the caller already holds,
@@ -901,7 +873,7 @@ impl OpenHumanSessionHost {
/// Any other id that resolves nowhere is a hard error, exactly as before this
/// function existed — only the *search order* changed, not the failure
/// contract for a genuinely-unknown id.
-fn resolve_target_definition(
+pub(super) fn resolve_target_definition(
config: &Config,
agent_id: &str,
) -> Result<Option<crate::agent::harness::definition::AgentDefinition>> {
diff --git a/crates/openhuman-core/src/agent/session_host/builder/mod.rs b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
index efeb84fe1f..9e7712013b 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
@@ -16,6 +16,7 @@ mod host_only;
mod host_tools;
mod iteration_cap;
mod permanent_tool;
+mod profile_factory;
mod setters;
pub use host_only::HostOnlyToolPolicy;
diff --git a/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs b/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
new file mode 100644
index 0000000000..c4a0f2e45a
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
@@ -0,0 +1,26 @@
+//! Profile session construction carries the caller's exact conversation key.
+
+use crate::agent::OpenHumanSessionHost;
+use crate::config::Config;
+
+impl OpenHumanSessionHost {
+ /// Build a config-routed agent with its caller's exact conversation key.
+ /// Profile capabilities are fixed by the operator and narrowed before
+ /// host-only session registration. Ordinary config agents keep their belt.
+ ///
+ /// # Errors
+ /// As [`Self::from_config_for_agent`], or when a profile has no definition.
+ pub fn from_config_for_agent_session(
+ config: &Config,
+ agent_id: &str,
+ session_id: Option<&str>,
+ ) -> anyhow::Result<Self> {
+ if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::current() {
+ let definition = super::factory::resolve_target_definition(config, agent_id)?
+ .ok_or_else(|| anyhow::anyhow!("profile agent definition is unavailable"))?;
+ let factory = capabilities.factory(config);
+ return Self::from_config_host_only(config, &definition, Some(&factory), session_id);
+ }
+ Self::from_config_for_agent(config, agent_id)
+ }
+}