Skip to content

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

fix(tokenjuice): handle empty focus list in focus module

Steven Enamakel9a9270ac8928
diff --git a/crates/openhuman-core/src/inference/tokenjuice/focus.rs b/crates/openhuman-core/src/inference/tokenjuice/focus.rs
new file mode 100644
index 0000000000..4e1211fafd
--- /dev/null
+++ b/crates/openhuman-core/src/inference/tokenjuice/focus.rs
@@ -0,0 +1,36 @@
+//! `summary_focus`: the argument a tool opts into so its caller can steer the
+//! summary of a large result.
+//!
+//! A tool opts in by adding [`summary_focus_property`] to its schema's
+//! `properties`. `ToolOutputMiddleware` takes the value out of the call in
+//! `before_tool` — before schema validation and before the tool runs, so the
+//! tool body never sees it — and hands it to TinyJuice with the result.
+
+use serde_json::{json, Value};
+
+/// The argument's name on the wire.
+pub const SUMMARY_FOCUS_ARG: &str = "summary_focus";
+
+/// The schema for the optional `summary_focus` argument.
+pub fn summary_focus_property() -> Value {
+ json!({
+ "type": "string",
+ "description": "What you need from this result. A large result is summarized around \
+ this; the full output stays retrievable."
+ })
+}
+
+/// Remove `summary_focus` from a call's arguments, returning it when it holds
+/// non-blank text.
+pub fn take_summary_focus(arguments: &mut Value) -> Option<String> {
+ let removed = arguments.as_object_mut()?.remove(SUMMARY_FOCUS_ARG)?;
+ removed
+ .as_str()
+ .map(str::trim)
+ .filter(|focus| !focus.is_empty())
+ .map(str::to_string)
+}
+
+#[cfg(test)]
+#[path = "focus_tests.rs"]
+mod tests;