Skip to content

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

Merge remote-tracking branch 'fork/epic/8092-inference-out' into epic-8092-260-managed-models

Steven Enamakel5761946fcc52
diff --cc crates/openhuman-core/src/flows/agent_route.rs
index 5eb44ab96a,0000000000..ebdfcfc14b
mode 100644,000000..100644
--- a/crates/openhuman-core/src/flows/agent_route.rs
+++ b/crates/openhuman-core/src/flows/agent_route.rs
@@@ -1,78 -1,0 +1,81 @@@
+//! Host-owned selection and model routing for TinyFlows agent nodes.
+
- use crate::inference::provider::{is_raw_passthrough_model, role_for_model_tier};
++use crate::inference::provider::factory::PROVIDER_OPENHUMAN;
+
+/// Which execution path an `agent_ref` routes to (see [`crate::flows::caps_host::agent::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_registry::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
+/// [`crate::flows::caps_host::OpenHumanLlm::complete`] applies through the
+/// TinyFlows portability contract.
+pub(crate) fn harness_model_default_override(node_model: &str) -> String {
- if is_raw_passthrough_model(node_model) {
++ if crate::inference::provider_model::is_raw_model(PROVIDER_OPENHUMAN, node_model) {
+ return node_model.to_string();
+ }
- format!("hint:{}", role_for_model_tier(node_model))
++ format!(
++ "hint:{}",
++ crate::inference::provider_model::role_for_provider_model(PROVIDER_OPENHUMAN, 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
+/// [`crate::flows::caps_host::agent::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,
+ }
+}
+
+#[cfg(test)]
+#[path = "agent_route_tests.rs"]
+mod tests;
diff --cc crates/openhuman-core/src/flows/agent_route_tests.rs
index cc2d4043d2,0000000000..13a61d4271
mode 100644,000000..100644
--- a/crates/openhuman-core/src/flows/agent_route_tests.rs
+++ b/crates/openhuman-core/src/flows/agent_route_tests.rs
@@@ -1,75 -1,0 +1,80 @@@
+use super::*;
+
+use serde_json::json;
+
+fn custom_registry_entry(enabled: bool) -> crate::agent_registry::AgentRegistryEntry {
+ use crate::agent_registry::types::{AgentRegistrySource, AgentSubagentPolicy};
+ crate::agent_registry::AgentRegistryEntry {
+ id: "finance_analyst".to_string(),
+ name: "Finance Analyst".to_string(),
+ description: "Reviews spend and drafts finance summaries.".to_string(),
+ source: AgentRegistrySource::Custom,
+ enabled,
+ model: Some("hint:reasoning".to_string()),
+ system_prompt: Some("You are a meticulous finance analyst.".to_string()),
+ tool_allowlist: vec!["memory_search".to_string()],
+ tool_denylist: Vec::new(),
+ tool_rules: None,
+ subagents: AgentSubagentPolicy::default(),
+ tags: Vec::new(),
+ metadata: json!(null),
+ }
+}
+
+#[test]
- fn harness_model_default_override_normalises_tiers_to_hint_roles() {
++fn harness_model_default_override_preserves_unowned_model_ids() {
+ assert_eq!(
+ harness_model_default_override("reasoning-v1"),
++ "reasoning-v1"
++ );
++ assert_eq!(harness_model_default_override("chat-v1"), "chat-v1");
++ crate::agent::session_host::test_support::install_model_fixture();
++ assert_eq!(
++ harness_model_default_override("fixture-reasoning"),
+ "hint:reasoning"
+ );
- assert_eq!(harness_model_default_override("chat-v1"), "hint:chat");
+ assert_eq!(
+ harness_model_default_override("hint:reasoning"),
+ "hint:reasoning"
+ );
+}
+
+#[test]
+fn harness_model_default_override_forwards_raw_models_verbatim() {
+ assert_eq!(
+ harness_model_default_override("claude-opus-4"),
+ "claude-opus-4"
+ );
+ assert_eq!(
+ harness_model_default_override("openai:gpt-4o"),
+ "openai:gpt-4o"
+ );
+ assert_eq!(harness_model_default_override(" "), "hint:chat");
+}
+
+#[test]
+fn route_for_agent_ref_selects_harness_for_definitions_else_fallback() {
+ let _ = crate::agent_registry::host_definition::AgentDefinitionRegistry::init_global_builtins();
+ assert_eq!(route_for_agent_ref("workflow_builder"), AgentRoute::Harness);
+ assert_eq!(route_for_agent_ref("planner"), AgentRoute::Harness);
+ assert_eq!(
+ route_for_agent_ref("totally_unknown_custom_agent_xyz"),
+ AgentRoute::RegistryFallback
+ );
+}
+
+#[test]
+fn custom_agent_route_requires_an_enabled_registry_entry() {
+ assert_eq!(
+ route_custom_entry_lookup(Some(&custom_registry_entry(true))),
+ AgentRoute::Harness
+ );
+ assert_eq!(
+ route_custom_entry_lookup(Some(&custom_registry_entry(false))),
+ AgentRoute::RegistryFallback
+ );
+ assert_eq!(
+ route_custom_entry_lookup(None),
+ AgentRoute::RegistryFallback
+ );
+}
diff --cc crates/openhuman-core/src/flows/caps_host/llm.rs
index b7aba8df88,aa041122ba..8f83bf1d5d
--- a/crates/openhuman-core/src/flows/caps_host/llm.rs
+++ b/crates/openhuman-core/src/flows/caps_host/llm.rs
@@@ -7,24 -7,17 +7,27 @@@
use std::sync::Arc;
-use async_trait::async_trait;
use serde_json::{json, Value};
-use tinyflows::caps::*;
-use tinyflows::error::{EngineError, Result};
+use super::prompt::build_completion_messages;
use super::*;
use crate::config::Config;
- use crate::inference::provider::{
- create_chat_model_with_model_id_in, is_raw_passthrough_model, role_for_model_tier,
- };
+ use crate::inference::provider::create_chat_model_with_model_id_in;
-use tinyflows::nodes::integration::agent_prompt;
+use crate::modules::tinyflows as module;
use tinyinference_llm::model::ModelRequest;
+pub(crate) fn resolve_host_model(node_model: Option<&str>, provider_model: String) -> String {
- match node_model.filter(|model| is_raw_passthrough_model(model)) {
++ match node_model.filter(|model| {
++ crate::inference::provider_model::is_raw_model(
++ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
++ model,
++ )
++ }) {
+ Some(model) => model.to_owned(),
+ None => provider_model,
+ }
+}
+
/// [`LlmProvider`] adapter over OpenHuman's inference stack
/// (`crates/openhuman-core/src/inference/provider/`).
///
diff --cc crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs
index 1fecfb65d4,0000000000..357789c398
mode 100644,000000..100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs
@@@ -1,75 -1,0 +1,78 @@@
+use super::*;
- use crate::inference::provider::is_raw_passthrough_model;
+use serde_json::json;
+
+#[test]
- fn raw_provider_models_override_the_role_default() {
++fn unowned_model_ids_override_the_role_default() {
+ for raw in ["claude-opus-4", "deepseek-v4-pro"] {
- assert!(is_raw_passthrough_model(raw));
++ assert!(crate::inference::provider_model::is_raw_model(
++ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
++ raw
++ ));
+ assert_eq!(resolve_host_model(Some(raw), "chat-v1".to_owned()), raw);
+ }
+}
+
+#[test]
- fn managed_model_tiers_keep_the_provider_resolved_model() {
- for tier in ["chat-v1", "hint:reasoning", "hint:garbage"] {
++fn registered_provider_aliases_and_hints_keep_the_resolved_model() {
++ crate::agent::session_host::test_support::install_model_fixture();
++ for tier in ["fixture-reasoning", "hint:reasoning", "hint:garbage"] {
+ assert_eq!(
+ resolve_host_model(Some(tier), "reasoning-v1".to_owned()),
+ "reasoning-v1"
+ );
+ }
+ assert_eq!(resolve_host_model(None, "chat-v1".to_owned()), "chat-v1");
+ assert_eq!(
+ resolve_host_model(Some(" "), "chat-v1".to_owned()),
+ "chat-v1"
+ );
+}
+
+#[test]
+fn provider_response_preserves_the_flow_completion_contract() {
+ use tinyinference_llm::message::{AssistantMessage, ContentBlock};
+ use tinyinference_llm::model::ModelResponse;
+ use tinyinference_llm::tool::ToolCall;
+ use tinyinference_llm::usage::Usage;
+
+ let usage = Usage::new(11, 7);
+ let response = ModelResponse {
+ message: AssistantMessage {
+ id: Some("msg-1".to_string()),
+ content: vec![
+ ContentBlock::Text("done".to_string()),
+ ContentBlock::thinking("private chain"),
+ ],
+ tool_calls: vec![ToolCall {
+ id: "call-1".to_string(),
+ name: "lookup".to_string(),
+ arguments: json!({"query": "weather"}),
+ invalid: None,
+ }],
+ usage: Some(usage),
+ origin: None,
+ },
+ usage: Some(usage),
+ finish_reason: Some("tool_calls".to_string()),
+ raw: tinyinference_llm::usage::merge_usage_meta(None, Some(0.125), 128_000),
+ resolved_model: None,
+ continue_turn: None,
+ served_from_cache: false,
+ correlation: None,
+ resolved_route: None,
+ };
+
+ let value = model_response_to_completion_value(&response);
+ assert_eq!(value["text"], "done");
+ assert_eq!(value["tool_calls"][0]["id"], "call-1");
+ assert_eq!(value["tool_calls"][0]["name"], "lookup");
+ assert_eq!(
+ value["tool_calls"][0]["arguments"],
+ r#"{"query":"weather"}"#
+ );
+ assert_eq!(value["usage"]["input_tokens"], 11);
+ assert_eq!(value["usage"]["output_tokens"], 7);
+ assert_eq!(value["usage"]["context_window"], 128_000);
+ assert_eq!(value["usage"]["charged_amount_usd"], 0.125);
+ assert_eq!(value["reasoning_content"], "private chain");
+}
diff --cc crates/openhuman-core/src/flows/ops/inference_readiness.rs
index 12dd8195cb,ac0e5ce9bd..6131a5893a
--- a/crates/openhuman-core/src/flows/ops/inference_readiness.rs
+++ b/crates/openhuman-core/src/flows/ops/inference_readiness.rs
@@@ -68,8 -205,12 +68,11 @@@ pub(super) async fn agent_node_role(con
.map(str::trim)
.filter(|s| !s.is_empty());
if let Some(model) = pinned_model {
- return crate::inference::provider::role_for_model_tier(model);
+ return crate::inference::provider_model::role_for_provider_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ model,
+ );
}
-
"summarization"
}
diff --cc crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
index e302d8be24,4d7a58fe5b..f55745c4ff
--- a/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
@@@ -230,6 -225,6 +230,17 @@@ async fn agent_node_role_prefers_custom
);
}
++#[tokio::test]
++async fn agent_node_role_uses_registered_provider_model_policy() {
++ crate::agent::session_host::test_support::install_model_fixture();
++ let tmp = TempDir::new().unwrap();
++ let config = test_config(&tmp);
++ assert_eq!(
++ agent_node_role(&config, &json!({ "model": "fixture-reasoning" })).await,
++ "reasoning"
++ );
++}
++
#[tokio::test]
async fn inference_gate_probes_every_distinct_agent_node_role() {
// A graph with TWO `agent` nodes, each pinned (via `config.model`) to a
diff --cc crates/openhuman-core/src/inference/mod.rs
index ad82aea14a,754d5662ea..e3432dcd62
--- a/crates/openhuman-core/src/inference/mod.rs
+++ b/crates/openhuman-core/src/inference/mod.rs
@@@ -32,7 -32,7 +32,8 @@@ pub mod http
pub mod model_context;
pub mod ops;
pub mod provider;
+ pub mod provider_model;
+pub mod readiness;
pub(crate) mod reasoning;
pub mod registry;
mod schemas;
diff --cc crates/openhuman-core/src/inference/provider/factory.rs
index 879540de47,5956e7fb92..c49c54bc20
--- a/crates/openhuman-core/src/inference/provider/factory.rs
+++ b/crates/openhuman-core/src/inference/provider/factory.rs
@@@ -46,12 -21,12 +21,10 @@@ mod credentials
mod discovery;
mod local_runtime;
mod managed_backend;
- mod primary_cloud;
mod routing;
mod subprocess_providers;
- mod tiers;
mod turn_model;
-#[cfg(feature = "flows")]
-pub(crate) use access_gates::current_host_requires_session;
pub(crate) use chat_model::resolves_to_managed_backend;
pub use chat_model::{
create_chat_model_from_string, create_chat_model_from_string_with_model_id,
diff --cc scripts/ci/check-openhuman-rust-layout.mjs
index ef24590fe9,8eac5a9ec9..1fcf0c9c4f
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@@ -39,9 -41,9 +41,9 @@@ const LEGACY_LIMIT_ENTRIES =
// oversized files are pinned at the size they had when enforcement began.
["crates/openhuman-core/src/core/all.rs", 1114],
["crates/openhuman-core/src/core/all_tests.rs", 1465],
- ["crates/openhuman-core/src/core/events.rs", 1703],
- ["crates/openhuman-core/src/core/events_tests.rs", 997],
+ ["crates/openhuman-core/src/core/events.rs", 1697],
+ ["crates/openhuman-core/src/core/events_tests.rs", 988],
- ["crates/openhuman-core/src/core/observability.rs", 3429],
+ ["crates/openhuman-core/src/core/observability.rs", 3425],
];
const LEGACY_LIMITS = new Map(LEGACY_LIMIT_ENTRIES);