Skip to content

Commit 4c210e2

Browse files
authored
Adapt image compression quality by model (#85742)
* feat: adapt image compression quality * refactor: move image limits into model metadata * test: cover adaptive image downscaling * test: cover image tool live providers * fix: apply media metadata to all image paths * fix: align providerless image compression * fix: add chutes runtime image limits * fix: optimize image data urls with model limits * fix: type media metadata merge * fix: optimize data url byte limits after decode * fix: preserve data url optimizer fallback * fix: keep low-side image compression fallbacks * fix: enforce data url image compression policy * fix: preserve gif data url media policy * fix: satisfy adaptive image type checks * test: keep cron provider-runtime mock current
1 parent 0038813 commit 4c210e2

32 files changed

Lines changed: 1750 additions & 53 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Docs: https://docs.openclaw.ai
88

99
- Gateway/perf: lazy-load startup-idle plugin work, core gateway method handlers, and the embedded ACPX runtime so Gateway health and ready signals no longer wait on unused handler trees or ACPX probes.
1010
- Gateway/perf: cache plugin SDK public-surface alias maps and skip irrelevant macOS Linuxbrew PATH probes so Gateway startup avoids repeated filesystem walks and slow missing-directory stats.
11+
- Image tool: add adaptive model-aware image compression with an `agents.defaults.imageQuality` preference for choosing token-efficient, balanced, or high-detail media handling.
1112
- Meeting Notes: add a source-only external meeting-notes plugin and SDK source-provider contract outside the core npm package, with auto-start capture config, manual transcript imports, read-only `openclaw meeting-notes` CLI access, and Discord voice as the first live source.
1213
- Docs/channels/config: add Signal `configPath`, Telegram wildcard topic defaults, local-time backup archive names, Termux home fallback, include-path validation, secret-scanner-safe placeholder guidance, Gemini CLI/Antigravity media guidance, and macOS VM auto-login guidance. Thanks @NorseGaud, @yudistiraashadi, @huangqian8, @VibhorGautam, @maweibin, @tianxingleo, @IgnacioPro, and @xzcxzcyy-claw.
1314
- Docs: clarify model-usage portability, Codex migration prerequisites, status bootstrap wording, thread-bound subagent limits, hook ownership, and config-preserving safety guidance. Thanks @aniruddhaadak80, @leno23, @TomDjerry, @matthewxmurphy, @vincentkoc, and @stablegenius49.

‎docs/gateway/config-agents.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,26 @@ Higher values preserve more visual detail.
327327
}
328328
```
329329

330+
### `agents.defaults.imageQuality`
331+
332+
Image-tool compression/detail preference for images loaded from file paths, URLs, and media references.
333+
Default: `auto`.
334+
335+
OpenClaw adapts the resize ladder to the selected image model. For example, Claude Opus 4.7, OpenAI GPT-5.5, Qwen VL, and hosted Llama 4 vision models can use larger images than older/default high-detail vision paths, while multi-image turns are compressed more aggressively in `auto` mode to control token and latency cost.
336+
337+
Values:
338+
339+
- `auto`: adapt to model limits and image count.
340+
- `efficient`: prefer smaller images for lower token and byte usage.
341+
- `balanced`: use the standard middle-ground ladder.
342+
- `high`: preserve more detail for screenshots, diagrams, and document images.
343+
344+
```json5
345+
{
346+
agents: { defaults: { imageQuality: "auto" } },
347+
}
348+
```
349+
330350
### `agents.defaults.userTimezone`
331351

332352
Timezone for system prompt context (not message timestamps). Falls back to host timezone.

‎extensions/anthropic/cli-catalog.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ const CLAUDE_CLI_MODEL_LABELS: Record<string, string> = {
1010
"claude-sonnet-4-6": "Claude Sonnet 4.6 (Claude CLI)",
1111
};
1212

13+
function resolveClaudeCliImageMediaInput(id: string): ModelCatalogEntry["mediaInput"] {
14+
const maxSidePx = id === "claude-opus-4-7" ? 2576 : 1568;
15+
return {
16+
image: {
17+
maxSidePx,
18+
preferredSidePx: maxSidePx,
19+
tokenMode: "provider",
20+
},
21+
};
22+
}
23+
1324
function extractClaudeCliModelIds(): string[] {
1425
const ids: string[] = [];
1526
const seen = new Set<string>();
@@ -34,6 +45,7 @@ export function buildClaudeCliCatalogEntries(): ModelCatalogEntry[] {
3445
provider: CLAUDE_CLI_BACKEND_ID,
3546
reasoning: true,
3647
input: ["text", "image"],
48+
mediaInput: resolveClaudeCliImageMediaInput(id),
3749
contextWindow: CLAUDE_CLI_DEFAULT_CONTEXT_WINDOW,
3850
}));
3951
}

‎extensions/anthropic/index.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,34 @@ describe("anthropic provider replay hooks", () => {
541541
} as never);
542542

543543
expect(normalized?.input).toEqual(["text", "image"]);
544+
expect(normalized?.mediaInput).toEqual({
545+
image: { maxSidePx: 1568, preferredSidePx: 1568, tokenMode: "provider" },
546+
});
547+
});
548+
549+
it("merges partial Claude image media metadata with provider limits", async () => {
550+
const provider = await registerSingleProviderPlugin(anthropicPlugin);
551+
552+
const normalized = provider.normalizeResolvedModel?.({
553+
provider: "anthropic",
554+
modelId: "claude-opus-4-7",
555+
model: {
556+
id: "claude-opus-4-7",
557+
name: "Claude Opus 4.7",
558+
provider: "anthropic",
559+
api: "anthropic-messages",
560+
reasoning: true,
561+
input: ["text", "image"],
562+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
563+
contextWindow: 200_000,
564+
maxTokens: 64_000,
565+
mediaInput: { image: { maxBytes: 1 } },
566+
},
567+
} as never);
568+
569+
expect(normalized?.mediaInput).toEqual({
570+
image: { maxBytes: 1, maxSidePx: 2576, preferredSidePx: 2576, tokenMode: "provider" },
571+
});
544572
});
545573

546574
it("normalizes GA 1M Claude variants to 1M context", async () => {
@@ -577,6 +605,29 @@ describe("anthropic provider replay hooks", () => {
577605
}
578606
});
579607

608+
it("does not normalize legacy Claude 4.5 models to 1M context", async () => {
609+
const provider = await registerSingleProviderPlugin(anthropicPlugin);
610+
611+
const normalized = provider.normalizeResolvedModel?.({
612+
provider: "anthropic",
613+
modelId: "claude-sonnet-4-5",
614+
model: {
615+
id: "claude-sonnet-4-5",
616+
name: "Claude Sonnet 4.5",
617+
provider: "anthropic",
618+
api: "anthropic-messages",
619+
reasoning: true,
620+
input: ["text", "image"],
621+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
622+
contextWindow: 200_000,
623+
contextTokens: 200_000,
624+
maxTokens: 32_000,
625+
},
626+
} as never);
627+
628+
expect(normalized).toBeUndefined();
629+
});
630+
580631
it("resolves claude-cli synthetic oauth auth", async () => {
581632
readClaudeCliCredentialsForRuntimeMock.mockReset();
582633
readClaudeCliCredentialsForRuntimeMock.mockReturnValue({

‎extensions/anthropic/register.runtime.ts‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ function supportsAnthropicImageInput(modelId: string, modelName?: string): boole
381381
.some((candidate) => matchesAnthropicModernModel(candidate));
382382
}
383383

384+
function resolveAnthropicImageMediaInput(modelId: string, modelName?: string) {
385+
if (!supportsAnthropicImageInput(modelId, modelName)) {
386+
return undefined;
387+
}
388+
const refs = [modelId, modelName].filter((value): value is string => typeof value === "string");
389+
const opus47 = refs.some((ref) =>
390+
[ANTHROPIC_OPUS_47_MODEL_ID, ANTHROPIC_OPUS_47_DOT_MODEL_ID].some((prefix) =>
391+
normalizeLowercaseStringOrEmpty(ref).startsWith(prefix),
392+
),
393+
);
394+
return {
395+
image: {
396+
maxSidePx: opus47 ? 2576 : 1568,
397+
preferredSidePx: opus47 ? 2576 : 1568,
398+
tokenMode: "provider" as const,
399+
},
400+
};
401+
}
402+
384403
function applyAnthropicImageInputCapability(params: {
385404
modelId: string;
386405
model: ProviderRuntimeModel;
@@ -401,13 +420,27 @@ function normalizeAnthropicResolvedModel(
401420
ctx: ProviderNormalizeResolvedModelContext,
402421
): ProviderRuntimeModel | undefined {
403422
const imageCapableModel = applyAnthropicImageInputCapability(ctx) ?? ctx.model;
423+
const mediaInput = resolveAnthropicImageMediaInput(ctx.modelId, imageCapableModel.name);
424+
const mediaInputModel = mediaInput
425+
? {
426+
...imageCapableModel,
427+
mediaInput: {
428+
...mediaInput,
429+
...imageCapableModel.mediaInput,
430+
image: {
431+
...mediaInput.image,
432+
...imageCapableModel.mediaInput?.image,
433+
},
434+
},
435+
}
436+
: imageCapableModel;
404437
const contextWindowModel =
405438
applyAnthropicGa1MContextWindow({
406439
config: ctx.config,
407440
provider: ctx.provider,
408441
modelId: ctx.modelId,
409-
model: imageCapableModel,
410-
}) ?? imageCapableModel;
442+
model: mediaInputModel,
443+
}) ?? mediaInputModel;
411444
return contextWindowModel === ctx.model ? undefined : contextWindowModel;
412445
}
413446

‎extensions/chutes/models.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ describe("chutes-models", () => {
8585
expect(def.compat.supportsUsageInStreaming).toBe(false);
8686
});
8787

88+
it("keeps Qwen VL image limits in the runtime catalog", () => {
89+
const visionModelIds = ["Qwen/Qwen2.5-VL-32B-Instruct", "Qwen/Qwen3-VL-235B-A22B-Instruct"];
90+
for (const id of visionModelIds) {
91+
const model = CHUTES_MODEL_CATALOG.find((candidate) => candidate.id === id);
92+
expect(model).toBeDefined();
93+
if (!model) {
94+
throw new Error(`expected ${id}`);
95+
}
96+
expect(buildChutesModelDefinition(model).mediaInput).toEqual({
97+
image: { maxPixels: 12845056, preferredSidePx: 2048, tokenMode: "provider" },
98+
});
99+
}
100+
});
101+
88102
it("discoverChutesModels returns static catalog when accessToken is empty", async () => {
89103
const models = await discoverChutesModels("");
90104
expect(models).toHaveLength(CHUTES_MODEL_CATALOG.length);

‎extensions/chutes/models.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ export const CHUTES_MODEL_CATALOG: ModelDefinitionConfig[] = [
349349
name: "Qwen/Qwen2.5-VL-32B-Instruct",
350350
reasoning: false,
351351
input: ["text", "image"],
352+
mediaInput: {
353+
image: { maxPixels: 12845056, preferredSidePx: 2048, tokenMode: "provider" },
354+
},
352355
contextWindow: 16384,
353356
maxTokens: 16384,
354357
cost: { input: 0.05, output: 0.22, cacheRead: 0, cacheWrite: 0 },
@@ -358,6 +361,9 @@ export const CHUTES_MODEL_CATALOG: ModelDefinitionConfig[] = [
358361
name: "Qwen/Qwen3-VL-235B-A22B-Instruct",
359362
reasoning: false,
360363
input: ["text", "image"],
364+
mediaInput: {
365+
image: { maxPixels: 12845056, preferredSidePx: 2048, tokenMode: "provider" },
366+
},
361367
contextWindow: 262144,
362368
maxTokens: 262144,
363369
cost: { input: 0.3, output: 1.2, cacheRead: 0, cacheWrite: 0 },

‎extensions/chutes/openclaw.plugin.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@
567567
"name": "Qwen/Qwen2.5-VL-32B-Instruct",
568568
"reasoning": false,
569569
"input": ["text", "image"],
570+
"mediaInput": {
571+
"image": { "maxPixels": 12845056, "preferredSidePx": 2048, "tokenMode": "provider" }
572+
},
570573
"contextWindow": 16384,
571574
"maxTokens": 16384,
572575
"cost": {
@@ -581,6 +584,9 @@
581584
"name": "Qwen/Qwen3-VL-235B-A22B-Instruct",
582585
"reasoning": false,
583586
"input": ["text", "image"],
587+
"mediaInput": {
588+
"image": { "maxPixels": 12845056, "preferredSidePx": 2048, "tokenMode": "provider" }
589+
},
584590
"contextWindow": 262144,
585591
"maxTokens": 262144,
586592
"cost": {

‎extensions/groq/openclaw.plugin.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
"name": "Llama 4 Scout 17B",
9595
"reasoning": false,
9696
"input": ["text", "image"],
97+
"mediaInput": {
98+
"image": { "maxPixels": 33177600, "preferredSidePx": 2048, "tokenMode": "provider" }
99+
},
97100
"contextWindow": 131072,
98101
"maxTokens": 8192,
99102
"cost": {

‎extensions/openai/openclaw.plugin.json‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
"name": "GPT-5.4",
7474
"reasoning": true,
7575
"input": ["text", "image"],
76+
"mediaInput": {
77+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
78+
},
7679
"contextWindow": 272000,
7780
"maxTokens": 128000,
7881
"cost": { "input": 2.5, "output": 15, "cacheRead": 0.25, "cacheWrite": 0 }
@@ -82,6 +85,9 @@
8285
"name": "GPT-5.4 mini",
8386
"reasoning": true,
8487
"input": ["text", "image"],
88+
"mediaInput": {
89+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
90+
},
8591
"contextWindow": 400000,
8692
"maxTokens": 128000,
8793
"cost": { "input": 0.75, "output": 4.5, "cacheRead": 0.075, "cacheWrite": 0 }
@@ -91,6 +97,9 @@
9197
"name": "GPT-5.4 nano",
9298
"reasoning": true,
9399
"input": ["text", "image"],
100+
"mediaInput": {
101+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
102+
},
94103
"contextWindow": 400000,
95104
"maxTokens": 128000,
96105
"cost": { "input": 0.2, "output": 1.25, "cacheRead": 0.02, "cacheWrite": 0 }
@@ -100,6 +109,9 @@
100109
"name": "GPT-5.4 Pro",
101110
"reasoning": true,
102111
"input": ["text", "image"],
112+
"mediaInput": {
113+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
114+
},
103115
"contextWindow": 1050000,
104116
"maxTokens": 128000,
105117
"cost": { "input": 30, "output": 180, "cacheRead": 0, "cacheWrite": 0 }
@@ -109,6 +121,9 @@
109121
"name": "GPT-5.5",
110122
"reasoning": true,
111123
"input": ["text", "image"],
124+
"mediaInput": {
125+
"image": { "maxSidePx": 6000, "preferredSidePx": 2048, "tokenMode": "detail" }
126+
},
112127
"contextWindow": 272000,
113128
"maxTokens": 128000,
114129
"cost": { "input": 5, "output": 30, "cacheRead": 0.5, "cacheWrite": 0 }
@@ -190,6 +205,9 @@
190205
"name": "gpt-5.5-pro",
191206
"reasoning": true,
192207
"input": ["text", "image"],
208+
"mediaInput": {
209+
"image": { "maxSidePx": 6000, "preferredSidePx": 2048, "tokenMode": "detail" }
210+
},
193211
"contextWindow": 1000000,
194212
"maxTokens": 128000,
195213
"cost": { "input": 30, "output": 180, "cacheRead": 0, "cacheWrite": 0 }
@@ -205,6 +223,9 @@
205223
"name": "gpt-5.5",
206224
"reasoning": true,
207225
"input": ["text", "image"],
226+
"mediaInput": {
227+
"image": { "maxSidePx": 6000, "preferredSidePx": 2048, "tokenMode": "detail" }
228+
},
208229
"contextWindow": 400000,
209230
"contextTokens": 272000,
210231
"maxTokens": 128000,
@@ -215,6 +236,9 @@
215236
"name": "gpt-5.4",
216237
"reasoning": true,
217238
"input": ["text", "image"],
239+
"mediaInput": {
240+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
241+
},
218242
"contextWindow": 1050000,
219243
"contextTokens": 272000,
220244
"maxTokens": 128000,
@@ -225,6 +249,9 @@
225249
"name": "gpt-5.4-pro",
226250
"reasoning": true,
227251
"input": ["text", "image"],
252+
"mediaInput": {
253+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
254+
},
228255
"contextWindow": 1050000,
229256
"contextTokens": 272000,
230257
"maxTokens": 128000,
@@ -235,6 +262,9 @@
235262
"name": "gpt-5.4-mini",
236263
"reasoning": true,
237264
"input": ["text", "image"],
265+
"mediaInput": {
266+
"image": { "maxSidePx": 2048, "preferredSidePx": 2048, "tokenMode": "detail" }
267+
},
238268
"contextWindow": 400000,
239269
"contextTokens": 272000,
240270
"maxTokens": 128000,
@@ -245,6 +275,9 @@
245275
"name": "gpt-5.5-pro",
246276
"reasoning": true,
247277
"input": ["text", "image"],
278+
"mediaInput": {
279+
"image": { "maxSidePx": 6000, "preferredSidePx": 2048, "tokenMode": "detail" }
280+
},
248281
"contextWindow": 1000000,
249282
"contextTokens": 272000,
250283
"maxTokens": 128000,

0 commit comments

Comments
 (0)