Skip to content

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

feat(search): add configurable search provider settings

Steven Enamakel15c4f73be90a
diff --git a/Cargo.lock b/Cargo.lock
index b008a41b33..eb890de737 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8162,6 +8162,7 @@ dependencies = [
name = "tinysearch-bus"
version = "0.5.0"
dependencies = [
+ "schemars",
"serde",
"serde_json",
]
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 77a03eb30c..b99d5fe2f3 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -238,7 +238,7 @@ tinychannels-bus = { version = "0.1", path = "../../vendor/tinychannels/crates/t
# --features flows` would carry `ureq` and the archive stack for a host that
# never loads a module. The kernel-floor ratchet catches exactly that, and did.
tinybus = { path = "../../vendor/tinybus/crates/tinybus", default-features = false, features = ["macros", "uds"] }
-tinysearch-bus = { path = "../../vendor/tinysearch/crates/tinysearch-bus" }
+tinysearch-bus = { path = "../../vendor/tinysearch/crates/tinysearch-bus", features = ["schemars"] }
# Registry vocabulary is available even when the loader is disabled, so the
# pre-core client can identify and report an unavailable module safely.
tinycomputer-bus = { path = "../../vendor/tinycomputer/crates/tinycomputer-bus" }
diff --git a/crates/openhuman-core/src/config/ops/search.rs b/crates/openhuman-core/src/config/ops/search.rs
index 60edbfacdc..e9cc060c37 100644
--- a/crates/openhuman-core/src/config/ops/search.rs
+++ b/crates/openhuman-core/src/config/ops/search.rs
@@ -14,7 +14,8 @@ use crate::config::{
Config, PresentationMode, ProviderRoute, MANAGED_SEARCH_PROVIDERS, SEARCH_PROVIDERS,
};
use crate::core::Outcome;
-use crate::search::providers::{self, parse_role, role_key, ROLES};
+use crate::search::providers;
+use tinysearch_bus::{parse_role, role_key, ROLES};
use super::loader::load_config_with_timeout;
@@ -92,9 +93,9 @@ fn supported_routes(provider: &str) -> Vec<&'static str> {
let managed = MANAGED_SEARCH_PROVIDERS.contains(&provider);
let mut routes = Vec::new();
if managed {
- routes.push(ProviderRoute::Backend.as_str());
+ routes.push(ProviderRoute::Backend.config_name());
}
- routes.push(ProviderRoute::Direct.as_str());
+ routes.push(ProviderRoute::Direct.config_name());
routes
}
@@ -114,10 +115,10 @@ fn apply_provider_patch(
if let Some(route) = patch.route.as_deref() {
let route = ProviderRoute::parse(route)
.ok_or_else(|| format!("route must be managed or direct (got {route:?})"))?;
- if !supported_routes(provider).contains(&route.as_str()) {
+ if !supported_routes(provider).contains(&route.config_name()) {
return Err(format!(
"{provider} does not support the {} route",
- route.as_str()
+ route.config_name()
));
}
let default_enabled = patch.enabled.unwrap_or(true);
@@ -333,7 +334,7 @@ pub(crate) fn search_settings_json_with(config: &Config, managed_available: bool
"id": p.id,
"label": label(p.id),
"enabled": p.enabled,
- "route": p.route.as_str(),
+ "route": p.route.config_name(),
"routes": supported_routes(p.id),
"managed_available": p.managed_available,
"key_configured": p.key_configured,
diff --git a/crates/openhuman-core/src/modules/search/mod.rs b/crates/openhuman-core/src/modules/search/mod.rs
index f434c7a522..c15e5c851a 100644
--- a/crates/openhuman-core/src/modules/search/mod.rs
+++ b/crates/openhuman-core/src/modules/search/mod.rs
@@ -11,12 +11,13 @@
use std::collections::BTreeMap;
use tinysearch_bus::{
- BackendAuthMode, BackendConfig, PresentationConfig, PresentationMode, ProviderConfig,
+ BackendAuthMode, BackendConfig, PresentationConfig, ProviderConfig,
ProviderRoute, SearchConfig as ModuleSearchConfig,
};
use crate::config::Config;
-use crate::search::providers::{self, ResolvedProvider, ROLES};
+use crate::search::providers::{self, ResolvedProvider};
+use tinysearch_bus::ROLES;
mod proxy;
diff --git a/crates/openhuman-core/src/profiles/provider_settings.rs b/crates/openhuman-core/src/profiles/provider_settings.rs
index fcab373c3a..a45a561a1d 100644
--- a/crates/openhuman-core/src/profiles/provider_settings.rs
+++ b/crates/openhuman-core/src/profiles/provider_settings.rs
@@ -10,7 +10,6 @@ use crate::config::{
};
use crate::core::runtime::direct_profile_provider::{validate_endpoint, DirectProfileProvider};
use crate::core::runtime::SaasConfig;
-use crate::search::providers;
use std::collections::{BTreeMap, HashSet};
use std::sync::Arc;
use tinysearch_bus::Role;
@@ -127,7 +126,7 @@ impl ProfileProviderSettings {
]);
let role_names = saas.search_role_names.clone();
let mut used = HashSet::new();
- for role in crate::search::providers::ROLES {
+ for role in tinysearch_bus::ROLES {
let canonical = tinysearch_bus::names::role_tool_name(role);
let name = role_names
.get(&role)
@@ -186,7 +185,7 @@ impl ProfileProviderSettings {
/// An advertised role maps exactly once to its canonical module operation.
/// Renamed canonical operations and provider-native names never resolve.
pub fn canonical_role_name(&self, advertised: &str) -> Option<&'static str> {
- crate::search::providers::ROLES
+ tinysearch_bus::ROLES
.into_iter()
.find_map(|role| {
(self.advertised_role_name(role) == advertised)
@@ -213,7 +212,7 @@ impl ProfileProviderSettings {
if self
.search
.roles
- .get(providers::role_key(role))
+ .get(tinysearch_bus::role_key(role))
.is_none_or(Vec::is_empty)
{
return false;
diff --git a/crates/openhuman-core/src/search/tools.rs b/crates/openhuman-core/src/search/tools.rs
index f1c86e651c..992a60a29e 100644
--- a/crates/openhuman-core/src/search/tools.rs
+++ b/crates/openhuman-core/src/search/tools.rs
@@ -129,33 +129,36 @@ impl TinySearchTool {
/// classified failures with `tinysearch.<code>:`; the detail after the prefix
/// may echo the query, so it is not logged.
pub fn user_facing_error(error: &str) -> String {
- match error_code(error) {
- Some(code) if code == errors::INSUFFICIENT_BALANCE => {
+ let code = errors::code_of(error);
+ match errors::classify(error) {
+ Category::InsufficientBalance => {
"Web search is unavailable: the TinyHumans balance is too low for managed search. \
Top up the balance, or add your own provider key under Connections → Search."
.to_string()
}
- Some(code) if code == errors::RATE_LIMITED => {
+ Category::RateLimited => {
"Web search is rate limited right now. Wait a moment and try again.".to_string()
}
- Some(code) if code == errors::UNAVAILABLE => SEARCH_EXHAUSTED_MESSAGE.to_string(),
- Some(code) if code == errors::PROVIDER_UNAUTHORIZED => {
+ Category::Exhausted => SEARCH_EXHAUSTED_MESSAGE.to_string(),
+ Category::Unauthorized if code == Some(errors::BACKEND_UNAUTHORIZED) => {
+ backend_unauthorized_message(false)
+ }
+ Category::Unauthorized => {
// The detail names the provider and its HTTP status; the module
// never puts the key or the query in it.
format!(
"Web search is unavailable: {}. Update the key under Connections → Search, or \
remove it to use managed search.",
- code_detail(error, code)
+ code_detail(error, code.unwrap_or_default())
)
}
- Some(code) if code == errors::BACKEND_UNAUTHORIZED => backend_unauthorized_message(false),
- Some(code) if code == errors::INVALID_ARGUMENTS => {
+ Category::InvalidArguments => {
format!(
"The search request was rejected: {}",
- code_detail(error, code)
+ code_detail(error, code.unwrap_or_default())
)
}
- _ => format!("Web search failed: {error}"),
+ Category::Unclassified => format!("Web search failed: {error}"),
}
}
@@ -200,21 +203,6 @@ fn on_backend_unauthorized(tool: &str, api_key: bool) {
});
}
-/// The classified error code in a module error message, if any.
-pub fn error_code(error: &str) -> Option<&'static str> {
- errors::code_of(error)
-}
-
-/// Whether this failure means no provider can answer for the rest of the
-/// session, rather than something a later call could get past.
-///
-/// Only the "every provider is unavailable" verdict qualifies. A rate limit
-/// clears on its own, and a low balance or a rejected argument has its own
-/// message telling the caller what to change, so neither latches.
-pub(crate) fn exhausts_providers(error: &str) -> bool {
- error_code(error) == Some(errors::UNAVAILABLE)
-}
-
#[async_trait]
impl Tool for TinySearchTool {
fn name(&self) -> &str {
@@ -304,10 +292,10 @@ impl Tool for TinySearchTool {
))
}
Err(error) => {
- if exhausts_providers(&error) {
+ if errors::exhausts_providers(&error) {
self.mark_exhausted_for(signature);
}
- if error_code(&error) == Some(errors::BACKEND_UNAUTHORIZED) {
+ if errors::code_of(&error) == Some(errors::BACKEND_UNAUTHORIZED) {
let api_key = crate::security::credentials::api_key::has_api_key(&config);
on_backend_unauthorized(&self.spec.name, api_key);
tracing::warn!(
@@ -319,11 +307,11 @@ impl Tool for TinySearchTool {
}
tracing::warn!(
tool = %self.spec.name,
- code = error_code(&error).unwrap_or("unclassified"),
+ code = errors::code_of(&error).unwrap_or("unclassified"),
exhausted = self.is_exhausted_for(signature),
"[search][tool] failed"
);
- Ok(if exhausts_providers(&error) {
+ Ok(if errors::exhausts_providers(&error) {
ToolResult::failed(user_facing_error(&error))
} else {
ToolResult::error(user_facing_error(&error))