Skip to content

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

feat(tinyagents): register harness tools alongside agent tools

Steven Enamakel186304d2bec9
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
deleted file mode 100644
index 81c95a5d70..0000000000
--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
+++ /dev/null
@@ -1,282 +0,0 @@
-//! Tool + agent capability-registry projection for
-//! [`assemble_turn_harness`](super::harness_assembly::assemble_turn_harness):
-//! register every admitted tool onto the harness and project the visible
-//! agent set into the [`CapabilityRegistry`] for the health-diagnostics gate.
-
-use std::collections::HashSet;
-use std::sync::Arc;
-
-use tinyagents_graph::goals::GoalToolKind;
-use tinyagents_harness::runtime::AgentHarness;
-use tinyagents_harness::tool::ToolDispatch;
-use tinyagents_registry::{
- CapabilityRegistry, ComponentKind, RegistryDiagnostic, RegistrySnapshot,
-};
-use tinyagents_runtime::{
- project_descriptors, register_admitted_projected, ToolAdmission, ToolRegistration,
-};
-
-use crate::agent::orchestration::tools::{
- CloseSubagentDispatch, ContinueSubagentDispatch, DelegateGraphDispatch, DelegationDispatch,
- ListSubagentsDispatch, SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch,
- SpawnSubagentDispatch, SpawnWorkerThreadDispatch, SteerSubagentDispatch, WaitSubagentDispatch,
-};
-use crate::agent::tinyagents::host::OpenHumanRunContext;
-use crate::agent::tinyagents::tools::{CanonicalSharedToolAdapter, EarlyExitHook};
-use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;
-use crate::agent::tinyagents::use_skill_dispatch::UseSkillDispatch;
-use crate::agent::tools::{DelegateToolDispatch, TodoToolDispatch};
-use tinyagents_harness::tool::packs::USE_SKILL;
-
-/// Typed-dispatch selection shared by the direct per-turn registration below
-/// and by [`UseSkillDispatch`], which must resolve the SAME live-parent
-/// dispatch for a packed archetype delegation (`create_image`, `do_crypto`,
-/// `make_presentation`, …) reached through `use_skill` instead of natively
-/// advertised (regression R3: `use_skill` used to hand every packed tool to
-/// plain `Tool::execute_with_context`, which has no live parent, so a packed
-/// delegation always failed with "delegation requires a live harness run
-/// context.").
-///
-/// `adapter` is expected to be the same `CanonicalSharedToolAdapter` seam
-/// used at registration: dispatch selection keys off `name` and the tool's
-/// own schema (via [`DelegationDispatch::for_tool`]'s fallback), not object
-/// identity, so a freshly built adapter over the resolved tool's registry
-/// slot is equivalent to the one the harness itself would have registered.
-pub(crate) fn typed_dispatch_for(
- name: &str,
- adapter: Arc<dyn tinytools::Tool>,
-) -> Option<Arc<dyn ToolDispatch<(), OpenHumanRunContext>>> {
- let dispatch: Arc<dyn ToolDispatch<(), OpenHumanRunContext>> = match name {
- "spawn_parallel_agents" => Arc::new(SpawnParallelAgentsDispatch::new(adapter)),
- "spawn_async_subagent" => Arc::new(SpawnAsyncSubagentDispatch::new(adapter)),
- "spawn_worker_thread" => Arc::new(SpawnWorkerThreadDispatch::new(adapter)),
- "spawn_subagent" => Arc::new(SpawnSubagentDispatch::new(adapter)),
- "continue_subagent" => Arc::new(ContinueSubagentDispatch::new(adapter)),
- "wait_subagent" => Arc::new(WaitSubagentDispatch::new(adapter)),
- "steer_subagent" => Arc::new(SteerSubagentDispatch::new(adapter)),
- "close_subagent" => Arc::new(CloseSubagentDispatch::new(adapter)),
- "list_subagents" => Arc::new(ListSubagentsDispatch::new(adapter)),
- "delegate_graph" => Arc::new(DelegateGraphDispatch::new(adapter)),
- "delegate" | "memory" => Arc::new(DelegateToolDispatch::new(adapter)),
- "todo" => Arc::new(TodoToolDispatch::new(adapter)),
- _ => {
- return DelegationDispatch::for_tool(adapter).map(|dispatch| {
- Arc::new(dispatch) as Arc<dyn ToolDispatch<(), OpenHumanRunContext>>
- })
- }
- };
- 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 {
- GoalToolKind::MODEL_FACING
- .iter()
- .any(|kind| kind.name() == name)
-}
-
-/// Register every admitted tool from `tool_sets` onto `harness` (and its
-/// `capability_registry` projection), project the visible agent set as
-/// name-only descriptors, and return `(tool_count, registry_diagnostics,
-/// registry_snapshot)`.
-///
-/// Allowlist semantics are **fail-closed** (issue #4452): `allowed == None` →
-/// no filter, every visible tool registers; `allowed == Some(set)` → register
-/// *exactly* the named tools, so `Some(empty)` denies all. This is what keeps
-/// a deliberately tool-less sub-agent (`ToolScope::Named([])`, a zero-match
-/// `skill_filter`, or a `named` list that resolves to nothing) from silently
-/// inheriting the parent's full tool surface (shell/file-write/spawn) — the
-/// old `allowed.is_empty() || allowed.contains(name)` predicate was
-/// fail-open.
-///
-/// `has_thread == false` drops the per-thread goal tools, which cannot run
-/// without a chat thread (issue #6956).
-#[allow(clippy::too_many_arguments)]
-pub(super) fn register_turn_tools_and_agents(
- harness: &mut AgentHarness<(), OpenHumanRunContext>,
- capability_registry: &mut CapabilityRegistry<()>,
- tool_sets: &[Arc<Vec<Box<dyn tinytools::Tool>>>],
- allowed: &Option<HashSet<String>>,
- early_exit_set: &HashSet<&str>,
- early_exit_hook: Option<&EarlyExitHook>,
- is_subagent_run: bool,
- has_thread: bool,
- session_deferred: &HashSet<String>,
-) -> (
- usize,
- Vec<String>,
- Vec<RegistryDiagnostic>,
- RegistrySnapshot,
-) {
- if let Some(set) = allowed {
- if set.is_empty() {
- tracing::warn!(
- subagent = is_subagent_run,
- "[subagent] tool allowlist resolved empty — registering no tools"
- );
- }
- }
- 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().to_string())
- .collect();
- 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());
- }
- }
- 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
- // metadata only: no executable `HarnessAgent` is attached (sub-agent
- // dispatch still flows through the openhuman sub-agent runner), so the
- // registration is cheap and leaves the turn hot path unchanged. Agents are
- // sourced from BOTH the runtime `AgentDefinitionRegistry` global (built-ins
- // plus any workspace/config custom overrides, already merged by id) AND the
- // `agent_registry` built-in loader, deduped by id — the runtime registry is
- // registered first and wins, since it carries the richer, override-aware
- // `when_to_use`. Registering here keeps the ids in
- // `capability_registry.snapshot()` so the 10.3 `agent.registry_snapshot` RPC
- // and the fail-closed diagnostics (10.2) observe them.
- //
- // DEFERRED (rich metadata): tinyagents 1.3.0 exposes no public API to attach
- // a `ComponentMetadata` description/tags to a name-only descriptor — only
- // `register_agent(Arc<dyn HarnessAgent>)` carries a full executable blueprint
- // we do not have at this layer. Until the crate grows a
- // `register_descriptor_with_meta` (or we thread real `HarnessAgent`s through
- // `assemble_turn_harness`), the `when_to_use` descriptions and
- // `display_name`/`source` tags cannot be persisted onto the snapshot entry;
- // only the ids are projected. The runtime-registry → executable-agent
- // projection (so `register_agent`/`.rag` sub-agent resolution can bind these)
- // remains the deferred follow-up.
- // Runtime registry first: it wins, carrying the override-aware definitions.
- let runtime_ids: Vec<String> =
- crate::agent::harness::host_definition::AgentDefinitionRegistry::current()
- .map(|runtime| runtime.list().iter().map(|def| def.id.clone()).collect())
- .unwrap_or_default();
- let runtime_agent_count =
- project_descriptors(capability_registry, ComponentKind::Agent, runtime_ids);
- // agent_registry built-ins as a supplement/fallback (deduped by id).
- let builtin_supplement_count = match crate::agent::registry::agents::load_builtins() {
- Ok(builtins) => project_descriptors(
- capability_registry,
- ComponentKind::Agent,
- builtins.into_iter().map(|def| def.id),
- ),
- Err(err) => {
- tracing::debug!(
- %err,
- "[registry] agent_registry builtin load failed; \
- registered runtime-registry agents only"
- );
- 0
- }
- };
-
- let registry_diagnostics = capability_registry.diagnostics();
- let registry_snapshot = capability_registry.snapshot();
-
- // Validation/projection pass (issue #4249, Workstream 10.1): exercise the
- // model/tool projection helpers that are slated to eventually replace the
- // live `harness.register_model`/`register_tool` glue. Today they are
- // infallible projections — they cannot themselves surface diagnostics — so
- // invoking them here is a non-fatal cross-check that every registered model
- // and tool projects into a harness registry cleanly. The authoritative,
- // fail-closed health signal stays `capability_registry.diagnostics()`
- // (captured in `registry_diagnostics` above and enforced by 10.2); a benign
- // projection difference must never abort a turn, so nothing here is folded
- // into that stream. The harness is deliberately NOT switched over to these
- // projections yet — that glue swap is explicitly deferred.
- let projected_models = capability_registry.to_model_registry();
- let projected_tools = capability_registry.to_tool_registry::<OpenHumanRunContext>();
- tracing::debug!(
- models = projected_models.names().len(),
- tools = projected_tools.names().len(),
- graphs = capability_registry.names(ComponentKind::Graph).len(),
- agents = runtime_agent_count + builtin_supplement_count,
- runtime_agents = runtime_agent_count,
- builtin_supplement_agents = builtin_supplement_count,
- diagnostics = registry_diagnostics.len(),
- "[registry] per-turn capability projection summary"
- );
-
- (
- tool_count,
- candidate_names,
- registry_diagnostics,
- registry_snapshot,
- )
-}
-
-#[cfg(test)]
-#[path = "harness_tool_registration_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
new file mode 100644
index 0000000000..ba6b52d4f6
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
@@ -0,0 +1,279 @@
+//! Host adapters over the runtime's generic tool registration
+//! ([`tinyagents_runtime::turn_driver::ToolSetBuilder`]): which typed dispatch a
+//! tool needs, the ambient turn-origin scope every tool execution runs in, and
+//! the capability-registry projection behind the fail-closed diagnostics gate.
+
+use std::collections::HashSet;
+use std::sync::Arc;
+
+use tinyagents_graph::goals::GoalToolKind;
+use tinyagents_harness::tool::packs::USE_SKILL;
+use tinyagents_harness::tool::{
+ CanonicalSharedToolAdapter, ToolDispatch, ToolExecScope, ToolExecution, ToolExecutionContext,
+};
+use tinyagents_registry::{CapabilityRegistry, ComponentKind, RegistryDiagnostic};
+use tinyagents_runtime::turn_driver::{SharedToolSet, ToolSetBuilder};
+use tinyagents_runtime::{plan_registration, project_descriptors, ToolAdmission};
+use tinyinference_llm::model::ChatModel;
+use tinytools::ToolRunContext;
+
+use crate::agent::orchestration::tools::{
+ CloseSubagentDispatch, ContinueSubagentDispatch, DelegateGraphDispatch, DelegationDispatch,
+ ListSubagentsDispatch, SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch,
+ SpawnSubagentDispatch, SpawnWorkerThreadDispatch, SteerSubagentDispatch, WaitSubagentDispatch,
+};
+use crate::agent::tinyagents::host::run_context::HostOperationContext;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
+use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;
+use crate::agent::tinyagents::use_skill_dispatch::UseSkillDispatch;
+use crate::agent::tools::{DelegateToolDispatch, TodoToolDispatch};
+use crate::core::runtime::CoreContext;
+
+/// Typed-dispatch selection shared by the direct per-turn registration below
+/// and by [`UseSkillDispatch`], which must resolve the SAME live-parent
+/// dispatch for a packed archetype delegation (`create_image`, `do_crypto`,
+/// `make_presentation`, …) reached through `use_skill` instead of natively
+/// advertised (regression R3: `use_skill` used to hand every packed tool to
+/// plain `Tool::execute_with_context`, which has no live parent, so a packed
+/// delegation always failed with "delegation requires a live harness run
+/// context.").
+///
+/// `adapter` is expected to be the same `CanonicalSharedToolAdapter` seam
+/// used at registration: dispatch selection keys off `name` and the tool's
+/// own schema (via [`DelegationDispatch::for_tool`]'s fallback), not object
+/// identity, so a freshly built adapter over the resolved tool's registry
+/// slot is equivalent to the one the harness itself would have registered.
+pub(crate) fn typed_dispatch_for(
+ name: &str,
+ adapter: Arc<dyn tinytools::Tool>,
+) -> Option<Arc<dyn ToolDispatch<(), OpenHumanRunContext>>> {
+ let dispatch: Arc<dyn ToolDispatch<(), OpenHumanRunContext>> = match name {
+ "spawn_parallel_agents" => Arc::new(SpawnParallelAgentsDispatch::new(adapter)),
+ "spawn_async_subagent" => Arc::new(SpawnAsyncSubagentDispatch::new(adapter)),
+ "spawn_worker_thread" => Arc::new(SpawnWorkerThreadDispatch::new(adapter)),
+ "spawn_subagent" => Arc::new(SpawnSubagentDispatch::new(adapter)),
+ "continue_subagent" => Arc::new(ContinueSubagentDispatch::new(adapter)),
+ "wait_subagent" => Arc::new(WaitSubagentDispatch::new(adapter)),
+ "steer_subagent" => Arc::new(SteerSubagentDispatch::new(adapter)),
+ "close_subagent" => Arc::new(CloseSubagentDispatch::new(adapter)),
+ "list_subagents" => Arc::new(ListSubagentsDispatch::new(adapter)),
+ "delegate_graph" => Arc::new(DelegateGraphDispatch::new(adapter)),
+ "delegate" | "memory" => Arc::new(DelegateToolDispatch::new(adapter)),
+ "todo" => Arc::new(TodoToolDispatch::new(adapter)),
+ _ => {
+ return DelegationDispatch::for_tool(adapter).map(|dispatch| {
+ Arc::new(dispatch) as Arc<dyn ToolDispatch<(), OpenHumanRunContext>>
+ })
+ }
+ };
+ Some(dispatch)
+}
+
+/// Names among the candidate tools that spawn or delegate to a sub-agent.
+fn candidate_spawn_tools(tool_sets: &[SharedToolSet]) -> 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 {
+ GoalToolKind::MODEL_FACING
+ .iter()
+ .any(|kind| kind.name() == name)
+}
+
+/// Runs every tool execution inside the turn's [`AgentTurnOrigin`] scope.
+///
+/// The origin rides the run's typed host operation context; the process-wide
+/// `CoreContext` is re-scoped with it so a tool that asks "who is acting"
+/// answers for this turn and not for whichever turn last set a global.
+///
+/// [`AgentTurnOrigin`]: crate::agent::turn_origin::AgentTurnOrigin
+pub(crate) struct TurnOriginScope;
+
+impl ToolExecScope for TurnOriginScope {
+ fn scope<'a>(
+ &'a self,
+ context: Option<&'a dyn ToolRunContext>,
+ execution: ToolExecution<'a>,
+ ) -> ToolExecution<'a> {
+ let origin = context
+ .and_then(ToolRunContext::host_extension)
+ .and_then(|extension| extension.downcast_ref::<ToolExecutionContext>())
+ .and_then(|context| context.state::<HostOperationContext>())
+ .and_then(|context| context.origin.clone());
+ match (origin, CoreContext::current()) {
+ (Some(origin), Some(core_context)) => Box::pin(
+ CoreContext::scope_with_turn_origin(core_context, Some(origin), execution),
+ ),
+ _ => execution,
+ }
+ }
+}
+
+/// The adapter for tool `name` over `sets`, scoped to the turn origin.
+///
+/// This is the same adapter the registration builds, so a dispatch that
+/// resolves a tool later (`use_skill`) executes it exactly as a natively
+/// registered one.
+pub(crate) fn shared_tool_adapter(
+ sets: Vec<SharedToolSet>,
+ name: &str,
+) -> Option<CanonicalSharedToolAdapter> {
+ Some(
+ CanonicalSharedToolAdapter::for_name(sets, name)?
+ .with_exec_scope(Arc::new(TurnOriginScope)),
+ )
+}
+
+/// Chooses the typed dispatch for a registered tool: `use_skill` gets its own
+/// (it is the proxy every packed archetype delegation is reached through and
+/// must resolve the SAME live parent a natively advertised delegate tool does,
+/// regression R3), everything else goes through [`typed_dispatch_for`].
+fn dispatch_selector(
+ tool_sets: Vec<SharedToolSet>,
+) -> Arc<
+ dyn Fn(&str, Arc<dyn tinytools::Tool>) -> Option<Arc<dyn ToolDispatch<(), OpenHumanRunContext>>>
+ + Send
+ + Sync,
+> {
+ Arc::new(move |name, adapter| {
+ if name != USE_SKILL {
+ return typed_dispatch_for(name, adapter);
+ }
+ // The pack-registry handle comes off the raw registered tool, not the
+ // 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()?;
+ Some(Arc::new(UseSkillDispatch::new(adapter, handle)))
+ })
+}
+
+/// The admission rules for one turn.
+///
+/// Allowlist semantics are **fail-closed** (issue #4452): `None` admits every
+/// visible tool; `Some(set)` admits *exactly* the named tools, so `Some(empty)`
+/// denies all. That keeps a deliberately tool-less sub-agent from silently
+/// inheriting the parent's full tool surface. `has_thread == false` drops the
+/// per-thread goal tools, which cannot run without a chat thread (#6956).
+pub(crate) fn turn_admission(
+ tool_sets: &[SharedToolSet],
+ allowed: &Option<HashSet<String>>,
+ has_thread: bool,
+) -> ToolAdmission {
+ ToolAdmission {
+ allowed: allowed.clone(),
+ // A sub-agent scope on the turn forces this on in the driver.
+ is_subagent_run: false,
+ has_thread,
+ thread_scoped: GoalToolKind::MODEL_FACING
+ .iter()
+ .map(|kind| kind.name().to_string())
+ .collect(),
+ spawn_tools: candidate_spawn_tools(tool_sets),
+ }
+}
+
+/// The host's tool registration: shared sets, fail-closed admission, session
+/// deferral, typed dispatches and the turn-origin execution scope.
+pub(crate) fn host_tool_set_builder(
+ tool_sets: &[SharedToolSet],
+ allowed: &Option<HashSet<String>>,
+ has_thread: bool,
+ session_deferred: &HashSet<String>,
+) -> ToolSetBuilder<(), OpenHumanRunContext> {
+ ToolSetBuilder::new()
+ .sets(tool_sets.iter().cloned())
+ .admission(turn_admission(tool_sets, allowed, has_thread))
+ .deferred(session_deferred.iter().cloned())
+ .dispatch(dispatch_selector(tool_sets.to_vec()))
+ .exec_scope(Arc::new(TurnOriginScope))
+}
+
+/// Projects the turn's models, admitted tools, graph topologies and visible
+/// agents into a [`CapabilityRegistry`] and returns its health diagnostics.
+///
+/// The turn path enforces them fail-closed before the first model dispatch, so
+/// an ambiguous tool surface (a name shared across native/MCP/Composio/generated
+/// tools, a dangling alias) aborts instead of silently resolving to an
+/// unintended component mid-call. The live run keeps using the harness's own
+/// registries; this projection is metadata only.
+pub(crate) fn capability_diagnostics(
+ models: &[(String, Arc<dyn ChatModel<()>>)],
+ tool_sets: &[SharedToolSet],
+ admission: &ToolAdmission,
+) -> Vec<RegistryDiagnostic> {
+ let mut registry: CapabilityRegistry<()> = CapabilityRegistry::new();
+ for (name, model) in models {
+ registry.replace_model(name.as_str(), model.clone());
+ }
+ let names: Vec<String> = tool_sets
+ .iter()
+ .flat_map(|set| set.iter())
+ .map(|tool| tool.name().to_string())
+ .collect();
+ let plan = plan_registration(names, admission);
+ for name in &plan.admitted {
+ if let Some(adapter) = shared_tool_adapter(tool_sets.to_vec(), name) {
+ registry.replace_tool(Arc::new(adapter));
+ }
+ }
+ project_descriptors(
+ &mut registry,
+ ComponentKind::Graph,
+ tinyagents_orchestration::topology::all_graph_topologies()
+ .into_iter()
+ .map(|report| report.name),
+ );
+
+ // The agents visible to this turn, as name-only `ComponentKind::Agent`
+ // descriptors (issue #4249, Workstream 10.1): metadata only, no executable
+ // agent is attached (sub-agent dispatch flows through the OpenHuman
+ // sub-agent runner). Sourced from the runtime `AgentDefinitionRegistry`
+ // (built-ins plus workspace/config overrides, already merged by id) first,
+ // then the `agent_registry` built-in loader, deduped by id.
+ let runtime_ids: Vec<String> =
+ crate::agent::harness::host_definition::AgentDefinitionRegistry::current()
+ .map(|runtime| runtime.list().iter().map(|def| def.id.clone()).collect())
+ .unwrap_or_default();
+ let runtime_agent_count = project_descriptors(&mut registry, ComponentKind::Agent, runtime_ids);
+ let builtin_supplement_count = match crate::agent::registry::agents::load_builtins() {
+ Ok(builtins) => project_descriptors(
+ &mut registry,
+ ComponentKind::Agent,
+ builtins.into_iter().map(|def| def.id),
+ ),
+ Err(err) => {
+ tracing::debug!(
+ %err,
+ "[registry] agent_registry builtin load failed; \
+ registered runtime-registry agents only"
+ );
+ 0
+ }
+ };
+
+ let diagnostics = registry.diagnostics();
+ tracing::debug!(
+ models = registry.to_model_registry().names().len(),
+ tools = registry.names(ComponentKind::Tool).len(),
+ graphs = registry.names(ComponentKind::Graph).len(),
+ agents = runtime_agent_count + builtin_supplement_count,
+ diagnostics = diagnostics.len(),
+ "[registry] per-turn capability projection summary"
+ );
+ diagnostics
+}
+
+#[cfg(test)]
+#[path = "tool_registration_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
similarity index 100%
rename from crates/openhuman-core/src/agent/tinyagents/harness_tool_registration_tests.rs
rename to crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs