A Low-Cost Architecture for Augmenting Text Models with Vision Capabilities
While pure text models excel in tasks like code generation and logical reasoning, they lack native image understanding. Directly migrating to multimodal models incurs high costs and infrastructure changes. This article introduces a low-cost architecture that decouples planning and perception: the main text model decides when to invoke a lightweight multimodal model as a vision adapter. By utilizing structured protocols, placeholders, strict budget controls, and security measures, this approach seamlessly extends text models' capabilities without disrupting existing engineering pipelines.
I. Problem Definition: Why a “Vision Plugin”?
Pure text models already possess strong capabilities in tasks like code generation, logical reasoning, and planning breakdown, but their input boundaries remain limited to text. When users upload screenshots, invoices, tables, UI designs, flowcharts, or field photos, the main model cannot directly understand the image content. Replacing the model directly with a multimodal main model is certainly an option, but it introduces migration costs, higher inference costs, context bloat, and the need to modify existing engineering pipelines.
A more pragmatic approach is to decouple “planning and decision-making” from “visual perception”: the main text model continues to be responsible for understanding tasks, formulating plans, and deciding whether it needs to look at images; a lightweight multimodal model acts as a visual adapter, invoked only when necessary to return structured recognition results. This approach does not change how the main model is invoked, allows visual capabilities to be expanded on demand, and enables cost control through budget management, caching, and fallback strategies.
The architecture is built on four core principles: First, images are not pushed directly into the main model’s context; instead, placeholders and reference identifiers are injected. Second, the main model initiates visual requests through a structured protocol rather than automatically calling the vision service for every image. Third, visual results are backfilled as “tool return data” and explicitly marked as untrusted data. Fourth, all calls must be constrained by budget, timeout, cache, audit, and fallback mechanisms.
II. Overall Architecture: Intercept, Placeholder, Decide, Forward, Backfill
The entire workflow can be summarized as follows: The message interception layer identifies attachments, saves the images, and generates placeholder text. Upon seeing the placeholder in its context, the main model decides whether to initiate a visual request based on the user’s question and task objectives. The vision gateway parses the request, invokes the lightweight multimodal adapter, and returns structured results. The main model continues reasoning based on the results and, if necessary, initiates a second round of more fine-grained visual requests. The session layer is responsible for managing round limits, budgets, timeouts, and fallbacks.
The key here is not “sending every image through a vision model,” but “allowing the main model to request visual information on demand.” The stronger the main model’s planning capabilities, the better it can determine whether an image is relevant to the current task, whether a holistic summary or local details are needed, and whether OCR or table structure recognition is required. The visual adapter is only responsible for perception, not the final decision, thereby preventing complex reasoning from overwhelming the vision service.
For message representation, it is recommended to standardize the attachment reference format, such as [image id=... hint=...]. The placeholder should only carry lightweight metadata like references, dimensions, content type, and user notes—not binary data. The image itself is stored in object storage or an attachment service and accessed via short-term signed URLs or internal references. This ensures the main model’s context is not bloated with image data, and visual results can be cropped and cached on demand.
III. Protocol Design: Structured Vision Requests and Results
When the main model initiates a visual request, it should output verifiable structured data rather than natural language instructions. It is recommended that the request includes: image reference, question intent, region of interest, detail level, expected output type, and confidence requirements. The result should include: an overall summary, OCR results, layout or table structure, key entities, uncertainty notes, and time/cost metadata. A structured protocol allows the gateway to validate, retry, audit, and swap out underlying adapters easily.
Visual results must be backfilled as tool return data and explicitly marked as untrusted data. Text within images may contain prompt injection content, which must not be allowed to override system instructions. When referencing visual results, the main model should include the image reference for traceability. For high-risk scenarios, visual results can be required to include an uncertainty field; low confidence can trigger more fine-grained cropping or manual review.
Illustrative pseudocode is as follows:
def intercept_and_rewrite(messages, store):for m in messages:for att in m.attachments:ref = store.put(att.bytes, content_type=att.content_type)# Append a lightweight placeholder with metadatam.text += "\n[image id={} hint={}]".format(ref.id, att.name or "User uploaded image")return messagesdef run_session(messages, text_model, vision_gateway, budget):messages = intercept_and_rewrite(messages, object_store)for _ in range(budget.max_steps):out = text_model.chat(messages)req = parse_vision_request(out)if req is None:return outif not budget.allow(req):result = {"status": "denied", "reason": "budget"}else:result = vision_gateway.describe(image_id=req.image_id,question=req.question,detail=req.detail)messages.append({"role": "tool","name": "vision","content": to_json(result),"trust": "untrusted-data"})return {"status": "fallback", "message": "Vision analysis round limit reached"}
IV. Vision Adapter: Preprocessing, Cache, Budget, and Fallback
The vision adapter should standardize its interface and internally handle image validation, size compression, format conversion, metadata cleanup, crop candidate generation, and desensitization. For large images, a thumbnail can be generated first for an overall summary; when the main model requests local details, the image is cropped by region. The cache key should be composed of the image content hash, question intent, and detail level to avoid duplicate calls for the same image. For multi-image tasks, images can be sorted by relevance and concurrency can be limited.
Cost control should be implemented at both the session and tenant levels: each session should limit the number of vision calls, single-call timeout, maximum output length, and total cost. When the budget is insufficient, a clear fallback message should be returned rather than failing silently. Latency optimization can utilize asynchronous prefetching, parallel calls, result caching, and tiered recognition: return a low-cost summary first, and dig deeper if necessary. When the vision service is unavailable, the main model should be able to continue answering based on placeholders and user descriptions, prompting the user to provide supplementary text information.
V. Security Governance and Observability
In terms of security, it is necessary to enforce tenant isolation, attachment access control, short-term signed URLs, audit logs, and log desensitization. Image content safety, text recognition result filtering, prompt injection prevention, and output content moderation should all be handled at the gateway layer and the result backfill layer. Visual results must only be used as data, not executed as instructions. For sensitive images, a no-disk-cache or short-term retention policy should be supported, and access paths must be logged.
Regarding observability, it is recommended to monitor the vision call success rate, timeout rate, cache hit rate, average rounds, cost per unit task, fallback rate, and injection attack interception rate. Logs should record image references, request intents, result summaries, and budget consumption, but must not log sensitive original images or complete recognized text. During deployment, a general container platform can host the gateway, object storage can save attachments, and logging services with monitoring and alerting can establish observability; for instance, general container, object storage, and logging/monitoring services provided by Baidu AI Cloud can fulfill these roles.
VI. Evaluation and Deployment Path
Before going live, an offline evaluation set should be built, covering screenshot Q&A, invoice recognition, table extraction, UI understanding, low-quality images, multi-image correlation, and prompt injection samples. Metrics include recognition accuracy, hallucination rate, request count, end-to-end latency, cost per unit task, and fallback rate. Begin with a shadow mode (logging only, no effect), then move to a canary release with low traffic to compare task completion rates and costs before and after enabling the vision plugin, and finally roll out gradually by tenant and scenario.
During evaluation, do not solely focus on single-pass recognition accuracy; also evaluate “whether the main model requests visual information at the correct time.” False triggers increase costs, while missed triggers reduce task completion rates. It is recommended to simultaneously evaluate the precision and recall of the requests, and continuously optimize through prompt engineering, protocol validation, and budget strategies. The ultimate goal is not to let the vision model replace the main model, but to expand the main model’s capability boundaries at a controllable cost, enabling non-vision models to acquire reliable image understanding capabilities when needed.
