Skip to content

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

refactor(flows): extract agent routing helpers into agent_route module

Steven Enamakel1e0ed9e42b3b
diff --git a/crates/openhuman-core/src/flows/agent_route.rs b/crates/openhuman-core/src/flows/agent_route.rs
new file mode 100644
index 0000000000..e122f96d41
--- /dev/null
+++ b/crates/openhuman-core/src/flows/agent_route.rs
@@ -0,0 +1,75 @@
+//! Host-owned selection and model routing for TinyFlows agent nodes.
+
+use crate::inference::provider::{is_raw_passthrough_model, role_for_model_tier};
+
+/// Which execution path an `agent_ref` routes to (see [`OpenHumanAgentRunner`]).
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum AgentRoute {
+ /// A host-registered agent (`agent::host_agents`) — run the full agent
+ /// tool loop as that agent, with its host tools, in its context.
+ HostAgent,
+ /// A harness `AgentDefinition` exists — run the full agent tool loop.
+ Harness,
+ /// No definition; fall back to the custom-registry persona completion.
+ RegistryFallback,
+}
+
+/// Decides the route for `agent_ref` by consulting the (already-initialised)
+/// global `AgentDefinitionRegistry`: a harness definition wins; otherwise the
+/// custom-registry fallback. Pure over the global registry so the selection is
+/// unit-testable with `init_global_builtins`.
+pub(crate) fn route_for_agent_ref(agent_ref: &str) -> AgentRoute {
+ if crate::agent::host_agents::resolve(agent_ref).is_some() {
+ return AgentRoute::HostAgent;
+ }
+ let has_definition = crate::agent::harness::host_definition::AgentDefinitionRegistry::current()
+ .map(|reg| reg.get(agent_ref).is_some())
+ .unwrap_or(false);
+ if has_definition {
+ AgentRoute::Harness
+ } else {
+ AgentRoute::RegistryFallback
+ }
+}
+
+/// Translates a managed tier / `hint:*` / model string into the `default_model`
+/// value that routes a freshly-built harness [`Agent`](crate::agent::OpenHumanSessionHost)
+/// to the workload serving that tier. The session builder's `provider_role_for`
+/// only routes the `hint:<role>` form to a specialised workload, so a bare tier
+/// name (`hint:reasoning`) must be normalised to `hint:reasoning` here — otherwise
+/// it would silently fall through to the chat workload.
+///
+/// A **raw/BYOK** model id (e.g. `claude-opus-4`) is instead forwarded verbatim:
+/// wrapping it in `hint:chat` would collapse the user's explicit per-node model
+/// onto the managed `hint:chat` tier (issue #4598). Left verbatim, it flows through
+/// the session builder's generic `chat` role — which inherits
+/// `config.default_model` — to `make_openhuman_backend`, which forwards non-tier
+/// ids to the backend unchanged. Mirrors the per-node routing
+/// [`OpenHumanLlm::complete`] applies via `agent_prompt::resolve_completion_model`.
+pub(crate) fn harness_model_default_override(node_model: &str) -> String {
+ if is_raw_passthrough_model(node_model) {
+ return node_model.to_string();
+ }
+ format!("hint:{}", role_for_model_tier(node_model))
+}
+
+
+/// Decides how to run an `agent_ref` that has no harness definition, given
+/// the (already-performed) config-backed custom registry lookup: an
+/// [`AgentRoute::Harness`] for a known, *enabled* custom entry — the factory
+/// synthesizes a real `AgentDefinition` for it (issue B38/Gap 2), so it can
+/// run the full tool loop — and [`AgentRoute::RegistryFallback`] for
+/// anything else (no entry at all, or a disabled one, which
+/// [`OpenHumanAgentRunner::run_via_registry_fallback`] itself rejects with a
+/// clear "is disabled" error rather than silently skipping it here). Pure
+/// over the lookup result so the decision is unit-testable without a live
+/// `Config`/registry.
+pub(crate) fn route_custom_entry_lookup(
+ entry: Option<&crate::agent::registry::AgentRegistryEntry>,
+) -> AgentRoute {
+ match entry {
+ Some(e) if e.enabled => AgentRoute::Harness,
+ _ => AgentRoute::RegistryFallback,
+ }
+}
+
diff --git a/crates/openhuman-core/src/flows/mod.rs b/crates/openhuman-core/src/flows/mod.rs
index 2c13be1b81..859856a48e 100644
--- a/crates/openhuman-core/src/flows/mod.rs
+++ b/crates/openhuman-core/src/flows/mod.rs
@@ -24,6 +24,7 @@
//! family must convert to the facade+stub shape (see `voice/`).
pub mod agents;
+mod agent_route;
pub mod builder_host;
pub(crate) mod builder_tools;
mod builder_tools_connection_reads;
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
index 3d9935ad57..6f34e46aba 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
@@ -17,8 +17,8 @@ use tinyflows::caps::*;
use tinyflows::error::{EngineError, Result};
use super::*;
+use super::agent_route::{harness_model_default_override, route_custom_entry_lookup, route_for_agent_ref, AgentRoute};
use crate::config::Config;
-use crate::inference::provider::{is_raw_passthrough_model, role_for_model_tier};
/// [`AgentRunner`] backing an `agent` node's `agent_ref`. It runs the selected
/// agent kind by one of two paths, chosen by [`route_for_agent_ref`]:
@@ -118,56 +118,6 @@ fn max_parallel_harness_agents(raw: Option<&str>) -> usize {
.unwrap_or(DEFAULT_MAX_PARALLEL_HARNESS_AGENTS)
}
-/// Which execution path an `agent_ref` routes to (see [`OpenHumanAgentRunner`]).
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub(crate) enum AgentRoute {
- /// A host-registered agent (`agent::host_agents`) — run the full agent
- /// tool loop as that agent, with its host tools, in its context.
- HostAgent,
- /// A harness `AgentDefinition` exists — run the full agent tool loop.
- Harness,
- /// No definition; fall back to the custom-registry persona completion.
- RegistryFallback,
-}
-
-/// Decides the route for `agent_ref` by consulting the (already-initialised)
-/// global `AgentDefinitionRegistry`: a harness definition wins; otherwise the
-/// custom-registry fallback. Pure over the global registry so the selection is
-/// unit-testable with `init_global_builtins`.
-pub(crate) fn route_for_agent_ref(agent_ref: &str) -> AgentRoute {
- if crate::agent::host_agents::resolve(agent_ref).is_some() {
- return AgentRoute::HostAgent;
- }
- let has_definition = crate::agent::harness::host_definition::AgentDefinitionRegistry::current()
- .map(|reg| reg.get(agent_ref).is_some())
- .unwrap_or(false);
- if has_definition {
- AgentRoute::Harness
- } else {
- AgentRoute::RegistryFallback
- }
-}
-
-/// Translates a managed tier / `hint:*` / model string into the `default_model`
-/// value that routes a freshly-built harness [`Agent`](crate::agent::OpenHumanSessionHost)
-/// to the workload serving that tier. The session builder's `provider_role_for`
-/// only routes the `hint:<role>` form to a specialised workload, so a bare tier
-/// name (`hint:reasoning`) must be normalised to `hint:reasoning` here — otherwise
-/// it would silently fall through to the chat workload.
-///
-/// A **raw/BYOK** model id (e.g. `claude-opus-4`) is instead forwarded verbatim:
-/// wrapping it in `hint:chat` would collapse the user's explicit per-node model
-/// onto the managed `hint:chat` tier (issue #4598). Left verbatim, it flows through
-/// the session builder's generic `chat` role — which inherits
-/// `config.default_model` — to `make_openhuman_backend`, which forwards non-tier
-/// ids to the backend unchanged. Mirrors the per-node routing
-/// [`OpenHumanLlm::complete`] applies via `agent_prompt::resolve_completion_model`.
-pub(crate) fn harness_model_default_override(node_model: &str) -> String {
- if is_raw_passthrough_model(node_model) {
- return node_model.to_string();
- }
- format!("hint:{}", role_for_model_tier(node_model))
-}
#[async_trait]
impl AgentRunner for OpenHumanAgentRunner {
@@ -286,24 +236,6 @@ impl AgentRunner for OpenHumanAgentRunner {
}
}
-/// Decides how to run an `agent_ref` that has no harness definition, given
-/// the (already-performed) config-backed custom registry lookup: an
-/// [`AgentRoute::Harness`] for a known, *enabled* custom entry — the factory
-/// synthesizes a real `AgentDefinition` for it (issue B38/Gap 2), so it can
-/// run the full tool loop — and [`AgentRoute::RegistryFallback`] for
-/// anything else (no entry at all, or a disabled one, which
-/// [`OpenHumanAgentRunner::run_via_registry_fallback`] itself rejects with a
-/// clear "is disabled" error rather than silently skipping it here). Pure
-/// over the lookup result so the decision is unit-testable without a live
-/// `Config`/registry.
-pub(crate) fn route_custom_entry_lookup(
- entry: Option<&crate::agent::registry::AgentRegistryEntry>,
-) -> AgentRoute {
- match entry {
- Some(e) if e.enabled => AgentRoute::Harness,
- _ => AgentRoute::RegistryFallback,
- }
-}
impl OpenHumanAgentRunner {
/// Full harness turn: build a real session agent for `agent_ref` and drive