feat(viking): auto-return image bytes from viking_read for vision models - #356
feat(viking): auto-return image bytes from viking_read for vision models#356Leoyzen wants to merge 2 commits into
Conversation
Add tri-state support_vision config (True=force bytes, False=force text, None=auto-detect from model capabilities) to VikingCapability. The agent factory now populates VikingCapability.model_capabilities with resolved model capabilities, and viking_read detects image URIs by extension to return BinaryImage parts (or text URI hints) accordingly. - agentpool_config: support_vision field on VikingCapabilityConfig - capabilities/viking: constants.py (IMAGE_EXTENSIONS/MIME), _should_return_image_bytes() - tools.py: image branch in viking_read with SVG text-only degradation - agent.py: populate viking cap model_capabilities in factory injection loop - openviking-sdk upgraded to 0.1.6 for download_bytes support
|
Review complete. Both specialist subagents (code + docs) verified my analysis; findings confirmed against the on-disk files. Review: PR #356 — viking_read auto-return image bytes for vision modelsThe approach is sound and consistent with the Blocking
Major
Minor
Docs / process notes
Behavioral noteThis PR silently activates Recommendation: address #1 (add the claimed image-branch tests), #2, and #3 before merge; the rest can be follow-ups. |
The viking_read image-branch tests (download_bytes -> BinaryImage, SVG degradation, mixed URIs, error handling) were accidentally edited into the main working tree instead of this worktree and never committed. Restore them here and address review findings: - tools.py: prefix image markers with 1-based index (#N) so return_value markers map 1:1 to BinaryImage order in ToolReturn.content (review M1) - constants.py: rename _IMAGE_MIME_TYPES -> IMAGE_MIME_TYPES (public, used cross-module); keep .svg in IMAGE_EXTENSIONS, excluded from byte path - tools.py: SVG always degrades to text hint even with support_vision=True - tests: add multi-image index/order mapping test

概述
为 Viking 能力增加图片资源返回支持:当模型具备视觉能力(或
support_vision显式开启)时,viking_read对图片 URI 返回BinaryImage字节;否则返回文本 URI 说明(安全降级)。背景问题
viking_read通过client.read()读取图片时会把二进制字节按文本解码成乱码(utf-8→gbk→latin-1→replace)。模型无法理解图片内容。改动
agentpool_config/capabilities.py):VikingCapabilityConfig新增三态开关support_vision: bool | None = NoneTrue— 强制返回图片字节False— 强制返回文本 URINone(默认)— 由模型能力自动判断capabilities/viking/):constants.py:与 openviking 服务器一致的IMAGE_EXTENSIONS集合 + MIME 映射(需手动同步服务器parse/parsers/media/constants.py)_should_return_image_bytes():三态决策,NNone 语义文档化(与ModalityFilterCapability的 pass-through 语义区分——Viking 未注入时按 text-only 安全降级)agents/native_agent/agent.py):capability 注入循环中为VikingCapability填充model_capabilities(与 ModalityFilter 同模式,非自动注入)tools.pyviking_read):按扩展名判定图片 →download_bytes→BinaryImage;.svg矢量格式永不返回字节(降级文本);混合 URI 列表按序处理;下载失败返回viking_read error:文本openviking-sdk0.1.5 → 0.1.6(提供AsyncHTTPClient.download_bytes)测试
_should_return_image_bytes三态矩阵(6 用例)viking_read图片分支 9 mock 场景(True/False/None 自动、非图片忽略、SVG 降级、混合 URI、下载错误、MIME 映射)ModelCapabilitiesper-run copy 保留断言备注
IMAGE_EXTENSIONS与 openviking 服务器手动同步(见 design.md 风险矩阵)OpenSpec change:
openspec/changes/viking-image-vision-support/(本地规划文件,不进 git)