The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(tinyagents): move web_fetch host and policy logic into fetched_site module
Steven Enamakelcfa95ca8fb5f
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rsindex afcbe9b8b8..d54ddd1b3b 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rs@@ -28,28 +28,42 @@ pub(super) fn fetched_site_status(text: &str) -> Option<u16> {(!host.is_empty() && !host.contains(char::is_whitespace)).then_some(status)}-/// Recovery class and retry budget for a fetched site's `status`.+/// Recovery policy for a `web_fetch` error carrying a fetched site's status:+/// `None` when `tool`/`error` are not that shape (the caller classifies as+/// usual), otherwise the policy to return, itself `None` for an ordinary+/// failure.////// - 401/403: the site refused us. Another page or source may still work, so/// the run continues, but the same host refusing repeatedly stops it./// - 429 and 5xx: transient, with the usual retry headroom./// - anything else (404, 410, 400, ...): an ordinary tool failure with no/// classified budget; the exact-repeat guard bounds it.-pub(super) fn site_status_policy(status: u16) -> Option<(&'static str, usize)> {+pub(super) fn fetched_site_policy(+ tool: &str,+ error: &str,+) -> Option<Option<(&'static str, usize)>> {+ if tool != WEB_FETCH_TOOL {+ return None;+ }+ let status = fetched_site_status(error)?;tracing::debug!(status,"[tinyagents::mw] web_fetch site status — not a credential failure");- match status {+ Some(match status {401 | 403 => Some(("site_refused", 2)),429 | 500..=599 => Some(("transient", 2)),_ => None,- }+ })}-/// The host of `url`, if it parses.-pub(super) fn url_host(url: &str) -> Option<String> {- url::Url::parse(url)- .ok()- .and_then(|u| u.host_str().map(str::to_owned))+/// The failure-scope part for a `web_fetch` `url` argument: its host. A site+/// decides whether to serve us per host, not per page, so a model walking a+/// blocked site's pages shares one budget instead of a fresh one per URL.+pub(super) fn fetch_host_scope(tool: &str, field: &str, value: &str) -> Option<String> {+ if tool != WEB_FETCH_TOOL || field != "url" {+ return None;+ }+ let url = url::Url::parse(value).ok()?;+ Some(format!(":host={}", url.host_str()?))}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex c096f94933..7944ad8f25 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -19,7 +19,7 @@ use tinyinference_llm::model::ModelRequest;use tinyinference_llm::tool::ToolCall as TaToolCall;use tinytools::ToolResult as TaToolResult;-use super::fetched_site::{fetched_site_status, site_status_policy, url_host, WEB_FETCH_TOOL};+use super::fetched_site::{fetch_host_scope, fetched_site_policy};use super::loop_guards::{is_repeat_call_exempt, RECOVERABLE_NO_PROGRESS_FAILURE_THRESHOLD,RECOVERABLE_REPEAT_FAILURE_THRESHOLD,@@ -217,15 +217,9 @@ pub(super) fn failure_scope(tool: &str, arguments: &serde_json::Value) -> StringSome(serde_json::Value::Number(value)) => value.to_string(),_ => continue,};- // A site decides whether to serve us per host, not per page: scope a- // fetch by host so a model walking a blocked site's pages shares one- // budget instead of getting a fresh one for every URL.- if tool == WEB_FETCH_TOOL && field == "url" {- if let Some(host) = url_host(&value) {- scope.push_str(":host=");- scope.push_str(&host);- continue;- }+ if let Some(host_scope) = fetch_host_scope(tool, field, &value) {+ scope.push_str(&host_scope);+ continue;}scope.push(':');scope.push_str(field);@@ -317,12 +311,9 @@ fn classified_recovery_policy({return Some(("unavailable", 1));}- // A public website refusing or failing a fetch says nothing about- // OpenHuman's credentials; only `web_fetch` is exempt (see `fetched_site`).- if tool == WEB_FETCH_TOOL {- if let Some(status) = fetched_site_status(error) {- return site_status_policy(status);- }+ // A site's refusal is not our credential failure (see `fetched_site`).+ if let Some(policy) = fetched_site_policy(tool, error) {+ return policy;}// A tool-owned JSON error contract is less ambiguous than rendered prose.// Read only explicit status/code fields; arbitrary response data is not a