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
refactor(tinyagents): extract tool admission and registration into runtime helpers
Steven Enamakeld7ce6239421f
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rsindex e547186023..119114887f 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs@@ -9,6 +9,9 @@ use std::sync::Arc;use tinyagents_graph::goals::GoalToolKind;use tinyagents_harness::runtime::AgentHarness;use tinyagents_harness::tool::ToolDispatch;+use tinyagents_runtime::{+ project_descriptors, register_admitted_projected, ToolAdmission, ToolRegistration,+};use tinyagents_registry::{CapabilityRegistry, ComponentKind, RegistryDiagnostic, RegistrySnapshot,};@@ -65,6 +68,16 @@ pub(crate) fn typed_dispatch_for(Some(dispatch)}+/// Names among the candidate tools that spawn or delegate to a sub-agent.+fn candidate_spawn_tools(tool_sets: &[Arc<Vec<Box<dyn tinytools::Tool>>>]) -> HashSet<String> {+ tool_sets+ .iter()+ .flat_map(|set| set.iter())+ .map(|tool| tool.name().to_string())+ .filter(|name| is_subagent_spawn_or_delegate_tool(name))+ .collect()+}+/// Whether `name` is one of the model-facing per-thread goal tools/// (`goal_get` / `goal_set` / `goal_complete`), named by their owner.pub(crate) fn is_thread_goal_tool(name: &str) -> bool {@@ -114,99 +127,78 @@ pub(super) fn register_turn_tools_and_agents();}}- let mut seen_candidates: HashSet<String> = HashSet::new();- let candidate_names: Vec<String> = tool_sets+ let admission = ToolAdmission {+ allowed: allowed.clone(),+ is_subagent_run,+ has_thread,+ // The per-thread goal tools resolve their target from the run's thread+ // and refuse every call without one, so a thread-less turn is not+ // offered them (issue #6956).+ thread_scoped: GoalToolKind::MODEL_FACING+ .iter()+ .map(|kind| kind.name().to_string())+ .collect(),+ spawn_tools: candidate_spawn_tools(tool_sets),+ };+ let names: Vec<String> = tool_sets.iter().flat_map(|set| set.iter())- .map(|tool| tool.name())- .filter(|&name| seen_candidates.insert(name.to_string()))- // The per-thread goal tools resolve their target from the run's thread- // and refuse every call without one ("thread goal tools require an- // active chat thread"), so a thread-less turn is not offered them- // (issue #6956). Dropped as candidates, not just at registration, so- // the shadow exposure layer's reference matches what registers.- .filter(|&name| {- let keep = has_thread || !is_thread_goal_tool(name);- if !keep {- tracing::debug!(- tool = name,- "[goals] not registering thread goal tool on a turn without a chat thread"- );- }- keep- })- .map(|name| name.to_string())+ .map(|tool| tool.name().to_string()).collect();- let mut registered: HashSet<String> = HashSet::new();- for name in candidate_names.iter().map(String::as_str) {- // Fail-closed allowlist: `None` admits everything, `Some(set)` admits only- // its members (empty set → nothing).- let admitted = match allowed {- None => true,- Some(set) => set.contains(name),- };- // Defense-in-depth (issue #4452): a sub-agent must NEVER be handed a- // spawn/delegate tool whatever the allowlist says — re-assert it here at- // registration, not just on the caller's `allowed_indices`. Warn only when- // the allowlist actually readmitted one (issue #6157); the caller strips- // them first, so a bare `spawn_stripped` warn fired on every healthy run.- let spawn_stripped = is_subagent_run && is_subagent_spawn_or_delegate_tool(name);- if spawn_stripped && admitted {- tracing::warn!(- tool = name,- "[subagent] refusing to register spawn/delegate tool on sub-agent run"- );- }- if !registered.contains(name) && admitted && !spawn_stripped {- if let Some(mut adapter) =- CanonicalSharedToolAdapter::for_name(tool_sets.to_vec(), name)- {- if early_exit_set.contains(name) {- if let Some(hook) = early_exit_hook {- adapter = adapter.with_early_exit(hook.clone());- }- }- if session_deferred.contains(name) {- adapter = adapter.deferred();- }- registered.insert(name.to_string());- let adapter = Arc::new(adapter);- capability_registry.replace_tool(adapter.clone());- if name == USE_SKILL {- // `use_skill` needs its own typed dispatch (regression- // R3): it is the proxy every packed archetype delegation- // (`create_image`, `do_crypto`, `make_presentation`, …)- // is reached through, and it must resolve the SAME live- // parent `typed_dispatch_for` gives a natively advertised- // delegate tool. The pack-registry handle comes off the- // raw registered tool (not this adapter, which has no- // erased host extension of its own).- let handle = tool_sets- .iter()- .flat_map(|set| set.iter())- .find(|tool| tool.name() == name)- .and_then(|tool| {- crate::tools::host_extensions::pack_registry_handle(tool.as_ref())- })- .cloned();- match handle {- Some(handle) => harness.register_tool_dispatch(Arc::new(- UseSkillDispatch::new(adapter, handle),- )),- None => harness.register_tool(adapter),- };- } else if let Some(dispatch) = typed_dispatch_for(name, adapter.clone()) {- harness.register_tool_dispatch(dispatch);- } else {- harness.register_tool(adapter);+ let (tool_count, plan) = register_admitted_projected(+ harness,+ capability_registry,+ names,+ &admission,+ |name| {+ let mut adapter = CanonicalSharedToolAdapter::for_name(tool_sets.to_vec(), name)?;+ if early_exit_set.contains(name) {+ if let Some(hook) = early_exit_hook {+ adapter = adapter.with_early_exit(hook.clone());}}- }- }- let tool_count = registered.len();- for report in tinyagents_orchestration::topology::all_graph_topologies() {- let _ = capability_registry.register_descriptor(ComponentKind::Graph, report.name);- }+ if session_deferred.contains(name) {+ adapter = adapter.deferred();+ }+ let adapter = Arc::new(adapter);+ let view: Arc<dyn tinytools::Tool> = adapter.clone();+ let registration = if name == USE_SKILL {+ // `use_skill` needs its own typed dispatch (regression R3): it+ // is the proxy every packed archetype delegation is reached+ // through, and it must resolve the SAME live parent+ // `typed_dispatch_for` gives a natively advertised delegate+ // tool. The pack-registry handle comes off the raw registered+ // tool, not this adapter.+ let handle = tool_sets+ .iter()+ .flat_map(|set| set.iter())+ .find(|tool| tool.name() == name)+ .and_then(|tool| {+ crate::tools::host_extensions::pack_registry_handle(tool.as_ref())+ })+ .cloned();+ match handle {+ Some(handle) => ToolRegistration::Dispatch(Arc::new(UseSkillDispatch::new(+ adapter, handle,+ ))),+ None => ToolRegistration::Tool(adapter),+ }+ } else if let Some(dispatch) = typed_dispatch_for(name, adapter.clone()) {+ ToolRegistration::Dispatch(dispatch)+ } else {+ ToolRegistration::Tool(adapter)+ };+ Some((view, registration))+ },+ );+ let candidate_names = plan.candidates;+ project_descriptors(+ capability_registry,+ ComponentKind::Graph,+ tinyagents_orchestration::topology::all_graph_topologies()+ .into_iter()+ .map(|report| report.name),+ );// Project the agents visible to this turn into the registry as name-only// `ComponentKind::Agent` descriptors (issue #4249, Workstream 10.1). This is