From 0c06276b48e90a2475e1cc77151759c69f8befb8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 18 Dec 2025 23:02:33 +0000 Subject: [PATCH] Agent: document 2000px image downscale --- src/agents/pi-embedded.ts | 2 ++ src/agents/pi-tools.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/agents/pi-embedded.ts b/src/agents/pi-embedded.ts index cbfeb2f0b..39878aee0 100644 --- a/src/agents/pi-embedded.ts +++ b/src/agents/pi-embedded.ts @@ -140,6 +140,8 @@ async function sanitizeSessionMessagesImages( messages: AppMessage[], label: string, ): Promise { + // We sanitize historical session messages because Anthropic can reject a request + // if the transcript contains oversized base64 images (see MAX_IMAGE_DIMENSION_PX). const out: AppMessage[] = []; for (const msg of messages) { if (!msg || typeof msg !== "object") { diff --git a/src/agents/pi-tools.ts b/src/agents/pi-tools.ts index e62d624e2..f1eb24485 100644 --- a/src/agents/pi-tools.ts +++ b/src/agents/pi-tools.ts @@ -11,6 +11,12 @@ type ToolContentBlock = AgentToolResult["content"][number]; type ImageContentBlock = Extract; type TextContentBlock = Extract; +// Anthropic Messages API limitation (observed in Clawdis sessions): +// When sending many images in a single request (e.g. via session history + tool results), +// Anthropic rejects any image where *either* dimension exceeds 2000px. +// +// To keep sessions resilient (and avoid "silent" WhatsApp non-replies), we auto-downscale +// all base64 image blocks above this limit while preserving aspect ratio. const MAX_IMAGE_DIMENSION_PX = 2000; function sniffMimeFromBase64(base64: string): string | undefined {