Skip to content

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

refactor(managed-tiers): replace hard-coded tier constants with role-based vocabulary

Steven Enamakel5d2735591557
diff --git a/crates/openhuman-core/src/inference/provider/factory/tiers.rs b/crates/openhuman-core/src/inference/provider/factory/tiers.rs
index 9a507ee389..3401bf6522 100644
--- a/crates/openhuman-core/src/inference/provider/factory/tiers.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/tiers.rs
@@ -1,99 +1,70 @@
-//! Managed tier / `hint:*` vocabulary: tier↔role lookups, passthrough
-//! detection, and per-tier vision capability for the managed backend.
+//! Managed workload vocabulary: `hint:*` role aliases, retired tier slugs,
+//! passthrough detection, and vision capability for the managed backend.
+//!
+//! The managed backend serves OpenRouter model ids only. Workload **roles**
+//! (`chat`, `reasoning`, `coding`, …) remain the routing vocabulary — a role
+//! picks its `*_provider` route — but on the managed backend every role runs on
+//! one concrete model: the pinned default (`config.default_model`) or
+//! [`MODEL_MANAGED_DEFAULT`]. The old `chat-v1`-style tier slugs are accepted
+//! as aliases of their role so un-migrated callers keep routing.
use super::*;
+use crate::config::{legacy_tier_role, MODEL_MANAGED_DEFAULT};
+/// Whether `model` is a managed alias rather than a concrete model id: a
+/// `hint:*` role marker or a retired tier slug.
pub(super) fn is_abstract_tier_model(model: &str) -> bool {
- use crate::config::{
- MODEL_AGENTIC_V1, MODEL_BURST_V1, MODEL_CHAT_V1, MODEL_CODING_V1, MODEL_REASONING_QUICK_V1,
- MODEL_REASONING_V1, MODEL_SUMMARIZATION_V1, MODEL_VISION_V1,
- };
let trimmed = model.trim();
- trimmed == MODEL_REASONING_V1
- || trimmed == MODEL_REASONING_QUICK_V1
- || trimmed == MODEL_CHAT_V1
- || trimmed == MODEL_AGENTIC_V1
- || trimmed == MODEL_BURST_V1
- || trimmed == MODEL_CODING_V1
- || trimmed == MODEL_VISION_V1
- || trimmed == MODEL_SUMMARIZATION_V1
+ trimmed.starts_with("hint:") || legacy_tier_role(trimmed).is_some()
}
-/// Resolve a model hint (e.g. `"hint:reasoning"`) or tier name to the
-/// concrete model string that the provider router would use — without
-/// constructing the actual provider. Returns the provider-string prefix
-/// (e.g. `"openai"`) concatenated with the model when a BYOK provider is
-/// active, or the bare tier name for the managed OpenHuman backend.
-pub fn resolve_model_for_hint(hint_or_tier: &str, config: &Config) -> String {
- let hint_to_tier: &[(&str, &str)] = &[
- ("reasoning", crate::config::MODEL_REASONING_V1),
- ("chat", crate::config::MODEL_CHAT_V1),
- ("agentic", crate::config::MODEL_AGENTIC_V1),
- ("burst", crate::config::MODEL_BURST_V1),
- ("coding", crate::config::MODEL_CODING_V1),
- ("vision", crate::config::MODEL_VISION_V1),
- ("summarization", crate::config::MODEL_SUMMARIZATION_V1),
- // Background subconscious workload rides the lightweight chat tier on the
- // managed backend; its `subconscious` *role* (handled below) still selects
- // the provider via `subconscious_provider`.
- ("subconscious", crate::config::MODEL_CHAT_V1),
- ];
- let tier_to_role: &[(&str, &str)] = &[
- (crate::config::MODEL_REASONING_V1, "reasoning"),
- (crate::config::MODEL_CHAT_V1, "chat"),
- (crate::config::MODEL_REASONING_QUICK_V1, "chat"),
- (crate::config::MODEL_AGENTIC_V1, "agentic"),
- (crate::config::MODEL_BURST_V1, "burst"),
- (crate::config::MODEL_CODING_V1, "coding"),
- (crate::config::MODEL_VISION_V1, "vision"),
- (crate::config::MODEL_SUMMARIZATION_V1, "summarization"),
- ];
+/// The workload role a `hint:*` marker names, if it is one of ours.
+fn hint_role(hint: &str) -> Option<&'static str> {
+ match hint.strip_prefix("hint:")? {
+ "chat" => Some("chat"),
+ "reasoning" => Some("reasoning"),
+ "agentic" => Some("agentic"),
+ "burst" => Some("burst"),
+ "coding" => Some("coding"),
+ "vision" => Some("vision"),
+ "summarization" => Some("summarization"),
+ "subconscious" => Some("subconscious"),
+ _ => None,
+ }
+}
- let (tier, role) = if let Some(hint_key) = hint_or_tier.strip_prefix("hint:") {
- let tier = hint_to_tier
- .iter()
- .find(|(k, _)| *k == hint_key)
- .map(|(_, v)| *v)
- .unwrap_or(hint_or_tier);
- // Background workloads map to a tier *model* but must keep their own
- // role so `provider_for_role` reads their dedicated `*_provider` field
- // rather than the chat-tier provider their model happens to share.
- let role = match hint_key {
- "subconscious" => "subconscious",
- _ => tier_to_role
- .iter()
- .find(|(k, _)| *k == tier)
- .map(|(_, v)| *v)
- .unwrap_or(hint_key),
- };
- (tier, role)
- } else {
- let role = tier_to_role
- .iter()
- .find(|(k, _)| *k == hint_or_tier)
- .map(|(_, v)| *v)
- .unwrap_or("chat");
- (hint_or_tier, role)
+/// The concrete model every managed role runs on: the user's pinned default,
+/// else [`MODEL_MANAGED_DEFAULT`].
+pub(crate) fn managed_default_model(config: &Config) -> String {
+ pinned_managed_default_model(config).unwrap_or_else(|| MODEL_MANAGED_DEFAULT.to_string())
+}
+
+/// Resolve a model hint (e.g. `"hint:reasoning"`), a retired tier slug, or a
+/// concrete model id to the model string the provider router would use —
+/// without constructing the provider. A BYOK route yields its own model; a
+/// managed route yields [`managed_default_model`]; a concrete id passes through.
+pub fn resolve_model_for_hint(hint_or_tier: &str, config: &Config) -> String {
+ let trimmed = hint_or_tier.trim();
+ let role = match hint_role(trimmed).or_else(|| legacy_tier_role(trimmed)) {
+ Some(role) => role,
+ None => {
+ // A concrete id (catalog model, BYOK id) resolves to itself.
+ return trimmed.to_string();
+ }
};
let provider_string = provider_for_role(role, config);
let ps = provider_string.trim();
if ps.is_empty() || ps == "cloud" || ps == PROVIDER_OPENHUMAN || ps == BYOK_INCOMPLETE_SENTINEL
{
- // A managed chat turn runs on the pinned default model when one is
- // set; every other tier keeps its name. Mirrors the managed backend's
- // own `hint:chat` translation so what the UI displays is what runs.
- if role == "chat" && tier == crate::config::MODEL_CHAT_V1 {
- if let Some(pinned) = pinned_managed_default_model(config) {
- log::debug!(
- "[providers][resolve-hint] hint={} managed chat resolves to pinned default model={}",
- hint_or_tier,
- pinned
- );
- return pinned;
- }
- }
- tier.to_string()
+ let model = managed_default_model(config);
+ log::debug!(
+ "[providers][resolve-hint] hint={} role={} managed resolves to model={}",
+ hint_or_tier,
+ role,
+ model
+ );
+ model
} else if let Some(idx) = ps.find(':') {
let model_with_temp = &ps[idx + 1..];
let (model, _) = split_model_and_temperature(model_with_temp);
@@ -103,148 +74,71 @@ pub fn resolve_model_for_hint(hint_or_tier: &str, config: &Config) -> String {
}
}
-/// Map a managed tier name (or `hint:*` string) to the workload **role** whose
-/// configured provider serves it.
+/// Map a `hint:*` marker or retired tier slug to the workload **role** whose
+/// configured provider serves it. Concrete model ids and unknown strings fall
+/// back to `"chat"`.
///
-/// This is the inverse of the role→tier routing `create_chat_model` does:
-/// callers that select a model *per unit of work by tier* (e.g. a tinyflows
-/// `agent` node pinning `config.model = "reasoning-v1"`) use this to turn that
-/// tier back into the role, then call [`create_chat_model`] with it — so the
-/// completion routes to that tier on the managed backend (or the role's BYOK
-/// model) instead of some caller default. Unknown strings fall back to `"chat"`.
-///
-/// Kept deliberately small and standalone (no `Config`) — it is a pure lookup
-/// over the tier constants, mirroring the `tier_to_role` table inside
-/// [`resolve_model_for_hint`].
+/// Kept deliberately small and standalone (no `Config`): callers that select
+/// a model *per unit of work* (a tinyflows `agent` node pinning
+/// `config.model = "hint:reasoning"`) turn that back into the role, then call
+/// `create_chat_model` with it so the completion follows the role's route.
pub fn role_for_model_tier(hint_or_tier: &str) -> &'static str {
- use crate::config::{
- MODEL_AGENTIC_V1, MODEL_BURST_V1, MODEL_CHAT_V1, MODEL_CODING_V1, MODEL_REASONING_QUICK_V1,
- MODEL_REASONING_V1, MODEL_SUMMARIZATION_V1, MODEL_VISION_V1,
- };
-
- // Normalise a `hint:*` alias to its concrete tier first.
- let tier = match hint_or_tier.strip_prefix("hint:") {
- Some("reasoning") => MODEL_REASONING_V1,
- Some("chat") => MODEL_CHAT_V1,
- Some("agentic") => MODEL_AGENTIC_V1,
- Some("burst") => MODEL_BURST_V1,
- Some("coding") => MODEL_CODING_V1,
- Some("vision") => MODEL_VISION_V1,
- Some("summarization") => MODEL_SUMMARIZATION_V1,
- // Background subconscious rides the chat tier for its model.
- Some("subconscious") => MODEL_CHAT_V1,
- Some(_) => hint_or_tier,
- None => hint_or_tier,
- };
-
- match tier {
- MODEL_REASONING_V1 => "reasoning",
- MODEL_CHAT_V1 | MODEL_REASONING_QUICK_V1 => "chat",
- MODEL_AGENTIC_V1 => "agentic",
- MODEL_BURST_V1 => "burst",
- MODEL_CODING_V1 => "coding",
- MODEL_VISION_V1 => "vision",
- MODEL_SUMMARIZATION_V1 => "summarization",
- _ => "chat",
- }
+ let trimmed = hint_or_tier.trim();
+ hint_role(trimmed)
+ .or_else(|| legacy_tier_role(trimmed))
+ .unwrap_or("chat")
}
-/// Return whether `model` is a recognized OpenHuman backend tier name.
-///
-/// Used to guard against stale `default_model` values (e.g. set by older UI
-/// versions) that the backend would reject with HTTP 400. The known tiers are
-/// the constants in `crate::config`; the four `hint:*` strings that
-/// `make_openhuman_backend` actually translates are also accepted. An
-/// unrecognized `hint:*` value is intentionally rejected so the factory falls
-/// back to the platform default instead of forwarding an untranslated string
-/// to the backend.
/// The user's pinned managed **default model** — `config.default_model` when
/// it names a concrete catalog model (e.g. `openrouter/deepseek/deepseek-v4-flash`)
-/// rather than a managed tier or a `hint:*` marker.
+/// rather than a `hint:*` marker or a retired tier slug.
///
-/// The Routing page writes a catalog id here as the "default model": the one a
-/// managed `chat` turn runs on instead of the anonymous `chat-v1` tier. Tier
-/// names and hints are not pins — they are the pre-existing "let the backend
-/// pick" contract — so they yield `None` and the caller keeps its tier.
+/// The Routing page writes a catalog id here as the "default model": the one
+/// every managed workload runs on. Hints and retired tiers are not pins — they
+/// are the old "let the backend pick" contract — so they yield `None`.
pub(crate) fn pinned_managed_default_model(config: &Config) -> Option<String> {
let model = config.default_model.as_deref()?.trim();
- if model.is_empty() || model.starts_with("hint:") || is_known_openhuman_tier(model) {
+ if model.is_empty() || is_known_openhuman_tier(model) {
return None;
}
Some(model.to_string())
}
+/// Whether `model` is a managed alias the backend must never receive verbatim:
+/// a `hint:*` role marker we translate, or a retired tier slug.
pub(crate) fn is_known_openhuman_tier(model: &str) -> bool {
- use crate::config::{
- MODEL_AGENTIC_V1, MODEL_BURST_V1, MODEL_CHAT_V1, MODEL_CODING_V1, MODEL_REASONING_QUICK_V1,
- MODEL_REASONING_V1, MODEL_SUMMARIZATION_V1, MODEL_VISION_V1,
- };
- matches!(
- model,
- MODEL_REASONING_V1
- | MODEL_CHAT_V1
- | MODEL_AGENTIC_V1
- | MODEL_BURST_V1
- | MODEL_CODING_V1
- | MODEL_REASONING_QUICK_V1
- | MODEL_SUMMARIZATION_V1
- | MODEL_VISION_V1
- | "hint:reasoning"
- | "hint:chat"
- | "hint:agentic"
- | "hint:burst"
- | "hint:coding"
- | "hint:summarization"
- | "hint:vision"
- )
+ let trimmed = model.trim();
+ hint_role(trimmed).is_some() || legacy_tier_role(trimmed).is_some()
}
-/// Return whether `model` is a raw BYOK/custom model id that must be forwarded
-/// **verbatim** to provider construction rather than mapped onto a managed tier.
+/// Return whether `model` is a raw model id that must be forwarded **verbatim**
+/// to provider construction rather than mapped onto a managed role.
///
/// A raw passthrough id is any **non-empty** string that is neither a `hint:*`
-/// alias nor a known managed tier ([`is_known_openhuman_tier`]) — i.e. the model
-/// ids a user pins directly on an agent/node (e.g. `"claude-opus-4"`). The
-/// OpenHuman backend preserves such ids verbatim
-/// (the managed model's blank-id normalization) and is authoritative over
-/// their validity, so the core must **not** silently collapse them onto
-/// `reasoning-v1` (issue #4598). Managed tiers and every `hint:*` string return
-/// `false` so their existing resolution is untouched.
+/// alias nor a retired tier slug — the model ids a user pins directly on an
+/// agent/node (e.g. `"openrouter/deepseek/deepseek-v4-pro"`). The managed
+/// backend is authoritative over their validity, so the core must **not**
+/// silently collapse them onto the default (issue #4598).
pub(crate) fn is_raw_passthrough_model(model: &str) -> bool {
let trimmed = model.trim();
!trimmed.is_empty() && !trimmed.starts_with("hint:") && !is_known_openhuman_tier(trimmed)
}
-/// Per-tier vision (image-input) capability for the managed OpenHuman backend.
-///
-/// The remote managed backend (`api.tinyhumans.ai`) does not advertise per-tier
-/// capabilities, so the core maintains this map itself. Accepts both the tier
-/// constants and their `hint:*` forms (callers may pass either pre- or
-/// post-resolution).
+/// Vision (image-input) capability for a managed model or role alias.
///
-/// `reasoning-v1` and the dedicated `vision-v1` tier are multimodal; every
-/// other tier returns `false` — flip an individual arm to `true` once that tier
-/// is confirmed multimodal on the backend. This is the **only** place to change
-/// managed-model vision; BYOK/custom models are handled separately by the
-/// user-set `model_registry.vision` flag
+/// The managed backend does not advertise per-model capabilities, so the core
+/// owns this. [`MODEL_MANAGED_DEFAULT`] (DeepSeek V4 Flash on the managed
+/// backend) accepts images, as do the `vision` and `reasoning` role aliases
+/// (and their retired tier slugs) that always ran a multimodal model. Any other
+/// pinned catalog id is covered by the user's `model_registry.vision` flag
/// ([`crate::inference::model_context::model_vision_enabled`]).
pub(crate) fn oh_tier_supports_vision(model: &str) -> bool {
- use crate::config::{
- MODEL_AGENTIC_V1, MODEL_BURST_V1, MODEL_CHAT_V1, MODEL_CODING_V1, MODEL_REASONING_QUICK_V1,
- MODEL_REASONING_V1, MODEL_SUMMARIZATION_V1, MODEL_VISION_V1,
- };
- match model {
- MODEL_REASONING_V1 | "hint:reasoning" => true,
- // Dedicated multimodal tier — the managed backend serves this with the
- // vision flag enabled. This is what the vision sub-agent rides on.
- MODEL_VISION_V1 | "hint:vision" => true,
- MODEL_CHAT_V1 | "hint:chat" => false,
- MODEL_REASONING_QUICK_V1 => false,
- MODEL_AGENTIC_V1 | "hint:agentic" => false,
- // Burst is a text-only tier.
- MODEL_BURST_V1 | "hint:burst" => false,
- MODEL_CODING_V1 | "hint:coding" => false,
- MODEL_SUMMARIZATION_V1 | "hint:summarization" => false,
- _ => false,
+ let trimmed = model.trim();
+ if trimmed == MODEL_MANAGED_DEFAULT {
+ return true;
}
+ matches!(
+ hint_role(trimmed).or_else(|| legacy_tier_role(trimmed)),
+ Some("vision") | Some("reasoning")
+ )
}