Skip to content

feat: FetchURL tool supports downloading images#946

Open
bj456736 wants to merge 1 commit into
MoonshotAI:mainfrom
bj456736:auto-pr-20260620-1800
Open

feat: FetchURL tool supports downloading images#946
bj456736 wants to merge 1 commit into
MoonshotAI:mainfrom
bj456736:auto-pr-20260620-1800

Conversation

@bj456736

Copy link
Copy Markdown
Contributor

Summary

This PR extends the FetchURL tool to support downloading images from URLs and returning them as base64-encoded markdown. This enables the LLM to view images referenced by URL without requiring the user to manually download them.

Changes

Core Changes

  • UrlFetchKind / UrlFetchResult: Added new kind alongside existing and
  • LocalFetchURLProvider: Detects Content-Type responses, converts binary payload to base64, and returns markdown image syntax () with
  • FetchURLTool: Reports image-specific execution message () so the LLM knows it's viewing an image

Safety

  • Respects existing 10 MiB max size limit (content-length + body measurement)
  • Supports PNG, JPEG, GIF, WebP, SVG, and other image formats
  • Falls back to existing text extraction for non-image URLs

Tests

  • Added 4 new test cases covering:
    • PNG image fetch → base64 markdown
    • JPEG image fetch → base64 markdown
    • SVG image fetch → correct extension (handles MIME subtype)
    • Oversized image rejection (15 MB > 10 MiB limit)
  • All 25 fetch-url related tests pass (18 + 7)
  • Full tool suite: 908 tests pass

Motivation

Previously, when a user provided an image URL, the FetchURL tool would attempt to extract text from it (via Readability) and return empty or garbled content. Now the LLM can actually view the image by receiving it as inline base64 markdown.

Backward Compatibility

Fully backward compatible. Non-image URLs continue to work exactly as before. The new kind is only returned when the server responds with Content-Type.

- Added 'image' kind to UrlFetchKind and UrlFetchResult
- LocalFetchURLProvider detects image Content-Type and converts to base64
- Tool execution reports image-specific message to the LLM
- Added tests for PNG, JPEG, SVG, and oversized image rejection
- Updated tool description to mention image support
@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c88be09

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 20, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c88be09
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c88be09

commit: c88be09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c88be09fe3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +189 to +190
const markdown = `![image](data:image/${cleanExt};base64,${base64})`;
return { content: markdown, kind: 'image' };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return fetched images as media parts

When this image path runs, the result stays a plain string, so createToolMessage wraps it as a text part rather than an image_url part; FetchURLTool also sends that same string through the 50k-character ToolResultBuilder. In normal model calls the tool result is therefore base64 text, or an invalid truncated data URI for images larger than about 37 KiB, not an attached image the model can inspect. Please return a ContentPart[] image output like ReadMedia does instead of markdown text.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant