Multimodal Agent Vision and Tool Capabilities: Architecture and Engineering Practices
This article explains why vision capabilities for multimodal agents should be integrated during pretraining rather than added later. It then outlines a unified multimodal architecture, native-resolution patch packing, and shared image-video modeling, with attention to routing balance, token budgets, and compute trade-offs.
1. Problem Background: Why Vision Cannot Be Bolted On Later
A common approach in early multimodal systems was to train a text-only language model first, then connect a separately trained vision encoder, and finally align the two with a small amount of image-text data. This pipeline has relatively low engineering cost, but it comes with two problems.
First, visual and language representations are unaware of each other during pretraining. Their semantic spaces can only be fitted through later alignment, and gaps can appear between image details and language reasoning. A model may be able to describe the general content of an image, yet fail to read numbers in a table or small text in a user interface accurately.
Second, subsequent training can cause capability conflicts. Continuing to strengthen language ability may degrade visual understanding, and vice versa. Developers often observe that a model becomes better at text reasoning while its chart-reading performance gets worse.
The recent technical direction is therefore to optimize text and vision jointly early in training. The same backbone receives both types of data and builds representations in the same semantic space. For developers, this means whether a model can understand screenshots, documents, and videos depends not only on the size of the vision encoder, but also on how the two data types are mixed and jointly optimized during training.
2. Three Layers of a Unified Multimodal Architecture
A typical unified architecture can be divided into three stages.
- Visual feature extraction: an encoder splits an image or video into visual units and outputs a set of feature vectors.
- Cross-modal projection: a lightweight projection layer, commonly implemented as a multilayer perceptron, maps visual features into the language model’s embedding space so that their dimensions and value distributions align with text tokens.
- Unified modeling in the language backbone: visual tokens and text tokens are concatenated and fed into the backbone for end-to-end modeling.
If the backbone uses a mixture-of-experts (MoE) structure, each token activates only part of the experts, which can balance parameter scale and per-inference compute. In multimodal scenarios, however, the routing mechanism may develop modality bias, where some experts become overly biased toward visual tokens. Training usually needs load-balancing constraints, and the distribution of different modalities across experts should be monitored.
The following sample code shows the basic input organization flow:
def encode_multimodal(inputs):tokens = []for item in inputs:if item.type == "text":tokens.extend(text_tokenizer(item.content))elif item.type in ("image", "video"):feats = vision_encoder(item.pixels) # visual features, shape [N, D_v]tokens.extend(projector(feats)) # after projection, shape [N, D_lm]return backbone(tokens) # unified end-to-end modeling
3. Native-Resolution Input: Patch Packing Strategy
Fixed-resolution approaches resize or crop images to a uniform size before splitting them into patches. This causes two kinds of loss. One is aspect-ratio distortion, which can break geometric relationships. The other is that fine lines and small text become hard to recognize after scaling.
A native-resolution approach does not apply fixed-size transformation. It first splits an image into patches, flattens the patches into a one-dimensional sequence, and sends them to the encoder with 2D positional information. Images of different sizes can each produce sequences of different lengths without being normalized to the same size.
The benefits and costs are as follows.
- Benefits: the original aspect ratio and details are preserved, and performance is more stable on information-dense images such as documents, tables, and interface screenshots.
- Costs: larger images produce more tokens, and attention compute grows with sequence length. In engineering practice, a maximum pixel budget is usually set. When it is exceeded, the image may be downsampled proportionally, or large blank areas may be cropped.
Sample code:
def patchify(image, patch_size):h, w = image.height, image.width# Pad any edge shorter than one patch with zeros to avoid stretching the original imagepad_h = (-h) % patch_sizepad_w = (-w) % patch_sizepadded = pad(image, bottom=pad_h, right=pad_w)patches, coords = [], []for r in range(0, padded.height, patch_size):for c in range(0, padded.width, patch_size):patches.append(padded[r:r+patch_size, c:c+patch_size])coords.append((r // patch_size, c // patch_size))return flatten(patches), coords
4. Unified Modeling for Images and Video
Video can be viewed as a sequence of images along the time dimension. A common approach is to design a separate temporal module for video, but this creates two independent branches for images and video. Parameters are difficult to share between the branches, and spatial understanding learned from images is hard to transfer directly to video tasks.
Another approach treats several consecutive frames as a spatiotemporal volume. Patches from each frame are packed together into the same sequence, and the same encoder models attention over spatial and temporal dimensions. An image can be treated as a special case with only one frame, so both share one set of parameters.
This approach has two direct benefits. First, image data and video data can be trained together, and spatial understanding can directly serve video. Second, deployment only needs to maintain one encoder, reducing model versions and inference paths.
The costs are also clear. The longer the spatiotemporal volume, the longer the sequence and the higher the compute cost. In practical design, trade-offs are needed among frame count, per-frame resolution, and sampling rate. For example, action-understanding tasks usually require a higher temporal sampling rate, while long-video summarization relies more on selecting keyframes.
The sample code begins as follows:
```text
def pack_clips(frames
