[PR #9542] feat(plugin): support images in custom tool responses #13145

Open
opened 2026-02-16 18:18:01 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9542

State: open
Merged: No


Summary

Custom tools can now return images alongside text, allowing the LLM to actually see and analyze visual data.

  • Custom tools return { content: [{ type: "text", text }, { type: "image", mimeType, data }] }
  • Backwards compatible: plain string returns still work
  • Images converted to attachments for model vision input

Changes

  • Add ToolContentPart and ToolResult types to plugin
  • Add content normalization helper with validation (max 10 images, ~5MB each, PNG/JPEG/GIF/WebP)
  • Handle rich content in tool registry
  • Add attachments field to tool.execute.after hook
  • Add 8 unit tests with 100% coverage on content module
  • Update docs with usage examples and limits

Verification

  • All 8 content tests pass: bun test test/tool/registry.test.ts --test-name-pattern "tool.content"
  • 100% function and line coverage on content.ts

Fixes #9539

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9542 **State:** open **Merged:** No --- ## Summary Custom tools can now return images alongside text, allowing the LLM to actually see and analyze visual data. - Custom tools return `{ content: [{ type: "text", text }, { type: "image", mimeType, data }] }` - Backwards compatible: plain string returns still work - Images converted to attachments for model vision input ## Changes - Add `ToolContentPart` and `ToolResult` types to plugin - Add content normalization helper with validation (max 10 images, ~5MB each, PNG/JPEG/GIF/WebP) - Handle rich content in tool registry - Add `attachments` field to `tool.execute.after` hook - Add 8 unit tests with 100% coverage on content module - Update docs with usage examples and limits ## Verification - All 8 content tests pass: `bun test test/tool/registry.test.ts --test-name-pattern "tool.content"` - 100% function and line coverage on `content.ts` Fixes #9539
yindo added the pull-request label 2026-02-16 18:18:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13145