From 2d933d0926b98ee6a5645ee52c83471cacd35d43 Mon Sep 17 00:00:00 2001 From: "andrea.difonzo" Date: Tue, 17 Nov 2026 01:20:19 +0100 Subject: [PATCH] aKode 0.9.1: immagini degli strumenti in un messaggio utente, errore 500 chiamato per nome MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - view_image con server llama.cpp/ik_llama.cpp: l'immagine dentro function_call_output faceva rispondere 500 ("Output of tool call should be 'Input text'") e chiudeva il turno con un errore (prove s2/s3 di Fourier). Con merge_system_messages l'output resta testo con un segnaposto e l'immagine segue in un messaggio utente (verificato sul server: 500 prima, risposta corretta dopo). - Il messaggio per HTTP 500 non parla più di «high demand». Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + .../tests/suite/v2/realtime_conversation.rs | 2 +- akode-rs/core/src/client.rs | 2 + akode-rs/core/src/lib.rs | 1 + akode-rs/core/src/tool_output_images.rs | 153 ++++++++++++++++++ akode-rs/protocol/src/error.rs | 2 +- 6 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 akode-rs/core/src/tool_output_images.rs diff --git a/README.md b/README.md index 99bc4c27..eab94c17 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ Il token sta nell'archivio delle chiavi (`provider_api_key_store`, id `telegram- - **Errori di rete dentro la sandbox**: se un comando fallisce per la rete (pip, npm, curl, git…), all'output si aggiunge una nota per il modello: è la sandbox, non la connessione; quali host sono raggiungibili; come chiedere all'utente di eseguire fuori dalla sandbox (`require_escalated`), oppure, se la politica di approvazione non lo permette, di dirlo all'utente. - **Escalation non concedibile eseguita nella sandbox**: se la politica di approvazione non permette di chiedere l'esecuzione fuori dalla sandbox (per esempio in una cartella senza progetto), il comando gira nella sandbox invariata con una nota per il modello, invece di essere rifiutato; nessun permesso in più. Prima Qwen, dopo il rifiuto, rinunciava a installare le dipendenze. - **Note sulla sandbox per il modello**: dopo una scrittura negata (`Operation not permitted`, per esempio `pip install` nel Python di sistema) aKode spiega dove può scrivere e suggerisce un ambiente virtuale nel progetto; dopo `write_file` ricorda di verificare il file. +- **Immagini degli strumenti nei messaggi utente**: llama.cpp/ik_llama.cpp accettano immagini solo nei messaggi utente; un'immagine dentro l'output di `view_image` faceva rispondere il server con HTTP 500 e il turno finiva con un errore. Con `merge_system_messages` (attivo di default) l'output dello strumento resta testo e l'immagine segue in un messaggio utente. L'errore 500 ora si chiama per nome invece di «high demand». - **Testi della TUI in italiano**: messaggio di benvenuto e comandi suggeriti, «Chiedi ad aKode qualsiasi cosa», «per gli agenti», «per le scorciatoie», «Errore fatale»; nelle approvazioni «aKode» invece di «codex». ### 0.9.0 diff --git a/akode-rs/app-server/tests/suite/v2/realtime_conversation.rs b/akode-rs/app-server/tests/suite/v2/realtime_conversation.rs index 7d70f254..ff03727f 100644 --- a/akode-rs/app-server/tests/suite/v2/realtime_conversation.rs +++ b/akode-rs/app-server/tests/suite/v2/realtime_conversation.rs @@ -4169,7 +4169,7 @@ async fn realtime_webrtc_start_surfaces_backend_error() -> Result<()> { let error = read_notification::(&mut mcp, "thread/realtime/error") .await?; - assert!(error.message.contains("currently experiencing high demand")); + assert!(error.message.contains("errore interno (HTTP 500)")); realtime_server.shutdown().await; Ok(()) diff --git a/akode-rs/core/src/client.rs b/akode-rs/core/src/client.rs index f6c7df88..029a8dc8 100644 --- a/akode-rs/core/src/client.rs +++ b/akode-rs/core/src/client.rs @@ -1168,6 +1168,8 @@ impl ModelClient { let include = vec!["reasoning.encrypted_content".to_string()]; if self.state.provider.info().merge_system_messages() { crate::merge_system_messages::merge_system_messages(&mut input); + // aKode: chat-template servers accept images only in user messages. + crate::tool_output_images::move_tool_output_images(&mut input); } let verbosity = if model_info.support_verbosity { self.state.model_verbosity.or(model_info.default_verbosity) diff --git a/akode-rs/core/src/lib.rs b/akode-rs/core/src/lib.rs index a2883c27..000616cb 100644 --- a/akode-rs/core/src/lib.rs +++ b/akode-rs/core/src/lib.rs @@ -41,6 +41,7 @@ mod compact_retained_tool_outputs; mod compact_token_budget; pub mod compaction_metadata; mod merge_system_messages; +mod tool_output_images; mod tool_order; mod tool_output_clearing; mod thread_startup_metadata; diff --git a/akode-rs/core/src/tool_output_images.rs b/akode-rs/core/src/tool_output_images.rs new file mode 100644 index 00000000..5a44299a --- /dev/null +++ b/akode-rs/core/src/tool_output_images.rs @@ -0,0 +1,153 @@ +//! aKode: moves images out of tool outputs for chat-template servers. +//! +//! llama.cpp / ik_llama.cpp accept images only in user messages: an image inside a +//! `function_call_output` (for example from `view_image`) makes `/v1/responses` fail +//! with HTTP 500 ("Output of tool call should be 'Input text'"), and the turn ends with +//! an error. With `merge_system_messages` enabled (the chat-template compatibility +//! switch, on by default) each tool output keeps its text plus a short placeholder and +//! its images follow it in a `user` message. The transformation only depends on the +//! history, so the prompt prefix stays the same between turns. + +use akode_protocol::models::ContentItem; +use akode_protocol::models::FunctionCallOutputBody; +use akode_protocol::models::FunctionCallOutputContentItem; +use akode_protocol::models::FunctionCallOutputPayload; +use akode_protocol::models::ResponseItem; + +/// Text left in the tool output in place of its images. +pub(crate) const IMAGE_MOVED_PLACEHOLDER: &str = "[image attached in the next message]"; + +/// Splits `output` into a text-only output and the images it contained. +fn split_images(output: &mut FunctionCallOutputPayload) -> Vec { + let FunctionCallOutputBody::ContentItems(items) = &output.body else { + return Vec::new(); + }; + if !items + .iter() + .any(|item| matches!(item, FunctionCallOutputContentItem::InputImage { .. })) + { + return Vec::new(); + } + let mut texts = Vec::new(); + let mut images = Vec::new(); + for item in items { + match item { + FunctionCallOutputContentItem::InputText { text } => texts.push(text.clone()), + FunctionCallOutputContentItem::InputImage { image, detail } => { + images.push(ContentItem::InputImage { + image: image.clone(), + detail: *detail, + }); + } + #[allow(unreachable_patterns)] + _ => {} + } + } + texts.push(IMAGE_MOVED_PLACEHOLDER.to_string()); + output.body = FunctionCallOutputBody::Text(texts.join("\n")); + images +} + +fn image_message(images: Vec) -> ResponseItem { + ResponseItem::Message { + encrypted_content: None, + status: None, + id: None, + role: "user".to_string(), + content: images, + phase: None, + internal_chat_message_metadata_passthrough: None, + } +} + +/// Moves the images of every tool output into a `user` message right after it. +pub(crate) fn move_tool_output_images(input: &mut Vec) { + let mut index = 0; + while index < input.len() { + let images = match &mut input[index] { + ResponseItem::FunctionCallOutput { output, .. } + | ResponseItem::CustomToolCallOutput { output, .. } => split_images(output), + _ => Vec::new(), + }; + if images.is_empty() { + index += 1; + continue; + } + input.insert(index + 1, image_message(images)); + index += 2; + } +} + +#[cfg(test)] +mod tests { + use super::*; + use akode_protocol::models::ImageReference; + use pretty_assertions::assert_eq; + + fn output_item(body: FunctionCallOutputBody) -> ResponseItem { + ResponseItem::FunctionCallOutput { + id: None, + call_id: Some("c1".to_string()), + name: None, + namespace: None, + output: FunctionCallOutputPayload { + body, + success: Some(true), + }, + internal_chat_message_metadata_passthrough: None, + } + } + + fn image(url: &str) -> ImageReference { + ImageReference::Inline { + image_url: url.to_string(), + } + } + + #[test] + fn moves_images_after_the_tool_output() { + let mut input = vec![ + output_item(FunctionCallOutputBody::ContentItems(vec![ + FunctionCallOutputContentItem::InputText { + text: "chart.png".to_string(), + }, + FunctionCallOutputContentItem::InputImage { + image: image("data:image/png;base64,AAA"), + detail: None, + }, + ])), + output_item(FunctionCallOutputBody::Text("plain".to_string())), + ]; + move_tool_output_images(&mut input); + assert_eq!(input.len(), 3); + assert_eq!( + input[0], + output_item(FunctionCallOutputBody::Text(format!( + "chart.png\n{IMAGE_MOVED_PLACEHOLDER}" + ))) + ); + assert_eq!( + input[1], + image_message(vec![ContentItem::InputImage { + image: image("data:image/png;base64,AAA"), + detail: None, + }]) + ); + assert_eq!( + input[2], + output_item(FunctionCallOutputBody::Text("plain".to_string())) + ); + } + + #[test] + fn leaves_text_outputs_alone() { + let original = vec![output_item(FunctionCallOutputBody::ContentItems(vec![ + FunctionCallOutputContentItem::InputText { + text: "a".to_string(), + }, + ]))]; + let mut input = original.clone(); + move_tool_output_images(&mut input); + assert_eq!(input, original); + } +} diff --git a/akode-rs/protocol/src/error.rs b/akode-rs/protocol/src/error.rs index 0d9c967c..bf9b7557 100644 --- a/akode-rs/protocol/src/error.rs +++ b/akode-rs/protocol/src/error.rs @@ -205,7 +205,7 @@ pub enum CodexErrorDetails { QuotaExceeded, #[error("Your model provider account does not include access to this model.")] UsageNotIncluded, - #[error("We’re currently experiencing high demand, which may cause temporary errors.")] + #[error("Il server del modello ha risposto con un errore interno (HTTP 500).")] InternalServerError, /// Retry limit exceeded. #[error("{0}")]