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
feat(inference): add tokenjuice schema definitions
Steven Enamakel33f0af5e3599
diff --git a/crates/openhuman-core/src/agent/session_host/builder/mod.rs b/crates/openhuman-core/src/agent/session_host/builder/mod.rsindex f8aadf92ed..4a76e3cd63 100644--- a/crates/openhuman-core/src/agent/session_host/builder/mod.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/mod.rs@@ -224,7 +224,8 @@ pub(super) fn ensure_tinyjuice_tools_visible() {ensure_recovery_tool_visible(visible,- config.context.compaction_enabled || summarizes_tool_output(agent_id, config),+ crate::inference::tokenjuice::enabled(config)+ && (config.context.compaction_enabled || summarizes_tool_output(agent_id, config)),);ensure_repl_tools_visible(visible,diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rsindex aac5293c4e..5714943bc6 100644--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs@@ -37,13 +37,21 @@ pub fn is_recovery_tool(name: &str) -> bool {RECOVERY_TOOL_NAMES.contains(&name)}+/// Whether the `[components] juice` switch is on. Off means turns truncate+/// tool output only: no compaction, no summary, no `juice_*` / recovery tools,+/// and the module is never loaded for it.+pub fn enabled(config: &crate::config::Config) -> bool {+ config.components.juice+}+/// Whether large results are stored behind a handle (stats, head, handle)/// instead of being compressed into one blob, and the REPL tools that query/// them are offered to the model. Needs the router, the CCR store the handle/// points into, and the compaction switch that lets the module rewrite results/// at all.pub fn repl_handle_active(config: &crate::config::Config) -> bool {- config.context.compaction_enabled+ enabled(config)+ && config.context.compaction_enabled&& config.tokenjuice.router_enabled&& config.tokenjuice.ccr_enabled&& config.tokenjuice.repl_handle_enabled@@ -52,7 +60,7 @@ pub fn repl_handle_active(config: &crate::config::Config) -> bool {/// 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+ enabled(config) && agent_id == "orchestrator" && config.context.summarizer_payload_threshold_tokens > 0}/// The TinyJuice tools a compacted result can point the model at: the CCR@@ -66,7 +74,9 @@ pub fn summarizes_tool_output(agent_id: &str, config: &crate::config::Config) ->/// 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) {+ if enabled(config)+ && (config.context.compaction_enabled || summarizes_tool_output(agent_id, config))+ {names.extend(RECOVERY_TOOL_VISIBLE.iter().copied());}if repl_handle_active(config) {@@ -119,6 +129,10 @@ pub(crate) fn install_request(config: &crate::config::Config) -> InstallRequest}pub async fn install_from_config(config: &crate::config::Config) -> Result<(), String> {+ if !enabled(config) {+ log::debug!("[tokenjuice] component disabled; module install skipped");+ return Ok(());+ }savings::configure(&client(config),configdiff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas.rsindex 31edb589ef..866cf0f97f 100644--- a/crates/openhuman-core/src/inference/tokenjuice/schemas.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas.rs@@ -263,12 +263,27 @@ pub fn schemas(function: &str) -> ControllerSchema {// ── Handlers ─────────────────────────────────────────────────────────+/// Refuse with the typed `COMPONENT_DISABLED:juice` error while `[components]+/// juice` is off. Read from the ambient core context (set at boot); a call with+/// no context is on, since the set only narrows.+fn gate() -> Result<(), String> {+ let on = crate::core::runtime::context::CoreContext::current()+ .map_or(true, |ctx| ctx.components().juice);+ if on {+ Ok(())+ } else {+ log::debug!("[tokenjuice][rpc] refused, component 'juice' disabled");+ Err(crate::core::runtime::components::component_disabled("juice").encode())+ }+}+fn str_param(params: &Map<String, Value>, key: &str) -> Option<String> {params.get(key).and_then(Value::as_str).map(str::to_string)}fn handle_detect(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let content = str_param(¶ms, "content").ok_or("missing 'content'")?;let hint = ContentHint {source_tool: str_param(¶ms, "tool_name"),@@ -317,6 +332,7 @@ fn compress_hint_from_params(params: &Map<String, Value>) -> Result<ContentHint,fn handle_compress(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let content = str_param(¶ms, "content").ok_or("missing 'content'")?;let hint = compress_hint_from_params(¶ms)?;let res = super::compress(content, hint).await?;@@ -335,6 +351,7 @@ fn handle_compress(params: Map<String, Value>) -> ControllerFuture {fn handle_cache_stats(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let stats = super::cache_stats().await?;Ok(serde_json::json!({ "entries": stats.entries, "bytes": stats.bytes }))})@@ -342,6 +359,7 @@ fn handle_cache_stats(_params: Map<String, Value>) -> ControllerFuture {fn handle_retrieve(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let token = str_param(¶ms, "token").ok_or("missing 'token'")?;match super::retrieve(token, None).await? {Some(content) => Ok(serde_json::json!({ "found": true, "content": content })),@@ -352,6 +370,7 @@ fn handle_retrieve(params: Map<String, Value>) -> ControllerFuture {fn handle_settings_get(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let config = crate::config::Config::load_or_init().await.map_err(|e| format!("load config: {e}"))?;@@ -363,6 +382,7 @@ fn handle_settings_get(_params: Map<String, Value>) -> ControllerFuture {fn handle_settings_update(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;// Accept either {"patch": {...}} or a bare object of fields.let patch = params.get("patch")@@ -391,6 +411,7 @@ fn handle_settings_update(params: Map<String, Value>) -> ControllerFuture {fn handle_savings_stats(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let cache = super::cache_stats().await?;let config = crate::config::Config::load_or_init().await@@ -409,6 +430,7 @@ fn handle_savings_stats(_params: Map<String, Value>) -> ControllerFuture {fn handle_savings_reset(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let config = crate::config::Config::load_or_init().await.map_err(|e| e.to_string())?;