Visual and Tool Collaboration Design for Multimodal AI Agents
This article explains the key design considerations for building multimodal AI agents that jointly process visual and textual inputs and coordinate tool calls. It covers native multimodal fusion, unified model architecture, native-resolution patch packing, image and video encoding, staged training, dependency-aware parallel orchestration, and evaluation metrics for quality, latency, and concurrency.
1. Why Multimodal Models Need Native Fusion
For a long time, many multimodal systems followed a “train the language model first, then attach a vision module” approach. The language model already provided strong reasoning and generation capabilities, so development teams later added a vision encoder and used image-text data for alignment. This approach has relatively low engineering cost, but it has two inherent drawbacks: subsequent vision training may weaken language capabilities, and the alignment between visual features and the language embedding space is often insufficient.
Native fusion allows vision and text to share the same optimization objective from the early stages of training. During pretraining, the model processes interleaved image-text data, with visual and text tokens entering the same attention mechanism. The two modalities constrain and reinforce each other, enabling bidirectional improvement. The trade-off is a more complex training process: data mixing, learning-rate scheduling, and module-freezing strategies all need to be redesigned.
2. Three Components of a Unified Architecture
A typical unified multimodal architecture consists of three components:
- Vision encoder: Splits images or video frames into patches and maps them into a sequence of vectors.
- Projection layer: Aligns visual features with the language model’s embedding dimension and semantic space.
- Language backbone: Processes visual and text tokens through a unified sequence-modeling approach to perform cross-modal reasoning and generation.
The data flow is:
Image or video → Vision encoder → Visual feature sequence → Projection layer → [Visual tokens] + [Text tokens] → Language backbone → Output
The responsibility of each component should be clearly defined. The vision encoder handles spatial structure and local texture. The projection layer performs dimensional and distribution alignment. The language backbone performs cross-modal reasoning.
If the projection layer is too simple, visual details may be lost during alignment. If it is too complex, training stability may suffer. Its capacity should therefore be evaluated together with the scale of the vision encoder and language backbone.
3. Native Resolution and Variable-Length Patch Packing
Traditional visual preprocessing often resizes or crops images to a fixed resolution. This can distort the original aspect ratio and compress the details of small objects. Text-heavy images are particularly vulnerable to this loss of detail.
Variable-length patch packing preserves the original image resolution. The patches from each image are flattened into a one-dimensional sequence, and the sequences from multiple images are concatenated while recording the boundary of each image. During attention computation, the boundary information restricts each patch to attending only to patches from the same image.
The following pseudocode illustrates the idea. It is not a specific interface:
function pack_patches(images, patch_size):sequence = []boundaries = [0]for each image img in images# img has the shape channels × height × width and keeps its original resolutionpatches = split img into(height / patch_size) × (width / patch_size) patchesflatten each patch into a one-dimensional vectorappend patches to sequenceappend the last boundary value plus the number of patchesto boundariesreturn sequence, boundaries
In practice, the image height and width usually need to be integer multiples of the patch size, so rounding or padding may be required. The boundary array determines the attention mask and is essential for preventing interference between different images.
Sharing an Encoder Between Images and Video
Video can be viewed as a sequence of images over time. One common approach is to treat a small number of consecutive frames as a spatiotemporal block, pack the patches from all frames along the temporal dimension, and process them with the same vision encoder.
This approach has three advantages:
- It avoids designing a separate encoding branch for video, keeping the model architecture simpler.
- Spatial representations learned from image data can be transferred directly to video understanding.
- Training and inference can use a unified code path, reducing maintenance costs.
However, more frames produce longer sequences and increase attention-related computation. In engineering practice, keyframe sampling or frame-rate reduction is often performed before packing.
4. Decoupled Training Stages
During joint training of multiple modules, different components often converge at different speeds and exhibit different levels of stability. A common industry practice is to divide training into several stages and assign different learning rates or freezing strategies to each module. This reduces mutual interference.
A typical staged training process is:
- Vision pretraining: Train the vision encoder separately to learn general visual representations, using objectives such as image-text contrastive learning or image reconstruction.
- Alignment training: Freeze the vision encoder and language backbone, and train only the projection layer so that visual features enter the language model’s embedding space.
- Joint training: Unfreeze the language backbone and fine-tune the vision encoder with a smaller learning rate. Mix plain-text and image-text data to prevent language degradation.
- Instruction tuning: Perform unified alignment with instruction data that includes multi-turn dialogue, tool calls, and image-text question answering.
Each stage should have independent validation metrics. For example, alignment training can focus on visual question-answering accuracy, while joint training should also monitor pure-text benchmarks to ensure that improvement in one capability does not cause a significant decline in another.
5. Parallel Agent Orchestration
When agents handle complex tasks, a common workflow is to divide the task into multiple subtasks. The model then calls tools step by step, reads the results, and decides what to do next. If every step runs sequentially, total latency is the sum of the latency of all steps.
If subtasks do not depend on one another, they can run in parallel. In that case, end-to-end latency is determined by the longest path in the dependency graph, also known as the critical path.
If the parallelizable portion accounts for a fraction p of total execution time and the number of parallel paths is n, the theoretical speedup is:
S = 1 / ((1 - p) + p / n)
This formula shows that speedup is limited by the sequential portion. Even with many parallel workers, overall gains remain limited when the serial portion is large. Engineering teams should therefore analyze task dependencies before deciding how aggressively to parallelize.
Dependency-Graph Scheduling Example
The following pseudocode demonstrates the basic logic for executing tasks in parallel by dependency layer:
async function run_graph(task_table):# task_table: {task_name: (list_of_dependencies, execution_function)}results = {}pending = copy(task_table)while pending is not empty:ready = [name for name, (dependencies, _) in pendingif all dependency in results for dependency in dependencies]if ready is empty:raise Error("Cyclic dependency detected")concurrently wait for all ready tasks:execute the function using the results of its dependencieswrite outputs to resultsremove completed tasks from pendingreturn results
This scheduler executes tasks layer by layer. Tasks in the same layer run concurrently, while tasks in the next layer wait until all of their dependencies are complete.
Practical Issues
Parallel orchestration introduces several issues that should be addressed during system design:
- Concurrent write conflicts: When multiple subtasks modify the same file, record, or interface state, the system needs locks or separate write scopes.
- Errors and timeouts: When one subtask fails, the system should define whether to retry, skip it, or terminate the entire task. Every tool call should have a timeout.
- Scheduling overhead: If subtasks are too fine-grained, scheduling and context-assembly overhead may exceed the benefits of parallel execution. Task granularity should be large enough for each call to complete meaningful work.
- Result aggregation: Outputs from multiple paths should use a consistent format, and the aggregation step should handle partial failures.
6. Evaluation and Engineering Metrics
When evaluating multimodal agents, capabilities should be separated into categories, with a fixed benchmark set for each category. Common dimensions include code generation, visual understanding, mathematical reasoning, tool use, and interface operation. Results are comparable only when each category uses the same evaluation scripts and parameter settings.
When comparing different approaches, the following variables should also be controlled:
- Whether tool permissions and the available tool set are identical.
- Whether the context-length budget and input image resolution are identical.
- Whether generation parameters such as sampling temperature and maximum output length are identical.
For latency evaluation, it is recommended to record the time to the first token, end-to-end latency, and throughput under concurrent workloads.
