Skip to content

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

feat(tokenjuice): add tool schema compression

Steven Enamakel0876d0cdf95f
diff --git a/crates/openhuman-core/src/inference/tokenjuice/tools.rs b/crates/openhuman-core/src/inference/tokenjuice/tools.rs
index 37f2bd1513..2df7407ed1 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/tools.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/tools.rs
@@ -1,4 +1,4 @@
-//! Agent tool: `tokenjuice_retrieve` — fetch the original of a compacted result.
+//! Agent tool: `juice_retrieve` — fetch the original of a compacted result.
//!
//! The content router may replace a large tool result with a compacted view and
//! a `⟦tj:<hash>⟧` marker, stashing the original in the CCR store
@@ -77,9 +77,10 @@ impl Tool for TokenjuiceRetrieveTool {
.map(str::trim)
.filter(|s| !s.is_empty());
let Some(token) = token else {
- return Ok(ToolResult::error(
- "tokenjuice_retrieve: missing required 'token' argument".to_string(),
- ));
+ return Ok(ToolResult::error(format!(
+ "{}: missing required 'token' argument",
+ super::RETRIEVE_TOOL_NAME
+ )));
};
// Optional range.
@@ -130,12 +131,13 @@ fn miss_message(token: &str) -> String {
// parent agent re-delegated forever on an evicted subagent result). Tell the
// model to proceed with the compacted summary it already has instead.
format!(
- "tokenjuice_retrieve: the full original for token '{token}' is no longer cached \
+ "{tool}: the full original for token '{token}' is no longer cached \
(evicted, or from an earlier session). Do NOT re-run the same tool call to \
regenerate it — that will produce the same oversized result and be 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."
+ query, filter, or smaller limit) so the result is small enough to keep in full.",
+ tool = super::RETRIEVE_TOOL_NAME
)
}
diff --git a/crates/openhuman-core/src/inference/tokenjuice/tools_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/tools_tests.rs
index fad606631b..49980a7f2c 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/tools_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/tools_tests.rs
@@ -39,3 +39,20 @@ fn miss_message_does_not_instruct_a_blind_re_run() {
"must point at the summary: {msg}"
);
}
+
+#[tokio::test]
+async fn retrieve_messages_name_only_the_tool_the_model_can_call() {
+ // `tokenjuice_retrieve` / `tinyjuice_retrieve` are dispatch aliases for old
+ // transcripts, not tools a model is offered. A message naming them sends the
+ // model after a tool it cannot see ("unknown tool").
+ let missing = TokenjuiceRetrieveTool::new()
+ .execute(json!({}))
+ .await
+ .unwrap()
+ .output();
+ for msg in [missing, miss_message("deadbeefcafe")] {
+ assert!(msg.contains(crate::inference::tokenjuice::RETRIEVE_TOOL_NAME), "{msg}");
+ assert!(!msg.contains("tokenjuice_retrieve"), "{msg}");
+ assert!(!msg.contains("tinyjuice_retrieve"), "{msg}");
+ }
+}