feat(plugin): add subagent delegation mode#2
Open
Olbrasoft wants to merge 1 commit into
Open
Conversation
Add VISION_MODE env var to support two delegation strategies: - 'api' (default, original): vision tool calls external VLM API - 'subagent' (new): LLM delegates to @image-reader subagent via Task tool Auto-fallback: uses 'api' when VISION_API_KEY is set, otherwise 'subagent'. This lets the plugin work out-of-the-box without external API credentials, reusing a vision-capable model already configured in opencode (e.g. opencode-go/minimax-m3) via a subagent definition. New env vars: - VISION_MODE: 'api' | 'subagent' (auto-detected if unset) - VISION_SUBAGENT_NAME: subagent identifier (default: 'image-reader') The original api mode is left untouched — all existing env vars and the vision tool behave exactly as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
VISION_MODEenv var to support two delegation strategies for non-vision models:apimode (default, original): thevisiontool calls an external VLM API (VISION_API_KEY+VISION_API_URL). This is the existing behaviour — left untouched.subagentmode (new): the plugin instructs the LLM to delegate image analysis to a vision-capable subagent via theTasktool. No external API key required — the subagent runs on whatever multimodal model is configured in opencode (e.g.opencode-go/minimax-m3).Auto-fallback
When
VISION_MODEis unset, the plugin auto-detects:apimode ifVISION_API_KEYis presentsubagentmode otherwiseThis means the plugin works out-of-the-box without any external credentials, as long as a vision-capable subagent is configured.
Motivation
Many users run a powerful non-vision model (e.g. GLM-5.2) as their primary agent and already have a multimodal model available via their opencode provider (e.g.
opencode-go/minimax-m3,qwen3-vlvia Ollama). Requiring a separate MiniMax Group API Key with Token Plan access — or any external VLM endpoint — adds friction for users who already have a vision model at hand.Related: #29550 (Task tool should support passing image/file attachments to subagents) — the subagent mode is a complementary workaround that works today without changes to the Task tool.
Changes
plugins/vision-helper.tsVISION_MODE("api" | "subagent") with auto-fallback based onVISION_API_KEYpresenceVISION_SUBAGENT_NAME(default: "image-reader") for configurable subagent identifierexperimental.chat.system.transform: inject delegation instruction for non-vision models in subagent modeexperimental.chat.messages.transform: path hint includes— use @image-reader subagent via Task toolsuffix in subagent modeisPluginInjectedText: extended regex to match new hint format (cleanup on re-transform)apimode behaviour preserved — no breaking changesREADME_en.mdVISION_MODEandVISION_SUBAGENT_NAMEenv varsSetup for subagent mode
~/.config/opencode/agent/image-reader.md:Either set
VISION_MODE=subagentor simply leave it unset (auto-fallback kicks in whenVISION_API_KEYis absent).Restart opencode. The plugin will:
/tmp/opencode-vision/image{N}/Test plan
bun buildclean)apimode still works (no env vars changed for existing users)subagentmode: image pasted → plugin saves to tmp → injects hint → GLM-5.2 delegates to @image-reader (MiniMax M3) → description returned to userVISION_API_KEYand noVISION_MODE, plugin uses subagent modeBackwards compatibility
✅ No breaking changes. Existing users with
VISION_API_KEYset get identical behaviour to v1.7.0. The new subagent mode only activates whenVISION_API_KEYis absent orVISION_MODE=subagentis explicit.