Skip to content

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

feat(tinyhumans): add Jev-backed tool_search ranker

Steven Enamakel7ec3093e9301
diff --git a/crates/openhuman-app/Cargo.toml b/crates/openhuman-app/Cargo.toml
index 8564d19664..4954848519 100644
--- a/crates/openhuman-app/Cargo.toml
+++ b/crates/openhuman-app/Cargo.toml
@@ -40,7 +40,10 @@ openhuman-rpc = { path = "../openhuman-rpc", features = ["http-client"] }
# boot. `default-features = false`: the shell controls every product gate
# through the `openhuman_core` line above, and this crate must not re-enable
# defaults behind `check-feature-forwarding`'s back.
-openhuman-tinyhumans = { path = "../openhuman-tinyhumans", default-features = false }
+# `jev` is that crate's own gate (not a core gate, so not in
+# `scripts/ci/product-features.txt`): the Jev-backed `tool_search` ranker the
+# product ships.
+openhuman-tinyhumans = { path = "../openhuman-tinyhumans", default-features = false, features = ["jev"] }
# Tauri core and plugins. Use upstream Tauri's native WebView runtime (Wry),
# rather than the removed Chromium/CEF fork.
tauri = { version = "2.11", default-features = false, features = [
diff --git a/crates/openhuman-cli/Cargo.toml b/crates/openhuman-cli/Cargo.toml
index 6b68b0becb..423f1b725f 100644
--- a/crates/openhuman-cli/Cargo.toml
+++ b/crates/openhuman-cli/Cargo.toml
@@ -366,6 +366,8 @@ wiremock = "0.6"
# pass `--features "$(scripts/ci/product-features.sh)"`; every product gate
# name resolves here so `cargo test --workspace --features ...` keeps working.
default = ["openhuman-core/default", "openhuman-tinyhumans/default"]
+# The Jev-backed `tool_search` ranker; `openhuman-tinyhumans`'s own gate.
+jev = ["openhuman-tinyhumans/jev"]
http-server = ["openhuman-core/http-server", "openhuman-tinyhumans/http-server"]
inference = ["openhuman-core/inference", "openhuman-tinyhumans/inference"]
documents = ["openhuman-core/documents", "openhuman-tinyhumans/documents"]
diff --git a/crates/openhuman-tinyhumans/Cargo.toml b/crates/openhuman-tinyhumans/Cargo.toml
index a3e1ff9683..dc7372aae7 100644
--- a/crates/openhuman-tinyhumans/Cargo.toml
+++ b/crates/openhuman-tinyhumans/Cargo.toml
@@ -12,7 +12,12 @@ publish = false
# This crate adds no gates of its own: it is the layer that *connects* an
# embed runtime to the TinyHumans backend, not a feature surface.
[features]
-default = ["openhuman-embed/default"]
+# `jev` is this crate's one gate of its own: the Jev-backed `tool_search`
+# ranker (`tinytools-jev` over the TinyHumans System One proxy). On by
+# default and forwarded by every shipped host; without it the core ranks
+# `tool_search` with BM25 alone.
+default = ["openhuman-embed/default", "jev"]
+jev = ["dep:tinytools-jev"]
http-server = ["openhuman-embed/http-server"]
inference = ["openhuman-embed/inference"]
documents = ["openhuman-embed/documents"]
@@ -45,6 +50,12 @@ openhuman-core = { path = "../openhuman-core", package = "openhuman", default-fe
# it. `default-features = false` drops the Socket.IO client; realtime stays
# on the core's own `platform::socket` transport.
tinyhumans-sdk = { path = "../../vendor/tinyhumans-sdk", default-features = false }
+# The `tool_search` ranker backed by TypeSafe's Jev, reached through the
+# backend's `/agent-integrations/openrouter/systemone` proxy with the same
+# credential every other backend call uses. Same vendored tree as the core's
+# `tinytools`, so the `ToolRanker` types unify.
+tinytools = { path = "../../vendor/tinyagents/vendor/tinytools/crates/tinytools" }
+tinytools-jev = { path = "../../vendor/tinyagents/vendor/tinytools/crates/tinytools-jev", optional = true }
anyhow = "1"
async-trait = "0.1"
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
diff --git a/crates/openhuman-tinyhumans/src/jev/mod.rs b/crates/openhuman-tinyhumans/src/jev/mod.rs
new file mode 100644
index 0000000000..963df39f6b
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/jev/mod.rs
@@ -0,0 +1,33 @@
+//! The Jev-backed `tool_search` ranker for a TinyHumans-connected core.
+//!
+//! The core's harness advertises a `tool_search` bridge over every deferred
+//! tool and ranks searches with whatever ranker the process installed
+//! (`openhuman_core::agent::tinyagents::discovery`). This module installs
+//! [`TinyHumansJevRanker`]: `tinytools_jev::JevRanker` — BM25 retrieval to a
+//! shortlist, one Jev `Choice` to decide — reached through the backend's
+//! `/agent-integrations/openrouter/systemone` proxy with the same credential
+//! every other backend call uses.
+//!
+//! The credential is resolved **per search**, not at install: a desktop
+//! signs in and out while the process runs, and a search must follow the
+//! current user. A process with no credential answers with an error the
+//! harness turns into a BM25 fallback, so `auto` costs nothing when signed
+//! out. The built client is cached by credential and base URL so a stable
+//! session does not rebuild an HTTP client on every search.
+
+mod ranker;
+
+pub use ranker::TinyHumansJevRanker;
+
+use std::sync::Arc;
+
+use openhuman_core::agent::tinyagents::discovery::install_tool_ranker;
+
+/// Install the Jev ranker as the process-wide `tool_search` ranker.
+///
+/// Idempotent; the core replaces the previous ranker in place.
+pub fn install_jev_ranker() -> Arc<TinyHumansJevRanker> {
+ let ranker = Arc::new(TinyHumansJevRanker::new());
+ install_tool_ranker(ranker.clone());
+ ranker
+}
diff --git a/crates/openhuman-tinyhumans/src/jev/ranker.rs b/crates/openhuman-tinyhumans/src/jev/ranker.rs
new file mode 100644
index 0000000000..08de6dd073
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/jev/ranker.rs
@@ -0,0 +1,153 @@
+//! [`TinyHumansJevRanker`]: a `ToolRanker` that resolves the process's
+//! TinyHumans credential on every search and ranks through Jev.
+
+use std::{
+ collections::hash_map::DefaultHasher,
+ hash::{Hash, Hasher},
+ sync::Mutex,
+};
+
+use openhuman_core::api::config::effective_backend_api_url;
+use openhuman_core::config::Config;
+use openhuman_core::security::credentials::session_support::resolve_backend_credential;
+use tinytools::{RankCandidate, RankContext, RankError, RankHit, ToolRanker};
+use tinytools_jev::{ClientConfig, JevRanker, JevRankerConfig};
+
+/// A [`JevRanker`] bound to whichever credential and backend the process has
+/// at search time.
+pub struct TinyHumansJevRanker {
+ config: JevRankerConfig,
+ cached: Mutex<Option<Cached>>,
+}
+
+struct Cached {
+ fingerprint: u64,
+ ranker: JevRanker,
+}
+
+impl std::fmt::Debug for TinyHumansJevRanker {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("TinyHumansJevRanker")
+ .field("config", &self.config)
+ .finish_non_exhaustive()
+ }
+}
+
+impl Default for TinyHumansJevRanker {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl TinyHumansJevRanker {
+ /// A ranker with `tinytools-jev`'s defaults: BM25 retrieval to 20, one
+ /// Jev decision, a 3 s deadline.
+ pub fn new() -> Self {
+ Self::with_config(JevRankerConfig::new())
+ }
+
+ /// A ranker with an explicit `tinytools-jev` configuration.
+ pub fn with_config(config: JevRankerConfig) -> Self {
+ Self {
+ config,
+ cached: Mutex::new(None),
+ }
+ }
+
+ /// The `JevRanker` for the current credential and backend, built or
+ /// reused.
+ ///
+ /// Reads the config and credential fresh each time: the cost is a config
+ /// load, which a `tool_search` (one model round trip plus a network call)
+ /// dwarfs, and the benefit is that sign-in, sign-out and a backend URL
+ /// change are all honoured by the next search.
+ async fn current(&self) -> Result<JevRanker, RankError> {
+ let config = Config::load_or_init()
+ .await
+ .map_err(|error| RankError::Backend {
+ reason: format!("config unavailable: {error:#}"),
+ })?;
+ let credential = resolve_backend_credential(&config).map_err(|reason| {
+ // The message names what is missing, never a secret.
+ RankError::Backend {
+ reason: format!("no TinyHumans credential ({reason})"),
+ }
+ })?;
+ let base_url = effective_backend_api_url(&config.api_url);
+ let fingerprint = fingerprint(credential.secret(), &base_url);
+
+ let mut cached = self
+ .cached
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner());
+ if let Some(entry) = cached.as_ref()
+ && entry.fingerprint == fingerprint
+ {
+ return Ok(entry.ranker.clone());
+ }
+ let mut client = ClientConfig::tinyhumans_openrouter(credential.into_secret());
+ client.base_url = base_url.clone();
+ let ranker = JevRanker::from_config(client, self.config.clone())?;
+ log::info!(
+ "[tool-search] jev ranker bound to backend {} ({})",
+ openhuman_core::api::config::redact_url_for_log(&base_url),
+ if fingerprint_changed(cached.as_ref(), fingerprint) {
+ "credential or backend changed"
+ } else {
+ "first search"
+ }
+ );
+ *cached = Some(Cached {
+ fingerprint,
+ ranker: ranker.clone(),
+ });
+ Ok(ranker)
+ }
+}
+
+fn fingerprint(secret: &str, base_url: &str) -> u64 {
+ let mut hasher = DefaultHasher::new();
+ secret.hash(&mut hasher);
+ base_url.hash(&mut hasher);
+ hasher.finish()
+}
+
+fn fingerprint_changed(cached: Option<&Cached>, fingerprint: u64) -> bool {
+ cached.is_some_and(|entry| entry.fingerprint != fingerprint)
+}
+
+#[async_trait::async_trait]
+impl ToolRanker for TinyHumansJevRanker {
+ fn kind(&self) -> &'static str {
+ JevRanker::KIND
+ }
+
+ async fn rank(
+ &self,
+ intent: &str,
+ context: &RankContext,
+ candidates: &[RankCandidate],
+ limit: usize,
+ ) -> Result<Vec<RankHit>, RankError> {
+ let ranker = self.current().await?;
+ let ranking = ranker
+ .rank_detailed(intent, context, candidates, limit)
+ .await?;
+ log::debug!(
+ "[tool-search] jev ranked {} of {} shortlisted (choice_confidence={:.2} needs_tool={:?} none={:.2} latency_ms={} attempts={} input_tokens={:?})",
+ ranking.hits.len(),
+ ranking.shortlisted,
+ ranking.choice_confidence,
+ ranking.needs_tool,
+ ranking.none_probability,
+ ranking.latency.as_millis(),
+ ranking.attempts,
+ ranking.input_tokens,
+ );
+ Ok(ranking.hits)
+ }
+}
+
+#[cfg(test)]
+#[path = "ranker_tests.rs"]
+mod tests;