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
fix(tokenjuice): delegate retrieve_tool_output to juice_retrieve
M3gA-Mind4b97ca8b336b
diff --git a/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output.rs b/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output.rsindex 7a5b56d6fe..0f2c6a24f2 100644--- a/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output.rs+++ b/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output.rs@@ -1,35 +1,32 @@//! Tool: retrieve_tool_output — fetch the original of a compacted tool result.//!-//! Native tool-output compaction (Stage 1a) may replace a large tool result-//! with a compacted view and a `retrieve_tool_output("<hash>")` sentinel,-//! stashing the original in the TokenJuice store. This tool hands the original-//! back on demand, so even lossy compaction stays reversible.+//! The legacy name for TinyJuice's `juice_retrieve`. Native tool-output+//! compaction (Stage 1a) hands out a `retrieve_tool_output("<hash>")` sentinel,+//! and models keep calling this name. It advertises the same schema as+//! `juice_retrieve` (`token`, optional `range`), so it delegates to that tool+//! and only keeps its own name: the arguments, the `hash` fallback, the range+//! slice and the eviction message all stay in one implementation.//!//! Read-only, no side effects, no path/network access.-use std::future::Future;-use std::pin::Pin;use std::sync::Arc;use async_trait::async_trait;+use tinyjuice_host::retrieve_tool::{RetrieveFn, RetrieveToolOutputTool as JuiceRetrieveTool};use tinytools::{PermissionLevel, Tool, ToolResult};-/// Looks a stored original up by hash: `Ok(None)` is a cache miss.-pub type RetrieveFn = Arc<- dyn Fn(String) -> Pin<Box<dyn Future<Output = Result<Option<String>, String>> + Send>>- + Send- + Sync,->;-/// The `retrieve_tool_output` tool, bound to a host-supplied lookup.pub struct RetrieveToolOutputTool {- retrieve: RetrieveFn,+ inner: JuiceRetrieveTool,}impl RetrieveToolOutputTool {- /// Build the tool over `retrieve`, which resolves a hash to the original.+ /// Build the tool over `retrieve`, which resolves a token (and optional+ /// range) to the original.pub fn new(retrieve: RetrieveFn) -> Self {- Self { retrieve }+ Self {+ inner: JuiceRetrieveTool::new(retrieve),+ }}}@@ -40,65 +37,34 @@ impl Tool for RetrieveToolOutputTool {}fn description(&self) -> &str {- tinyjuice_bus::tools::RETRIEVE_TOOL_DESCRIPTION+ self.inner.description()}fn parameters_schema(&self) -> serde_json::Value {- tinyjuice_bus::tools::retrieve_tool_parameters()+ self.inner.parameters_schema()}fn permission_level(&self) -> PermissionLevel {- PermissionLevel::ReadOnly+ self.inner.permission_level()}- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {- // The advertised schema is TinyJuice's, which names the key `token`;- // `hash` is the legacy spelling from the Stage 1a sentinel.- let hash = ["token", "hash"]- .iter()- .filter_map(|key| args.get(*key).and_then(|v| v.as_str()))- .map(str::trim)- .find(|s| !s.is_empty());- let Some(hash) = hash else {- return Ok(ToolResult::error(- "retrieve_tool_output: missing required 'token' argument".to_string(),- ));- };+ fn is_concurrency_safe(&self, args: &serde_json::Value) -> bool {+ self.inner.is_concurrency_safe(args)+ }- match (self.retrieve)(hash.to_string()).await {- Ok(Some(original)) => {- log::debug!(- "[compaction][ccr] retrieved hash={} bytes={}",- hash,- original.len()- );- Ok(ToolResult::success(original))- }- // Deliberately does NOT say "re-run the tool". Re-running- // regenerates the same oversized result, which is compacted and- // offloaded again under a new hash that can be evicted just as fast- // — so a blind re-run turns one cache miss into an unbounded- // compact→retrieve→re-run loop (observed live: a parent agent- // re-delegated forever on an evicted subagent result). Tell the- // model to proceed with the compacted summary it already has.- Ok(None) => Ok(ToolResult::error(format!(- "retrieve_tool_output: the full original for hash '{hash}' is no longer \- cached (evicted, or from an earlier session). Do NOT re-run the same tool \- call to regenerate it — that produces the same oversized result and is \- compacted again. Proceed using the compacted summary already shown above; \- only if a specific missing detail is essential, retry with narrower \- arguments (a tighter query, filter, or smaller limit) so the result is \- small enough to keep in full."- ))),- Err(error) => Ok(ToolResult::error(error)),- }+ fn external_effect(&self) -> bool {+ self.inner.external_effect()+ }++ async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {+ self.inner.execute(args).await}}/// Bind the recovery tool to the module-owned cache.pub fn retrieve_tool_output_tool() -> RetrieveToolOutputTool {- RetrieveToolOutputTool::new(Arc::new(|hash| {- Box::pin(async move { crate::inference::tokenjuice::retrieve(hash, None).await })+ RetrieveToolOutputTool::new(Arc::new(|token, range| {+ Box::pin(async move { crate::inference::tokenjuice::retrieve(token, range).await })}))}diff --git a/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output_tests.rs b/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output_tests.rsindex 0a7e6a51b9..a91890b9f9 100644--- a/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output_tests.rs+++ b/crates/openhuman-core/src/tools/impl/system/retrieve_tool_output_tests.rs@@ -20,29 +20,40 @@ async fn an_unreachable_store_is_reported_as_a_tool_error() {}fn echoing_tool() -> RetrieveToolOutputTool {- RetrieveToolOutputTool::new(Arc::new(|key| {- Box::pin(async move { Ok(Some(format!("original for {key}"))) })- }))+ RetrieveToolOutputTool::new(Arc::new(+ |key: String, range: Option<tinyjuice_bus::wire::RetrieveRange>| {+ let span = range.map(|r| (r.start, r.end));+ Box::pin(async move { Ok(Some(format!("original for {key} {span:?}"))) })+ },+ ))}#[tokio::test]async fn the_advertised_token_key_retrieves_the_original() {- let schema = echoing_tool().parameters_schema();- assert_eq!(schema["required"], json!(["token"]));+ let tool = echoing_tool();+ assert_eq!(tool.name(), "retrieve_tool_output");+ assert_eq!(tool.parameters_schema()["required"], json!(["token"]));+ let res = tool.execute(json!({ "token": "abc123" })).await.unwrap();+ assert!(!res.is_error);+ assert_eq!(res.output(), "original for abc123 None");+}++#[tokio::test]+async fn the_legacy_hash_key_still_retrieves_the_original() {let res = echoing_tool()- .execute(json!({ "token": "abc123" }))+ .execute(json!({ "hash": "abc123" })).await.unwrap();assert!(!res.is_error);- assert_eq!(res.output(), "original for abc123");+ assert_eq!(res.output(), "original for abc123 None");}#[tokio::test]-async fn the_legacy_hash_key_still_retrieves_the_original() {+async fn a_requested_range_is_forwarded_to_the_lookup() {let res = echoing_tool()- .execute(json!({ "hash": "abc123" }))+ .execute(json!({ "token": "abc123", "range": { "start": 2, "end": 5 } })).await.unwrap();assert!(!res.is_error);- assert_eq!(res.output(), "original for abc123");+ assert_eq!(res.output(), "original for abc123 Some((2, 5))");}