Skip to content

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

refactor(tokenjuice): centralize tool-summary and companion-tool logic

Steven Enamakelf972808b46b4
diff --git a/crates/openhuman-core/src/agent/session_host/builder/mod.rs b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
index 5b7539a453..e7213bb89b 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
@@ -250,7 +250,7 @@ pub(super) fn ensure_repl_tools_visible(
/// Whether TinyJuice may summarize this agent's tool output. Only the
/// orchestrator gets a summary model, and a zero threshold turns it off.
pub(super) fn summarizes_tool_output(agent_id: &str, config: &crate::config::Config) -> bool {
- agent_id == "orchestrator" && config.context.summarizer_payload_threshold_tokens > 0
+ crate::inference::tokenjuice::summarizes_tool_output(agent_id, config)
}
pub(super) fn should_synthesize_delegation_tools(def: &AgentDefinition) -> bool {
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs b/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs
index c9bf437b27..4695764a74 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs
@@ -329,6 +329,23 @@ impl OpenHumanDefinitionRegistry {
if let Some(delegation_tools) = self.session_delegation_tools.as_deref() {
names.extend(delegation_tools.iter().cloned());
}
+ // A curated belt still has to reach the tools a compacted
+ // result names (`tinyjuice_retrieve`, `juice_find`, …). The
+ // session adds them to its visible set; without the same
+ // names here the harness allowlist rejects every call to them
+ // as an unknown tool. A zero-tool belt stays zero-tool.
+ if !named.is_empty() {
+ if let (Some(config), Some(registered)) =
+ (self.config.as_deref(), self.registered_tools.as_deref())
+ {
+ for name in crate::inference::tokenjuice::companion_tool_names(&def.id, config)
+ {
+ if registered.iter().any(|r| r == name) {
+ names.push(name.to_string());
+ }
+ }
+ }
+ }
// `extra_tools` is an "also include these" hook on top of a
// named scope. Under `Wildcard` it is meaningless — everything
// is already in scope.
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
index 6818348438..8f875b2c2c 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
@@ -49,6 +49,35 @@ pub fn repl_handle_active(config: &crate::config::Config) -> bool {
&& config.tokenjuice.repl_handle_enabled
}
+/// Whether TinyJuice may summarize this agent's tool output. Only the
+/// orchestrator gets a summary model, and a zero threshold turns it off.
+pub fn summarizes_tool_output(agent_id: &str, config: &crate::config::Config) -> bool {
+ agent_id == "orchestrator" && config.context.summarizer_payload_threshold_tokens > 0
+}
+
+/// The TinyJuice tools a compacted result can point the model at: the CCR
+/// recovery tool while anything can hand out a `⟦tj:…⟧` marker or a summary
+/// footer, plus the REPL tools while results are stored behind a handle.
+///
+/// This is the single list both the session's visible-tool set and the harness
+/// allowlist are built from. A name in the former but not the latter is
+/// advertised in the prompt and the tool declarations yet answered as an
+/// unknown tool at dispatch, so the model burns its failure budget on a tool it
+/// was told to call.
+pub fn companion_tool_names(
+ agent_id: &str,
+ config: &crate::config::Config,
+) -> Vec<&'static str> {
+ let mut names: Vec<&'static str> = Vec::new();
+ if config.context.compaction_enabled || summarizes_tool_output(agent_id, config) {
+ names.extend(RECOVERY_TOOL_VISIBLE.iter().copied());
+ }
+ if repl_handle_active(config) {
+ names.extend(REPL_TOOL_NAMES.iter().copied());
+ }
+ names
+}
+
/// Where the module writes a plain-text copy of each stored original when
/// `[tokenjuice] repl_save_enabled` is on.
pub fn repl_save_dir(workspace_dir: &std::path::Path) -> std::path::PathBuf {