aKode 0.9.1: immagini degli strumenti in un messaggio utente, errore 500 chiamato per nome

- 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 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-17 01:20:19 +01:00
parent a1a92535bb
commit 2d933d0926
6 changed files with 159 additions and 2 deletions

View File

@@ -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

View File

@@ -4169,7 +4169,7 @@ async fn realtime_webrtc_start_surfaces_backend_error() -> Result<()> {
let error =
read_notification::<ThreadRealtimeErrorNotification>(&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(())

View File

@@ -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)

View File

@@ -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;

View File

@@ -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<ContentItem> {
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<ContentItem>) -> 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<ResponseItem>) {
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);
}
}

View File

@@ -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}")]