Skip to content

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

refactor(agent): resolve delegation targets from host extensions

Steven Enamakel2b62665e3b4a
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
index e0e13443ce..392778253d 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
@@ -3,7 +3,6 @@
use crate::agent::subagent_host::{
run_subagent_via_driver_tool, SubagentRunOptions, SubagentRunStatus,
};
-use crate::agent_registry::host_definition::AgentDefinitionRegistry;
use crate::progress::AgentProgress;
use async_trait::async_trait;
use std::sync::Arc;
@@ -30,11 +29,14 @@ enum DelegationDispatchKind {
Collapsed {
targets: Result<Vec<super::collapsed_delegation::DelegateTarget>, String>,
},
- Archetype,
+ Archetype { agent_id: String },
}
impl DelegationDispatch {
- pub(crate) fn for_tool(tool: Arc<dyn tinytools::Tool>) -> Option<Self> {
+ pub(crate) fn for_tool(
+ tool: Arc<dyn tinytools::Tool>,
+ delegation_target: Option<String>,
+ ) -> Option<Self> {
let kind = match tool.name() {
super::collapsed_delegation::DELEGATE_TO_TOOL_NAME => {
DelegationDispatchKind::Collapsed {
@@ -43,22 +45,13 @@ impl DelegationDispatch {
),
}
}
- // Only synthesized archetype delegate names enter this path.
- // `delegate_graph` is a concrete durable graph tool with its own
- // typed dispatcher, and arbitrary `delegate_*` tools must not be
- // mistaken for an agent target merely because of their spelling.
- name if AgentDefinitionRegistry::current().is_some_and(|registry| {
- registry.list().into_iter().any(|definition| {
- definition
- .delegate_name
- .clone()
- .unwrap_or_else(|| format!("delegate_{}", definition.id))
- == name
- })
- }) =>
- {
- DelegationDispatchKind::Archetype
- }
+ // The target is carried by the registered host extension, not
+ // inferred from an ambient registry or a tool's spelling. This
+ // keeps hidden packed delegates scoped to the catalogue that
+ // actually supplied them.
+ _ if delegation_target.is_some() => DelegationDispatchKind::Archetype {
+ agent_id: delegation_target.expect("checked above"),
+ },
_ => return None,
};
Some(Self { tool, kind })
@@ -105,26 +98,9 @@ impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext> for D
)
.await
}
- DelegationDispatchKind::Archetype => {
- let Some(agent_id) = AgentDefinitionRegistry::for_core_context(
- parent.data.dispatch_ctx().into_core(),
- )
- .and_then(|registry| {
- registry.list().into_iter().find_map(|definition| {
- let name = definition
- .delegate_name
- .clone()
- .unwrap_or_else(|| format!("delegate_{}", definition.id));
- (name == self.tool.name()).then_some(definition.id.clone())
- })
- }) else {
- return Ok(ToolResult::error(format!(
- "{}: delegation target is not registered",
- self.tool.name()
- )));
- };
+ DelegationDispatchKind::Archetype { agent_id } => {
super::archetype_delegation::execute_archetype_delegation_with_live_parent(
- &agent_id,
+ agent_id,
self.tool.name(),
arguments,
Some(&tool_context),
diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
index e90215e095..ce9be26a11 100644
--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
@@ -107,6 +107,7 @@ type ToolDispatchSelector = Arc<ToolDispatchSelectorFn>;
pub(crate) fn typed_dispatch_for(
name: &str,
adapter: Arc<dyn tinytools::Tool>,
+ delegation_target: Option<String>,
) -> Option<Arc<dyn ToolDispatch<(), OpenHumanRunContext>>> {
let dispatch: Arc<dyn ToolDispatch<(), OpenHumanRunContext>> = match name {
"spawn_parallel_agents" => Arc::new(SpawnParallelAgentsDispatch::new(adapter)),
@@ -123,7 +124,7 @@ pub(crate) fn typed_dispatch_for(
"memory" => Arc::new(LiveToolContextDispatch::new(adapter)),
"todo" => Arc::new(TodoToolDispatch::new(adapter)),
_ => {
- return DelegationDispatch::for_tool(adapter).map(|dispatch| {
+ return DelegationDispatch::for_tool(adapter, delegation_target).map(|dispatch| {
Arc::new(dispatch) as Arc<dyn ToolDispatch<(), OpenHumanRunContext>>
});
}
@@ -339,7 +340,13 @@ type DispatchSelector = Arc<
fn dispatch_selector(tool_sets: Vec<SharedToolSet>) -> DispatchSelector {
Arc::new(move |name, adapter| {
if name != USE_SKILL {
- return typed_dispatch_for(name, adapter);
+ let delegation_target = tool_sets
+ .iter()
+ .flat_map(|set| set.iter())
+ .find(|tool| tool.name() == name)
+ .and_then(|tool| crate::tools::host_extensions::delegation_target(tool.as_ref()))
+ .map(str::to_string);
+ return typed_dispatch_for(name, adapter, delegation_target);
}
// The pack-registry handle comes off the raw registered tool, not the
// adapter.
diff --git a/crates/openhuman-core/src/agent/tinyagents/use_skill_dispatch.rs b/crates/openhuman-core/src/agent/tinyagents/use_skill_dispatch.rs
index 2680a01bec..202d90a14f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/use_skill_dispatch.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/use_skill_dispatch.rs
@@ -112,7 +112,12 @@ impl ToolDispatch<(), OpenHumanRunContext> for UseSkillDispatch {
answer: Some(result),
})));
};
- let typed = typed_dispatch_for(name, inner_adapter.clone());
+ let delegation_target = tools
+ .iter()
+ .find(|tool| tool.name() == name)
+ .and_then(|tool| crate::tools::host_extensions::delegation_target(tool.as_ref()))
+ .map(str::to_string);
+ let typed = typed_dispatch_for(name, inner_adapter.clone(), delegation_target);
Ok(Some(Arc::new(BoundUseSkillDispatch {
outer: self.tool.clone(),
inner: Some(inner_adapter),
@@ -175,7 +180,12 @@ impl ToolDispatch<(), OpenHumanRunContext> for UseSkillDispatch {
.await;
};
- if let Some(dispatch) = typed_dispatch_for(&name, inner_adapter.clone()) {
+ let delegation_target = tools
+ .iter()
+ .find(|tool| tool.name() == name)
+ .and_then(|tool| crate::tools::host_extensions::delegation_target(tool.as_ref()))
+ .map(str::to_string);
+ if let Some(dispatch) = typed_dispatch_for(&name, inner_adapter.clone(), delegation_target) {
return dispatch
.execute(&(), call_id, inner_args, options, parent)
.await;