Multimodal Extension for Text-Only LLMs: A Hook-Based Agent Workflow

    This article explains how to add image understanding to text-only LLM agent setups without changing the underlying model. It describes the visual blind spot of cost-effective text models, why OCR/manual paste and temporary model switching disrupt workflows, and how an agent hook can intercept image input, send it to a vision model for structured transcription, and inject the resulting text back into the conversation. It also covers the data flow, transcription prompt design, practical issues such as latency, context growth, error propagation, and privacy, and how the same hook-based approach can be extended to other capabilities.

    The Problem: The Visual Blind Spot of Cost-Effective Text Models

    In practice, many teams build their AI coding environments with a combination of an agent shell and a remote LLM inference service. The shell handles file reading and writing, command execution, task planning, and other agent capabilities, while the backend inference service handles code generation and logical reasoning. This combination is cost-effective and stable, and it performs well in text-only coding scenarios: writing code, refactoring, and troubleshooting errors all work without issue.

    But text models have a hard limitation: they cannot process image input. When a user pastes a screenshot of a frontend error into the chat box, the interface only reports an unsupported image type, and the entire workflow is forced to stop.

    This limitation has a significant impact on daily development because image interaction is a high-frequency requirement:

    • A frontend page shows an anomaly, and the screenshot is handed to the agent so it can locate the cause of the rendering error.
    • A UI design mockup is available, and the screenshot is sent to the model so it can generate the corresponding frontend code.
    • During browser automation testing, screenshots are needed to determine the current page state and decide the next action.
    • A scanned contract, invoice, or legal document is received, and the model is expected to extract key field information.

    With natively multimodal models, these scenarios work smoothly. Once the model is switched to a text-only model, they all fail. The problem is not the agent shell but the limited input modality of the model itself.

    Why Common Workarounds Are Clumsy

    Faced with this limitation, the two most intuitive solutions are not elegant enough.

    Approach 1: Recognize text first, then paste it manually. A general optical character recognition (OCR) tool can extract text from a screenshot, which is then copied and pasted to the model. This works, but every instance requires switching tools and performing several extra steps. More critically, non-text information such as chart structure, interface layout, and spatial relationships between elements is lost, and this information is exactly what matters for frontend debugging and design mockup reproduction.

    Approach 2: Temporarily switch models when an image appears. Another model that supports vision can be asked separately. This is also feasible, but it interrupts the entire workflow: the context of the original conversation cannot be carried over, the problem must be described again, and the answer must be manually moved back to the main session. The cognitive burden of frequent switching is greater than expected.

    The common issue with both approaches is that the human is accommodating the machine rather than the machine adapting to the human. A good engineering solution should make capability differences transparent to the user: the user only needs to paste the image, and the system handles the rest.

    Core Idea: Give the “Blind” Model a Translator

    The value of an agent lies not only in the capabilities of the underlying model but also in the extensibility of its architecture. Most mainstream AI coding tools provide hook mechanisms that allow developers to insert custom scripts at key points in the agent lifecycle, such as before user input is submitted, before a tool is called, and after a model response is received.

    Based on this mechanism, the idea is clear: can a hook script intercept image data before it is sent to the text model, pass it to a model with vision understanding so it can be “translated” into a detailed text description, and then inject that text back into the conversation context?

    Essentially, this gives a “blind but intelligent” model a “translator that can see.” The text model handles deep reasoning, the vision model handles perception and description, and the hook script connects the two.

    The overall data flow is as follows:

    1. The user pastes an image in the client, triggering the “before user input submission” hook.
    2. The hook script checks whether the input contains image attachments.
    3. If so, it encodes the image and sends it to the vision understanding model along with a carefully designed transcription prompt.
    4. The vision model returns a structured text description, including error text, interface layout, element relationships, colors and styles, and so on.
    5. The hook script injects the description into the user message in an agreed format, replacing or marking the original image position.
    6. The combined text-only message is sent normally to the text model, and the reasoning flow is unaffected.

    An illustrative hook script skeleton (pseudo-code):

    1. on_user_submit(message):
    2. images = extract_images(message)
    3. if images is empty:
    4. return message # No images, pass through directly
    5. for img in images:
    6. description = call_vision_model(img, TRANSCRIBE_PROMPT)
    7. message = inject_text(message, f"[Image description] {description}")
    8. return message

    Transcription Prompt Engineering: The Key to Success

    The difficult part of this approach is not interception but transcription quality. If the vision model only outputs “this is an error screenshot,” it provides no help to the text model. The transcription prompt must guide the vision model to produce descriptions that serve downstream reasoning. The key points include:

    First, require complete transcription of visible text. Error stacks, status codes, file paths, line numbers, and similar details must be preserved verbatim rather than summarized or rewritten, because precise error information is the key clue for locating the problem.

    Second, require description of spatial structure. For interface screenshots, the prompt should ask for the relative positions, hierarchy, and size proportions of elements. For design mockups, it should include color schemes, font styles, and spacing characteristics so the downstream model can reproduce the layout.

    Third, require separation of facts from speculation. The description section should be strictly based on the image content, while the analysis section should be marked separately to prevent misjudgments by the vision model from contaminating the text model’s reasoning basis.

    Fourth, prepare multiple prompt templates for different scenarios. Error screenshots, design mockups, and scanned documents require completely different transcription priorities, and the hook script can select a template based on user instructions or image characteristics.

    Practical Pitfalls and Optimization Directions

    Several typical issues arise in practice.

    First, hook execution latency. Image transcription introduces an additional model call, so the user must wait several seconds after submission. This can be mitigated by processing multiple images asynchronously in parallel and caching identical images by hash.

    Second, context expansion. Detailed image descriptions may consume a large context window and squeeze the space available for subsequent conversation. The description length should be capped, and overly long descriptions should be summarized hierarchically.

    Third, error propagation. Recognition errors from the vision model can directly mislead the text model. For critical information such as error codes, the prompt can require the vision model to output confidence levels, and low-confidence content should be explicitly marked as “possibly misrecognized.”

    Fourth, privacy and compliance. Screenshots may contain internal domain names, keys, or personal information. The hook script is a natural privacy control point and can perform regex filtering or masking before sending data onward.

    Conclusion and Extensions

    The essence of this approach is to use the programmability of the agent architecture to turn multimodal capability from a model property into a system property. As long as the agent framework provides sufficiently rich hooks, text models and vision models can be freely combined like two processing nodes in a pipeline. The same idea can be extended further: connect speech transcription to text models for voice input, connect document parsing capabilities to handle various attachments, or even automatically inject retrieved knowledge snippets before requests. Mastering the hook mechanism is equivalent to mastering the key to assembling agent capabilities on demand, making “the machine adapting to the human” the default experience.