The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(embed): give an agent sub-agents of its own and reserve the built-in ids (#7032)
oxoxDevd1149cbf788e
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rsindex 24f57c4865..2d53c0ac4d 100644--- a/crates/openhuman-embed/src/agent/build.rs+++ b/crates/openhuman-embed/src/agent/build.rs@@ -7,6 +7,9 @@use std::path::Path;+use openhuman_core::agent::harness::definition::{+ AgentDefinition, AgentDefinitionRegistry, SubagentEntry,+};use openhuman_core::core::all::DomainGroup;use openhuman_core::core::runtime::{ContextOverlay, DomainSet};use openhuman_core::tools::toolpacks::{GroupMode, ToolGroups};@@ -21,6 +24,10 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInnid: id.clone(),reason,})?;+ let catalogue = process_catalogue();+ if catalogue.get(&id).is_some() {+ return Err(AgentError::ReservedId(id));+ }let base = runtime.base_config();let root_dir = base@@ -129,7 +136,6 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn}// ── definition ───────────────────────────────────────────────────────- #[cfg_attr(not(feature = "mcp"), allow(unused_mut))]let mut definition = parts.definition.into_core(&id)?;// Every declared server's tools are registered as their own// `mcp_<server>_<tool>`, deferred by default. A wildcard belt reaches them@@ -140,6 +146,8 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInnopt_named_belt_into_discovery(&mut definition.tools);}+ let definitions = own_catalogue(&catalogue, &id, &mut definition, parts.subagents)?;+// ── narrowing ────────────────────────────────────────────────────────let domains = match parts.domains {Some(requested) => {@@ -173,7 +181,7 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn.with_privacy_mode(config.privacy.mode),)),approvals_disabled: !access.approval_gate_enabled(),- definitions: None,+ definitions,};let ctx = runtime.core_runtime().context().derive_with(overlay);openhuman_core::core::runtime::AgentContextRegistry::register(&id, &ctx);@@ -205,6 +213,51 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn})}+/// The process catalogue: the booted registry, or the built-ins when none+/// was initialised.+fn process_catalogue() -> std::sync::Arc<AgentDefinitionRegistry> {+ AgentDefinitionRegistry::global_arc()+ .unwrap_or_else(|| std::sync::Arc::new(AgentDefinitionRegistry::builtins_only()))+}++/// The catalogue an agent with its own sub-agents delegates through: the+/// process catalogue plus the agent and its sub-agents. `None` (resolve+/// through the process catalogue) for an agent without sub-agents.+fn own_catalogue(+ catalogue: &AgentDefinitionRegistry,+ id: &str,+ definition: &mut AgentDefinition,+ subagents: Vec<(String, super::AgentDefinitionSpec)>,+) -> Result<Option<std::sync::Arc<AgentDefinitionRegistry>>, AgentError> {+ if subagents.is_empty() {+ return Ok(None);+ }+ let mut own = Vec::with_capacity(subagents.len() + 1);+ let mut seen = std::collections::HashSet::new();+ for (sub_id, spec) in subagents {+ validate_agent_id(&sub_id).map_err(|reason| AgentError::InvalidId {+ id: sub_id.clone(),+ reason,+ })?;+ if catalogue.get(&sub_id).is_some() {+ return Err(AgentError::ReservedId(sub_id));+ }+ if sub_id == id || !seen.insert(sub_id.clone()) {+ return Err(AgentError::DuplicateId(sub_id));+ }+ definition+ .subagents+ .push(SubagentEntry::AgentId(sub_id.clone()));+ own.push(spec.into_subagent_core(&sub_id)?);+ }+ own.push(definition.clone());+ log::debug!(+ "[embed][agent] id={id} owns a catalogue with {} sub-agent(s)",+ own.len() - 1+ );+ Ok(Some(std::sync::Arc::new(catalogue.with_definitions(own))))+}+/// Adds `tool_search` to a named belt that lacks it. A wildcard belt already/// has discovery.#[cfg(feature = "mcp")]diff --git a/crates/openhuman-embed/src/agent/definition.rs b/crates/openhuman-embed/src/agent/definition.rsindex c748e2b38b..06c6c6fab5 100644--- a/crates/openhuman-embed/src/agent/definition.rs+++ b/crates/openhuman-embed/src/agent/definition.rs@@ -159,6 +159,19 @@ impl AgentDefinitionSpec {}}+impl AgentDefinitionSpec {+ /// Materialize this spec as a worker sub-agent named `id`: it executes+ /// and delegates nothing further.+ pub(crate) fn into_subagent_core(self, id: &str) -> Result<AgentDefinition, AgentError> {+ let mut def = self.into_core(id)?;+ def.agent_tier = openhuman_core::agent::harness::definition::AgentTier::Worker;+ def.subagents.clear();+ def.delegate_name = None;+ def.searches_connected_mcp = false;+ Ok(def)+ }+}+/// The built-in definition every embedded agent starts from.const ORCHESTRATOR_ID: &str = "orchestrator";diff --git a/crates/openhuman-embed/src/agent/mod.rs b/crates/openhuman-embed/src/agent/mod.rsindex 591beeba8d..8d2969d75e 100644--- a/crates/openhuman-embed/src/agent/mod.rs+++ b/crates/openhuman-embed/src/agent/mod.rs@@ -76,6 +76,11 @@ pub enum AgentError {/// A spec input could not be honoured.#[error("{0}")]Invalid(String),++ /// The id names a built-in agent definition (`orchestrator`, `planner`,+ /// …), which the delegation catalogue would resolve instead of this agent.+ #[error("agent id {0:?} is reserved for a built-in agent definition")]+ ReservedId(String),}/// The assembled state behind an [`Agent`], shared by every clone of it anddiff --git a/crates/openhuman-embed/src/agent/spec.rs b/crates/openhuman-embed/src/agent/spec.rsindex 7c2db70fa3..edc1d3c512 100644--- a/crates/openhuman-embed/src/agent/spec.rs+++ b/crates/openhuman-embed/src/agent/spec.rs@@ -52,6 +52,7 @@ pub struct AgentSpec {config_fn: Option<ConfigEdit>,host_tools: Option<openhuman_core::agent::HostTools>,memory: Option<MemoryBinding>,+ subagents: Vec<(String, AgentDefinitionSpec)>,}/// Whose memory an agent reads and writes: the memory agent id its turns are@@ -101,9 +102,9 @@ impl AgentSpec {////// The id must match `^[a-z0-9][a-z0-9_-]{0,63}$` (checked at/// [`Runtime::agent`](crate::Runtime::agent)); it names the agent's- /// directories and transcripts. Avoid the built-in ids (`orchestrator`,- /// `summarizer`, …): the runtime-wide delegation catalog resolves those- /// to the shipped definitions.+ /// directories and transcripts. The built-in ids (`orchestrator`,+ /// `summarizer`, …) are reserved for the shipped definitions and refused+ /// with [`AgentError::ReservedId`](crate::AgentError::ReservedId).pub fn new(id: impl Into<String>) -> Self {Self {id: id.into(),@@ -125,6 +126,7 @@ impl AgentSpec {config_fn: None,host_tools: None,memory: None,+ subagents: Vec::new(),}}@@ -254,6 +256,21 @@ impl AgentSpec {self}+ /// Sub-agents only this agent can delegate to, each under its own id.+ ///+ /// Each becomes a `delegate_<id>` tool on this agent and a worker in this+ /// agent's own catalogue; other agents on the runtime never see it. Ids+ /// follow the agent-id rules and must not name a built-in definition.+ pub fn subagents<I, S>(mut self, subagents: I) -> Self+ where+ I: IntoIterator<Item = (S, AgentDefinitionSpec)>,+ S: Into<String>,+ {+ self.subagents+ .extend(subagents.into_iter().map(|(id, spec)| (id.into(), spec)));+ self+ }+/// Arbitrary edits to the agent's config, applied last.////// The escape hatch for the config fields the spec does not model — not@@ -359,6 +376,7 @@ impl AgentSpec {config_fn: self.config_fn,host_tools: self.host_tools,memory: self.memory,+ subagents: self.subagents,}}}@@ -384,6 +402,7 @@ pub(crate) struct AgentSpecParts {pub(crate) config_fn: Option<ConfigEdit>,pub(crate) host_tools: Option<openhuman_core::agent::HostTools>,pub(crate) memory: Option<MemoryBinding>,+ pub(crate) subagents: Vec<(String, AgentDefinitionSpec)>,}impl std::fmt::Debug for AgentSpec {diff --git a/crates/openhuman-embed/src/harness/error.rs b/crates/openhuman-embed/src/harness/error.rsindex 0eefb76112..fdbbdf80c4 100644--- a/crates/openhuman-embed/src/harness/error.rs+++ b/crates/openhuman-embed/src/harness/error.rs@@ -88,7 +88,7 @@ impl From<crate::AgentError> for HarnessError {match err {A::Call(e) => Self::Call(e),A::Workspace { what, source } => Self::Workspace { what, source },- A::DuplicateId(_) | A::InvalidId { .. } | A::WidensRuntime(_) => {+ A::DuplicateId(_) | A::InvalidId { .. } | A::WidensRuntime(_) | A::ReservedId(_) => {Self::Invalid(err_text(&err))}A::Invalid(msg) => Self::Invalid(msg),