Whole file
easylink-ai-open/agent-runtime
The author described this change as “Fix Anthropic data URL image serialization”. It counts as a record because the check below fails on the code as it stood at 41a1538ea and passes on a9447bb5d, with nothing else changed between the two runs.
Fix saved2026-07-23
Sharing licenceApache-2.0 · LICENSE
Change size+13 −1
What the code was meant to do, written into the code itself as a save note
Fix Anthropic data URL image serialization
The change
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | 70 | def _image_source(img: ImagePart) -> dict[str, Any]: | |
| 71 | + | if img.data is not None: | |
| 72 | + | return { | |
| 73 | + | "type": "base64", | |
| 74 | + | "media_type": img.media_type or "image/png", | |
| 75 | + | "data": img.data, | |
| 76 | + | } | |
| 71 | 77 | if img.url: | |
| 78 | + | if img.url.startswith("data:image/"): | |
| 79 | + | header, separator, data = img.url.partition(",") | |
| 80 | + | if not separator or not header.endswith(";base64"): | |
| 81 | + | raise ValueError("Anthropic image data URLs must contain base64-encoded image data") | |
| 82 | + | media_type = header.removeprefix("data:").removesuffix(";base64") | |
| 83 | + | return {"type": "base64", "media_type": media_type, "data": data} | |
| 72 | 84 | return {"type": "url", "url": img.url} | |
| 73 | 85 | return { | |
| 74 | 86 | "type": "base64", | |
| 75 | 87 | "media_type": img.media_type or "image/png", | |
| 76 | - | "data": img.data or "", | |
| 88 | + | "data": "", | |
| 77 | 89 | } | |
| 78 | 90 | ||
| 79 | 91 |
The check that tells the two apart
fail→pass·tests/test_multimodal.py::test_anthropic_base64_data_url_image
Check file tests/test_multimodal.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it41a1538ea531aa8d4d6c1a294b508bdc7bf879c0
Broken version dated2026-07-13
Moduleagent_runtime.llm.anthropic
Units changed_image_source
Fingerprint69e42bbdb80c1424
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.