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(tokenjuice): signal failed summary when module cannot produce one
Steven Enamakela7ec1fb1976a
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rsindex f83d260f65..facb7cc265 100644--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs@@ -198,6 +198,23 @@ impl CompactedToolOutput {summarized_from_bytes: None,}}++ /// The content untouched, disclosing the summary that did not happen when+ /// one was wanted.+ fn passthrough(text: String, wants_summary: bool) -> Self {+ Self {+ notice: wants_summary.then(summary_failed_notice),+ ..Self::unchanged(text)+ }+ }+}++/// TinyJuice's own notice for a summary that was attempted and not produced,+/// so a host-side failure reads the same as a module-side one.+pub fn summary_failed_notice() -> String {+ tinyjuice::summarize::UnavailableReason::Failed+ .notice()+ .to_string()}/// Deadline for `CompactWith`. It may wait on a summary model call, which the@@ -219,6 +236,10 @@ pub async fn compact_tool_output(call: ToolOutputCompaction<'_>) -> CompactedToocontext_token,scope,} = call;+ // A summary call is registered, so the result qualified for one. Any path+ // below that ends without a module answer says so, rather than handing+ // the model a raw dump it will re-run the tool to get summarized.+ let wants_summary = context_token.is_some();// Nothing to ask the module for: the router is off and no summary call is// registered, or this agent bypasses TinyJuice entirely.if (!enabled && context_token.is_none()) || profile == AgentTokenjuiceCompression::Off {@@ -245,7 +266,7 @@ pub async fn compact_tool_output(call: ToolOutputCompaction<'_>) -> CompactedTooOk(config) => std::sync::Arc::new(config),Err(error) => {log::debug!("[tokenjuice] config unavailable, passing through: {error}");- return CompactedToolOutput::unchanged(content);+ return CompactedToolOutput::passthrough(content, wants_summary);}},};@@ -259,13 +280,13 @@ pub async fn compact_tool_output(call: ToolOutputCompaction<'_>) -> CompactedToo};if let Err(error) = install_from_config(&config).await {log::debug!("[tokenjuice] module configuration failed, passing through: {error}");- return CompactedToolOutput::unchanged(content);+ return CompactedToolOutput::passthrough(content, wants_summary);}let proxy = match proxy(&config).await {Ok(proxy) => proxy.with_timeout(COMPACT_WITH_TIMEOUT),Err(error) => {log::debug!("[tokenjuice] module unavailable, passing through: {error}");- return CompactedToolOutput::unchanged(content);+ return CompactedToolOutput::passthrough(content, wants_summary);}};let request = types::CompactRequest {@@ -281,27 +302,41 @@ pub async fn compact_tool_output(call: ToolOutputCompaction<'_>) -> CompactedToolet response: types::CompactResponse = match proxy.call(methods::COMPACT_WITH, (request,)).await{Ok(response) => response,- // A module released before contract 1.1 has no `CompactWith`.- // Fall back to the positional member it does have, without the- // focus or a summary.- Err(error) => {+ // A module released before contract 1.1 has no `CompactWith`. Fall+ // back to the positional member it does have, without the focus or a+ // summary. Any other failure, a timeout above all, is not retried: the+ // module already had its chance, and a second call could double the+ // wait on a turn that is already stalled.+ Err(error) if error.wire_name() == tinybus::Error::UNKNOWN_METHOD => {log::debug!(- "[tokenjuice] CompactWith failed, retrying as Compact tool={tool_name}: {error}"+ "[tokenjuice] CompactWith unknown to the loaded module, retrying as Compact tool={tool_name}");match proxy- .call(+ .call::<types::CompactResponse>(methods::COMPACT,(content.clone(), tool_name.to_string(), enabled, profile),).await{- Ok(response) => response,+ Ok(mut response) => {+ if wants_summary && response.notice.is_none() {+ response.notice = Some(summary_failed_notice());+ }+ response+ }Err(error) => {log::debug!("[tokenjuice] module compaction failed, passing through: {error}");- return CompactedToolOutput::unchanged(content);+ return CompactedToolOutput::passthrough(content, wants_summary);}}}+ Err(error) => {+ log::debug!(+ "[tokenjuice] CompactWith failed, passing through tool={tool_name} wire_error={}: {error}",+ error.wire_name()+ );+ return CompactedToolOutput::passthrough(content, wants_summary);+ }};record_savings(&response);compacted_from(response)