Skip to content

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

fix(jev): adapt rankers to evaluator API

Steven Enamakel3b42115b041d
diff --git a/crates/openhuman-app/Cargo.lock b/crates/openhuman-app/Cargo.lock
index ccd6d8e8a0..4f2cdb3e14 100644
--- a/crates/openhuman-app/Cargo.lock
+++ b/crates/openhuman-app/Cargo.lock
@@ -4296,8 +4296,8 @@ dependencies = [
"tinymemory-sources",
"tinyruntime-bus",
"tinyskills",
- "tinytools 0.3.0",
- "tinytools-agent 0.3.0",
+ "tinytools 0.4.1",
+ "tinytools-agent 0.4.1",
"tinyvoice-bus",
"tinywallet-bus",
"tokio",
@@ -4410,6 +4410,8 @@ dependencies = [
"serde_json",
"thiserror 2.0.20",
"tinyhumans-sdk",
+ "tinytools 0.4.1",
+ "tinytools-jev",
"tokio",
"url",
"urlencoding",
@@ -7033,7 +7035,7 @@ dependencies = [
"serde_json",
"tinyagents-harness",
"tinyinference-llm",
- "tinytools 0.3.0",
+ "tinytools 0.4.1",
"tokio",
"tracing",
]
@@ -7060,8 +7062,8 @@ dependencies = [
"tinyagents-definition",
"tinyinference-embeddings",
"tinyinference-llm",
- "tinytools 0.3.0",
- "tinytools-agent 0.3.0",
+ "tinytools 0.4.1",
+ "tinytools-agent 0.4.1",
"tokio",
"tracing",
"uuid",
@@ -7084,7 +7086,7 @@ dependencies = [
"tinyagents-runtime",
"tinyagents-session",
"tinyinference-llm",
- "tinytools 0.3.0",
+ "tinytools 0.4.1",
"tokio",
"uuid",
]
@@ -7100,7 +7102,7 @@ dependencies = [
"tinyagents-definition",
"tinyagents-harness",
"tinyinference-llm",
- "tinytools 0.3.0",
+ "tinytools 0.4.1",
]
[[package]]
@@ -7113,7 +7115,7 @@ dependencies = [
"tinyagents-harness",
"tinyagents-session",
"tinyinference-llm",
- "tinytools 0.3.0",
+ "tinytools 0.4.1",
"tokio",
]
@@ -7409,7 +7411,7 @@ dependencies = [
"sha2 0.11.0",
"thiserror 2.0.20",
"tinyinference-core",
- "tinytools-agent 0.3.0 (git+https://github.com/tinyhumansai/tinytools?rev=a5d04a7f3af0abc1dd748f87f94871b36ae9fe71)",
+ "tinytools-agent 0.3.0",
"tokio",
"tracing",
]
@@ -7590,6 +7592,7 @@ dependencies = [
[[package]]
name = "tinytools"
version = "0.3.0"
+source = "git+https://github.com/tinyhumansai/tinytools?rev=a5d04a7f3af0abc1dd748f87f94871b36ae9fe71#a5d04a7f3af0abc1dd748f87f94871b36ae9fe71"
dependencies = [
"anyhow",
"async-trait",
@@ -7599,8 +7602,7 @@ dependencies = [
[[package]]
name = "tinytools"
-version = "0.3.0"
-source = "git+https://github.com/tinyhumansai/tinytools?rev=a5d04a7f3af0abc1dd748f87f94871b36ae9fe71#a5d04a7f3af0abc1dd748f87f94871b36ae9fe71"
+version = "0.4.1"
dependencies = [
"anyhow",
"async-trait",
@@ -7611,6 +7613,7 @@ dependencies = [
[[package]]
name = "tinytools-agent"
version = "0.3.0"
+source = "git+https://github.com/tinyhumansai/tinytools?rev=a5d04a7f3af0abc1dd748f87f94871b36ae9fe71#a5d04a7f3af0abc1dd748f87f94871b36ae9fe71"
dependencies = [
"regex",
"serde",
@@ -7620,13 +7623,20 @@ dependencies = [
[[package]]
name = "tinytools-agent"
-version = "0.3.0"
-source = "git+https://github.com/tinyhumansai/tinytools?rev=a5d04a7f3af0abc1dd748f87f94871b36ae9fe71#a5d04a7f3af0abc1dd748f87f94871b36ae9fe71"
+version = "0.4.1"
dependencies = [
"regex",
"serde",
"serde_json",
- "tinytools 0.3.0 (git+https://github.com/tinyhumansai/tinytools?rev=a5d04a7f3af0abc1dd748f87f94871b36ae9fe71)",
+ "tinytools 0.4.1",
+]
+
+[[package]]
+name = "tinytools-jev"
+version = "0.4.1"
+dependencies = [
+ "async-trait",
+ "tinytools 0.4.1",
]
[[package]]
diff --git a/crates/openhuman-cli/src/bin/tool_search_bench.rs b/crates/openhuman-cli/src/bin/tool_search_bench.rs
index af68997e1c..4104df9ad1 100644
--- a/crates/openhuman-cli/src/bin/tool_search_bench.rs
+++ b/crates/openhuman-cli/src/bin/tool_search_bench.rs
@@ -34,7 +34,7 @@
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;
-use std::time::{Duration, Instant};
+use std::time::Instant;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
@@ -277,29 +277,125 @@ fn load_intents(path: &PathBuf) -> Result<Vec<IntentRow>> {
use openhuman_core::agent::tinyagents::discovery::OverlapRanker;
+#[cfg(feature = "jev")]
+#[derive(Debug)]
+struct BenchmarkJevEvaluator {
+ client: reqwest::Client,
+ endpoint: String,
+ api_key: String,
+}
+
+#[cfg(feature = "jev")]
+#[async_trait::async_trait]
+impl tinytools_jev::JevEvaluator for BenchmarkJevEvaluator {
+ async fn evaluate(
+ &self,
+ request: &tinytools_jev::JevRequest,
+ ) -> Result<tinytools_jev::JevDecision, tinytools::RankError> {
+ let criteria = request
+ .options
+ .iter()
+ .map(|option| {
+ (
+ option.key.clone(),
+ serde_json::Value::String(option.description.clone()),
+ )
+ })
+ .collect::<serde_json::Map<_, _>>();
+ let instructions = request.instructions.clone().unwrap_or_else(|| {
+ "Which tool accomplishes the user's `request`? Judge by what each tool does, not by shared words. Pick `none` when no listed tool does it.".into()
+ });
+ let response: serde_json::Value = self
+ .client
+ .post(&self.endpoint)
+ .bearer_auth(&self.api_key)
+ .json(&serde_json::json!({
+ "state": { "request": request.intent, "recent_user_turns": request.recent_turns },
+ "model": request.model,
+ "questions": {
+ "tool": { "type": "choice", "instructions": instructions, "criteria": criteria },
+ "needs_tool": { "type": "noul", "instructions": "Does fulfilling the user's `request` require calling a tool — an action or a lookup outside the assistant's own knowledge?" },
+ },
+ }))
+ .send()
+ .await
+ .map_err(|error| tinytools::RankError::Backend { reason: format!("Jev request failed: {error}") })?
+ .error_for_status()
+ .map_err(|error| tinytools::RankError::Backend { reason: format!("Jev request was rejected: {error}") })?
+ .json()
+ .await
+ .map_err(|error| tinytools::RankError::Backend { reason: format!("Jev response could not be decoded: {error}") })?;
+ let answers = response
+ .get("answers")
+ .and_then(serde_json::Value::as_object)
+ .ok_or_else(|| tinytools::RankError::Backend {
+ reason: "Jev response has no answers object".into(),
+ })?;
+ let tool = answers
+ .get("tool")
+ .ok_or_else(|| tinytools::RankError::Backend {
+ reason: "Jev response has no tool answer".into(),
+ })?;
+ Ok(tinytools_jev::JevDecision {
+ probabilities: serde_json::from_value(tool.get("probabilities").cloned().ok_or_else(
+ || tinytools::RankError::Backend {
+ reason: "Jev tool answer has no probabilities".into(),
+ },
+ )?)
+ .map_err(|error| tinytools::RankError::Backend {
+ reason: format!("Jev tool probabilities are invalid: {error}"),
+ })?,
+ choice_confidence: tool
+ .get("confidence")
+ .and_then(serde_json::Value::as_f64)
+ .ok_or_else(|| tinytools::RankError::Backend {
+ reason: "Jev tool answer has no confidence".into(),
+ })?,
+ needs_tool: answers
+ .get("needs_tool")
+ .and_then(|answer| answer.get("noul"))
+ .and_then(serde_json::Value::as_f64),
+ input_tokens: response
+ .get("usage")
+ .and_then(|usage| usage.get("input_tokens"))
+ .and_then(serde_json::Value::as_u64),
+ attempts: 1,
+ })
+ }
+}
+
#[cfg(feature = "jev")]
fn jev_ranker(retrieval_k: usize) -> Option<(Arc<dyn ToolRanker>, Arc<tinytools_jev::JevRanker>)> {
- use tinytools_jev::{ClientConfig, JevRanker, JevRankerConfig};
- let client = if let Ok(key) = std::env::var("OPENHUMAN_BACKEND_API_KEY") {
- let mut client = ClientConfig::tinyhumans_openrouter(key);
- if let Ok(base) = std::env::var("BACKEND_URL") {
- if !base.trim().is_empty() {
- client.base_url = base.trim().trim_end_matches('/').to_string();
- }
- }
- client
+ use tinytools_jev::{JevRanker, JevRankerConfig};
+ let (endpoint, api_key) = if let Ok(key) = std::env::var("OPENHUMAN_BACKEND_API_KEY") {
+ let base = std::env::var("BACKEND_URL")
+ .ok()
+ .filter(|base| !base.trim().is_empty())
+ .unwrap_or_else(|| "https://api.tinyhumans.ai".into());
+ (
+ format!(
+ "{}/agent-integrations/openrouter/systemone",
+ base.trim_end_matches('/')
+ ),
+ key,
+ )
} else if let Ok(key) = std::env::var("TYPESAFE_API_KEY") {
- ClientConfig::new(key)
+ ("https://api.typesafe.ai/v1/systemone".into(), key)
} else {
return None;
};
- let ranker = JevRanker::from_config(
- client,
- JevRankerConfig::new()
- .with_retrieval_k(retrieval_k)
- .with_timeout(Duration::from_secs(15)),
- )
- .ok()?;
+ let client = reqwest::Client::builder()
+ .timeout(std::time::Duration::from_secs(15))
+ .build()
+ .ok()?;
+ let ranker = JevRanker::new(
+ Arc::new(BenchmarkJevEvaluator {
+ client,
+ endpoint,
+ api_key,
+ }),
+ JevRankerConfig::new().with_retrieval_k(retrieval_k),
+ );
let ranker = Arc::new(ranker);
Some((ranker.clone() as Arc<dyn ToolRanker>, ranker))
}
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 0f503125ac..165df0fd9d 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1473,7 +1473,6 @@ impl OpenHumanSessionHost {
self.model_name.clone(),
self.temperature,
self.config.max_tool_iterations,
- self.config.max_history_messages,
self.model_vision,
self.run_queue.clone(),
self.workspace_descriptor.clone(),
diff --git a/crates/openhuman-tinyhumans/src/jev/ranker.rs b/crates/openhuman-tinyhumans/src/jev/ranker.rs
index 35c0a80975..f2cb5f4923 100644
--- a/crates/openhuman-tinyhumans/src/jev/ranker.rs
+++ b/crates/openhuman-tinyhumans/src/jev/ranker.rs
@@ -9,11 +9,17 @@ use std::{
use std::{future::Future, pin::Pin, sync::Arc};
+use async_trait::async_trait;
use openhuman_core::api::config::effective_backend_api_url;
+use openhuman_core::api::headers::build_backend_client;
+use openhuman_core::api::transport::TransportProfile;
use openhuman_core::config::Config;
use openhuman_core::security::credentials::session_support::resolve_backend_credential;
+use serde_json::{json, Value};
use tinytools::{RankCandidate, RankContext, RankError, RankHit, ToolRanker};
-use tinytools_jev::{ClientConfig, JevRanker, JevRankerConfig};
+use tinytools_jev::{JevDecision, JevEvaluator, JevRanker, JevRankerConfig, JevRequest};
+
+const SYSTEM_ONE_PATH: &str = "agent-integrations/openrouter/systemone";
/// How the ranker reads the config a search runs under. The default is the
/// core's own read path (the embedder's config when one is bound, else the
@@ -34,6 +40,127 @@ struct Cached {
ranker: JevRanker,
}
+/// OpenHuman's System One transport. `tinytools-jev` deliberately keeps this
+/// policy at the host boundary, where backend headers and credentials belong.
+struct TinyHumansJevEvaluator {
+ client: reqwest::Client,
+ base_url: String,
+ credential: String,
+}
+
+impl std::fmt::Debug for TinyHumansJevEvaluator {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("TinyHumansJevEvaluator")
+ .field("base_url", &self.base_url)
+ .finish_non_exhaustive()
+ }
+}
+
+#[async_trait]
+impl JevEvaluator for TinyHumansJevEvaluator {
+ async fn evaluate(&self, request: &JevRequest) -> Result<JevDecision, RankError> {
+ let response = self
+ .client
+ .post(format!(
+ "{}/{SYSTEM_ONE_PATH}",
+ self.base_url.trim_end_matches('/')
+ ))
+ .bearer_auth(&self.credential)
+ .json(&system_one_request(request))
+ .send()
+ .await
+ .map_err(|error| RankError::Backend {
+ reason: format!("Jev request failed: {error}"),
+ })?
+ .error_for_status()
+ .map_err(|error| RankError::Backend {
+ reason: format!("Jev request was rejected: {error}"),
+ })?;
+ let value: Value = response.json().await.map_err(|error| RankError::Backend {
+ reason: format!("Jev response could not be decoded: {error}"),
+ })?;
+ system_one_decision(value)
+ }
+}
+
+fn system_one_request(request: &JevRequest) -> Value {
+ let criteria = request
+ .options
+ .iter()
+ .map(|option| {
+ (
+ option.key.clone(),
+ Value::String(option.description.clone()),
+ )
+ })
+ .collect::<serde_json::Map<_, _>>();
+ let instructions = request.instructions.clone().unwrap_or_else(|| {
+ "Which tool accomplishes the user's `request`? Judge by what each tool does, not by shared words. Pick `none` when no listed tool does it.".into()
+ });
+ json!({
+ "state": {
+ "request": request.intent,
+ "recent_user_turns": request.recent_turns,
+ },
+ "model": request.model,
+ "questions": {
+ "tool": {
+ "type": "choice",
+ "instructions": instructions,
+ "criteria": criteria,
+ },
+ "needs_tool": {
+ "type": "noul",
+ "instructions": "Does fulfilling the user's `request` require calling a tool — an action or a lookup outside the assistant's own knowledge?",
+ "criteria": {
+ "true": "The request asks for an action or for information that must be fetched.",
+ "false": "The request can be answered by replying, with no tool.",
+ },
+ },
+ },
+ })
+}
+
+fn system_one_decision(value: Value) -> Result<JevDecision, RankError> {
+ let answers = value
+ .get("answers")
+ .and_then(Value::as_object)
+ .ok_or_else(|| RankError::Backend {
+ reason: "Jev response has no answers object".into(),
+ })?;
+ let tool = answers.get("tool").ok_or_else(|| RankError::Backend {
+ reason: "Jev response has no tool answer".into(),
+ })?;
+ let probabilities =
+ serde_json::from_value(tool.get("probabilities").cloned().ok_or_else(|| {
+ RankError::Backend {
+ reason: "Jev tool answer has no probabilities".into(),
+ }
+ })?)
+ .map_err(|error| RankError::Backend {
+ reason: format!("Jev tool probabilities are invalid: {error}"),
+ })?;
+ let choice_confidence = tool
+ .get("confidence")
+ .and_then(Value::as_f64)
+ .ok_or_else(|| RankError::Backend {
+ reason: "Jev tool answer has no confidence".into(),
+ })?;
+ Ok(JevDecision {
+ probabilities,
+ choice_confidence,
+ needs_tool: answers
+ .get("needs_tool")
+ .and_then(|answer| answer.get("noul"))
+ .and_then(Value::as_f64),
+ input_tokens: value
+ .get("usage")
+ .and_then(|usage| usage.get("input_tokens"))
+ .and_then(Value::as_u64),
+ attempts: 1,
+ })
+}
+
impl std::fmt::Debug for TinyHumansJevRanker {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TinyHumansJevRanker")
@@ -104,9 +231,16 @@ impl TinyHumansJevRanker {
{
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())?;
+ let evaluator = TinyHumansJevEvaluator {
+ client: build_backend_client(TransportProfile::Integrations).map_err(|error| {
+ RankError::Backend {
+ reason: format!("Jev client is unavailable: {error}"),
+ }
+ })?,
+ base_url: base_url.clone(),
+ credential: credential.into_secret(),
+ };
+ let ranker = JevRanker::new(Arc::new(evaluator), self.config.clone());
log::info!(
"[tool-search] jev ranker bound to backend {} ({})",
openhuman_core::util::redact::redact_url_for_log(&base_url),
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index db0996e48f..c790c78f68 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -43,7 +43,7 @@ const LEGACY_LIMITS = new Map([
// Merged upstream work added focused coverage and routing seams. These
// legacy files remain pinned at their post-merge sizes until split.
["crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs", 779],
- ["crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs", 796],
+ ["crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs", 799],
["crates/openhuman-core/src/tools/ops_tests_default_registry_tests.rs", 752],
]);