Skip to content

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

fix(agent): handle missing spec test file gracefully

Steven Enamakelc1443fa8348e
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
new file mode 100644
index 0000000000..84cfaf8e81
--- /dev/null
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -0,0 +1,216 @@
+//! Turning an [`AgentSpec`] into an [`AgentInner`] on a [`Runtime`].
+//!
+//! Order matters and is fixed here: validate the id, lay out directories,
+//! assemble the per-agent `Config` (base → access → provider → MCP → escape
+//! hatch), build the profile and definition, copy skills, check the
+//! narrowing rules, derive the context.
+
+use std::path::Path;
+
+use openhuman_core::agent::profiles::{ensure_profile_home, validate_profile_id};
+use openhuman_core::core::all::DomainGroup;
+use openhuman_core::core::runtime::{ContextOverlay, DomainSet};
+use openhuman_core::tools::toolpacks::{GroupMode, ToolGroups};
+
+use super::{AgentError, AgentInner, AgentLayout, AgentSpec};
+use crate::harness::Provider;
+use crate::runtime::Runtime;
+
+pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInner, AgentError> {
+ let parts = spec.into_parts();
+ let id = parts.id;
+ validate_profile_id(&id).map_err(|reason| AgentError::InvalidId {
+ id: id.clone(),
+ reason,
+ })?;
+
+ let base = runtime.base_config();
+ let root_dir = base
+ .config_path
+ .parent()
+ .map(Path::to_path_buf)
+ .unwrap_or_default();
+
+ // ── config ───────────────────────────────────────────────────────────
+ let mut config = base.clone();
+ let action_dir = parts.action_dir.unwrap_or_else(|| {
+ AgentLayout::default_action_dir(
+ &root_dir,
+ &base.action_dir,
+ runtime.inherited_workspace(),
+ &id,
+ )
+ });
+ std::fs::create_dir_all(&action_dir).map_err(|source| AgentError::Workspace {
+ what: "create the agent's action directory",
+ source,
+ })?;
+ config.action_dir = action_dir.clone();
+
+ let mut access = parts
+ .access
+ .unwrap_or_else(|| runtime.default_access().clone());
+ for (path, grant) in parts.trusted {
+ access = access.trust(path, grant);
+ }
+ access.apply(&mut config);
+
+ let provider = parts
+ .provider
+ .unwrap_or_else(|| runtime.default_provider().clone());
+ crate::runtime::builder::apply_provider(&mut config, &provider);
+
+ #[cfg(feature = "mcp")]
+ if !parts.mcp_servers.is_empty() {
+ config.mcp_client.enabled = true;
+ config.mcp_client.servers.extend(
+ parts
+ .mcp_servers
+ .iter()
+ .cloned()
+ .map(crate::harness::McpServer::into_config),
+ );
+ }
+
+ if let Some(f) = parts.config_fn {
+ f(&mut config);
+ // Every agent shares the runtime's credential store and keyring; a
+ // moved `config_path` would silently point this agent at another.
+ config.config_path = base.config_path.clone();
+ }
+
+ // ── profile ──────────────────────────────────────────────────────────
+ let mut profile = super::spec::blank_profile(&id);
+ profile.dedicated_memory = !parts.shared_memory;
+ profile.allowed_tools = parts.allowed_tools;
+ profile.allowed_skills = parts.allowed_skills;
+ profile.system_prompt_suffix = parts.system_prompt_suffix;
+ #[cfg(feature = "mcp")]
+ {
+ profile.allowed_mcp_servers = None;
+ }
+ ensure_profile_home(&config.workspace_dir, &config.action_dir, &profile).map_err(
+ |source| AgentError::Workspace {
+ what: "create the agent's profile home",
+ source,
+ },
+ )?;
+ let layout = AgentLayout::resolve(&config.workspace_dir, &profile, action_dir);
+
+ // ── skills ───────────────────────────────────────────────────────────
+ #[cfg(feature = "skills")]
+ if let Some(dir) = parts.skills_dir.as_deref() {
+ let dest = match parts.skills_dest {
+ super::spec::SkillsDest::ProfileLocal => layout.skills.clone(),
+ super::spec::SkillsDest::WorkspaceLegacy => config.workspace_dir.join("skills"),
+ };
+ crate::harness::skills::install(dir, &dest).map_err(map_harness_err)?;
+ }
+
+ // ── definition ───────────────────────────────────────────────────────
+ let definition = parts.definition.into_core(&id)?;
+
+ // ── narrowing ────────────────────────────────────────────────────────
+ let domains = match parts.domains {
+ Some(requested) => {
+ check_domains_narrow(requested, runtime.domains())?;
+ requested
+ }
+ None => runtime.domains(),
+ };
+ let tool_groups = match parts.tool_groups {
+ Some(requested) => {
+ check_tool_groups_narrow(&requested, runtime.tool_groups())?;
+ requested
+ }
+ None => runtime.tool_groups().clone(),
+ };
+
+ // ── context ──────────────────────────────────────────────────────────
+ let overlay = ContextOverlay {
+ config: config.clone(),
+ domains,
+ tool_groups,
+ user_skill_roots: parts.include_user_skills,
+ };
+ let ctx = runtime.core_runtime().context().derive_with(overlay);
+
+ log::debug!(
+ "[embed][agent] instantiated id={id} action_dir={} routed={} access_origin={} \
+ dedicated_memory={} user_skills={}",
+ config.action_dir.display(),
+ provider.is_routed(),
+ access.turn_origin().is_some(),
+ profile.dedicated_memory,
+ parts.include_user_skills
+ );
+
+ Ok(AgentInner {
+ id,
+ runtime: runtime.core_runtime().clone(),
+ ctx,
+ config,
+ definition,
+ profile,
+ provider: normalize_provider(provider),
+ access,
+ layout,
+ })
+}
+
+fn normalize_provider(provider: Provider) -> Provider {
+ provider
+}
+
+/// Every family the agent asks for must be one the runtime registered.
+pub(crate) fn check_domains_narrow(requested: DomainSet, runtime: DomainSet) -> Result<(), AgentError> {
+ let widened: Vec<String> = DomainGroup::ALL
+ .iter()
+ .filter(|group| requested.allows(**group) && !runtime.allows(**group))
+ .map(|group| format!("{group:?}").to_lowercase())
+ .collect();
+ if widened.is_empty() {
+ Ok(())
+ } else {
+ Err(AgentError::WidensRuntime(format!(
+ "domain families not registered by the runtime: {}",
+ widened.join(", ")
+ )))
+ }
+}
+
+/// A group may only be as exposed as the runtime exposes it:
+/// `Off` ⊂ `Withheld` ⊂ `Advertised`.
+pub(crate) fn check_tool_groups_narrow(
+ requested: &ToolGroups,
+ runtime: &ToolGroups,
+) -> Result<(), AgentError> {
+ fn exposure(mode: GroupMode) -> u8 {
+ match mode {
+ GroupMode::Off => 0,
+ GroupMode::Withheld => 1,
+ GroupMode::Advertised => 2,
+ }
+ }
+ let widened: Vec<&str> = ToolGroups::ids()
+ .filter(|id| exposure(requested.mode(id)) > exposure(runtime.mode(id)))
+ .collect();
+ if widened.is_empty() {
+ Ok(())
+ } else {
+ Err(AgentError::WidensRuntime(format!(
+ "tool groups more exposed than the runtime's: {}",
+ widened.join(", ")
+ )))
+ }
+}
+
+fn map_harness_err(err: crate::HarnessError) -> AgentError {
+ match err {
+ crate::HarnessError::Workspace { what, source } => AgentError::Workspace { what, source },
+ crate::HarnessError::Invalid(msg) => AgentError::Invalid(msg),
+ crate::HarnessError::Call(e) => AgentError::Call(e),
+ crate::HarnessError::Build(e) => AgentError::Invalid(format!("{e:#}")),
+ crate::HarnessError::AlreadyRunning => AgentError::Invalid(err.to_string()),
+ }
+}
diff --git a/crates/openhuman-embed/src/agent/spec_tests.rs b/crates/openhuman-embed/src/agent/spec_tests.rs
new file mode 100644
index 0000000000..7adfaec88a
--- /dev/null
+++ b/crates/openhuman-embed/src/agent/spec_tests.rs
@@ -0,0 +1,52 @@
+use super::*;
+use crate::agent::build::{check_domains_narrow, check_tool_groups_narrow};
+use openhuman_core::tools::toolpacks::GroupMode;
+
+#[test]
+fn model_without_a_route_pins_the_model_on_an_inherited_provider() {
+ let spec = AgentSpec::new("alpha").model("gpt-5");
+ let parts = spec.into_parts();
+ let provider = parts.provider.expect("provider set");
+ assert_eq!(provider.model_id(), Some("gpt-5"));
+ assert!(!provider.is_routed());
+}
+
+#[test]
+fn debug_omits_the_provider_and_closure() {
+ let spec = AgentSpec::new("alpha")
+ .provider(Provider::openai_compatible("https://x.example", "sk-secret"))
+ .config(|_| {});
+ let debug = format!("{spec:?}");
+ assert!(debug.contains("alpha"));
+ assert!(!debug.contains("sk-secret"));
+}
+
+#[test]
+fn domains_may_only_narrow_the_runtime() {
+ let runtime = DomainSet::embedded();
+ assert!(check_domains_narrow(DomainSet::kernel(), runtime).is_ok());
+ let err = check_domains_narrow(DomainSet::full(), runtime).expect_err("widens");
+ assert!(matches!(err, AgentError::WidensRuntime(_)), "{err:?}");
+}
+
+#[test]
+fn tool_groups_may_only_narrow_the_runtime() {
+ let runtime = ToolGroups::default(); // every group withheld
+ assert!(check_tool_groups_narrow(&ToolGroups::none(), &runtime).is_ok());
+ assert!(check_tool_groups_narrow(&ToolGroups::default(), &runtime).is_ok());
+ let Some(id) = ToolGroups::ids().next() else {
+ return; // slim build with no packs: nothing to widen
+ };
+ let widened = ToolGroups::none().with(id, GroupMode::Advertised);
+ let err = check_tool_groups_narrow(&widened, &runtime).expect_err("widens");
+ assert!(matches!(err, AgentError::WidensRuntime(_)), "{err:?}");
+}
+
+#[test]
+fn blank_profile_carries_only_the_id() {
+ let p = blank_profile("alpha");
+ assert_eq!(p.id, "alpha");
+ assert_eq!(p.agent_id, "alpha");
+ assert!(!p.dedicated_memory);
+ assert!(p.allowed_tools.is_none());
+}