feat: FetchURL tool supports downloading images#1499
Conversation
- Detect image/* content types in LocalFetchURLProvider - Read binary body for images, convert to base64 data URI - Sniff image dimensions when available - Return image as ContentPart[] with image_url for LLM vision models - Update tool description to mention image support - Add tests for image fetching in both tool and provider
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 659898e52c
ℹ️ 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".
| }; | ||
| } | ||
|
|
||
| if (kind === 'image') { |
There was a problem hiding this comment.
Route image URLs around the Moonshot text fetcher
In configurations with services.moonshot_fetch.base_url, createRuntimeConfig wraps the local fetcher in MoonshotFetchURLProvider, and that provider returns { content, kind: 'extracted' } for every 200 from the coding-fetch service (packages/agent-core/src/tools/providers/moonshot-fetch-url.ts:51-56). This image branch is therefore only reached when the service fails and falls back locally, so a successful Moonshot fetch of an image URL produces text/empty output instead of an image even though FetchURL now advertises image support. Detect image responses before/inside the Moonshot path or have that provider surface kind: 'image'.
Useful? React with 👍 / 👎.
| const output: ContentPart[] = [ | ||
| { type: 'text', text: `<system>${systemParts.join(' ')}</system>` }, | ||
| { type: 'text', text: `<image url="${args.url}">` }, | ||
| { type: 'image_url', imageUrl: { url: content } }, |
There was a problem hiding this comment.
Gate image tool output on image-capable models
When the current model lacks image_in, FetchURL is still registered whenever a urlFetcher exists (packages/agent-core/src/agent/tool/index.ts:421), unlike ReadMediaFileTool which is capability-gated. Returning an image_url here records media in the tool result; providers such as the OpenAI legacy adapter then reattach tool-result images as image_url user content on the next request (packages/kosong/src/providers/openai-legacy.ts:260-267), which text-only tool-capable models reject. Return a text error or only advertise/emit image output when image_in is supported.
Useful? React with 👍 / 👎.
问题概述
FetchURL 工具目前只能获取文本内容,无法处理图片。当用户尝试用 FetchURL 拉取图片 URL 时,工具会尝试解析 HTML 并提取文本,导致图片内容丢失。
解决方案要点
LocalFetchURLProvider中检查响应头的Content-Type,识别image/*类型。ContentPart[]格式返回,包含image_url字段,供 LLM vision 模型直接使用。fetch-url.md中补充说明工具现在支持图片下载。技术方案选择原因
LocalFetchURLProvider中扩展,不引入新依赖,保持工具自包含。Content-Length时记录尺寸信息,便于调试。PR 链接
https://github.com/MoonshotAI/kimi-code/pull/NEW
Commit: 659898e
Branch: feat/fetch-url-image-support