Skip to content

feat(tools): add analyze_image vision tool for charts and screenshots#464

Merged
warren618 merged 1 commit into
HKUDS:mainfrom
fei-moss:feat/analyze-image-tool
Jul 10, 2026
Merged

feat(tools): add analyze_image vision tool for charts and screenshots#464
warren618 merged 1 commit into
HKUDS:mainfrom
fei-moss:feat/analyze-image-tool

Conversation

@fei-moss

Copy link
Copy Markdown
Contributor

Motivation

Users naturally send chart screenshots (K-line, positions, statements) to the bot through IM channels. Today the agent's only option is read_document, whose image path is OCR-only — for a candlestick chart it returns nothing, and the agent has to apologize:

我尝试读取了这张图片,但 OCR 没有识别出文字…

Meanwhile the provider layer already supports multimodal input (the OpenAI Codex adapter converts image_url content to input_image), it just isn't reachable from any tool.

What this adds

A new auto-discovered analyze_image tool:

  • sends the image (base64 data URL) + a question to the configured chat model via ChatLLM().chat(...) and returns the model's answer
  • path validation reuses resolve_safe_path + allowed_file_roots — exactly the same policy as read_file, no new read surface
  • jpg/png/gif/bmp/webp, 10 MB cap, 120 s timeout, standard {"ok": …} envelope
  • tool description steers the LLM to prefer it over OCR for charts/screenshots

Testing

  • 4 unit tests (mocked ChatLLM): path safety, missing/unsupported files, message shape (text + data-URL image part), empty-answer error
  • Verified live against the openai-codex provider: given a matplotlib chart titled "uptrend" whose data actually trends down, the model correctly read the title AND reported the downtrend — confirming genuine vision, not filename/OCR guessing
  • Also verified end-to-end through the weixin channel (send image → agent calls analyze_image → meaningful chart commentary). Note: channel media dirs must be readable, see the companion issue about default allowed file roots.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YEshFSpjkW7EFuPCMGE64A

Images received through IM channels (or uploaded) could previously only
be processed by read_document's OCR path, which returns nothing useful
for candlestick charts, account screenshots and photos - even though
multimodal providers (e.g. the OpenAI Codex adapter's input_image
conversion) can already accept images.

Add an analyze_image tool that base64-encodes a local image and asks the
configured chat model about it directly:

- path validation reuses resolve_safe_path + allowed_file_roots (same
  policy as read_file)
- jpg/png/gif/bmp/webp, 10 MB cap, 120 s vision timeout
- standard {"ok": ..., "data"/"error": ...} envelope

Tests mock ChatLLM and cover path safety, unsupported/missing files,
the data-URL message shape, and empty-answer handling.

Signed-off-by: fei-moss <fei@moss.site>
@warren618 warren618 merged commit 045d0f9 into HKUDS:main Jul 10, 2026
warren618 added a commit that referenced this pull request Jul 10, 2026
- manifest guard test: ignore __pycache__ when counting zoo modules
- analyze_image: state the vision-capable-model requirement in the tool
  description; point the example path at the new uploads media root
- turnover_aware: drop the mathematically inert risk_free knob (additive
  constant on the simplex), fix the max-Sharpe docstring mislabel, document
  realized_turnover as class-API-only
- skills: surface turnover_aware in asset-allocation + strategy-generate
  so the agent can actually propose it
OXOOOOX pushed a commit to OXOOOOX/Vibe-Trading that referenced this pull request Jul 12, 2026
…HKUDS#464)

Read-only tool that sends a local image to the session model as a multimodal message. Path-validated against the allowed file roots; complements read_document's OCR with semantic vision analysis. Requires a vision-capable model.
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.

2 participants