Skip to content

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

fix(tokenjuice): read the advertised token key in retrieve_tool_output

M3gA-Mindb14928e21467
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.rs
index 6eb63f6a1c..7a5b56d6fe 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
@@ -52,14 +52,16 @@ impl Tool for RetrieveToolOutputTool {
}
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
- let hash = args
- .get("hash")
- .and_then(|v| v.as_str())
+ // 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)
- .filter(|s| !s.is_empty());
+ .find(|s| !s.is_empty());
let Some(hash) = hash else {
return Ok(ToolResult::error(
- "retrieve_tool_output: missing required 'hash' argument".to_string(),
+ "retrieve_tool_output: missing required 'token' argument".to_string(),
));
};
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.rs
index 720f2a3d4c..0a7e6a51b9 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
@@ -18,3 +18,31 @@ async fn an_unreachable_store_is_reported_as_a_tool_error() {
.unwrap();
assert!(res.is_error);
}
+
+fn echoing_tool() -> RetrieveToolOutputTool {
+ RetrieveToolOutputTool::new(Arc::new(|key| {
+ Box::pin(async move { Ok(Some(format!("original for {key}"))) })
+ }))
+}
+
+#[tokio::test]
+async fn the_advertised_token_key_retrieves_the_original() {
+ let schema = echoing_tool().parameters_schema();
+ assert_eq!(schema["required"], json!(["token"]));
+ let res = echoing_tool()
+ .execute(json!({ "token": "abc123" }))
+ .await
+ .unwrap();
+ assert!(!res.is_error);
+ assert_eq!(res.output(), "original for abc123");
+}
+
+#[tokio::test]
+async fn the_legacy_hash_key_still_retrieves_the_original() {
+ let res = echoing_tool()
+ .execute(json!({ "hash": "abc123" }))
+ .await
+ .unwrap();
+ assert!(!res.is_error);
+ assert_eq!(res.output(), "original for abc123");
+}