Use AIUnderstand AIBuild with AI
Build with AI·Model deep dive·· 4 min read

Mage-VL-Cowork: a 4B Computer-Use Agent That Clicks and Runs Code

Microsoft's 4B vision-language agent chooses between GUI actions and bash on each turn. Load it with transformers or serve it with SGLang.

The code in this post comes from the model's docs and hasn't been run in our CI yet. If something breaks, let us know.

Mage-VL-Cowork is a 4B-parameter computer-use agent from the Microsoft Mage Team. It reads a screenshot and a task, then decides on each turn whether to act in the graphical interface (computer_use) or run a shell command (bash). The card says it does this in a single vision-language policy, with no external orchestrator.

The notable claim: 66.0% on OSWorld-Verified under a 50-step budget, which the card describes as the best result among 4B models.

Key specs

Property From the card
Parameters 4B (9.48 GB in bfloat16, 2 safetensors shards)
Backbone Mage-ViT + Qwen3-4B (Qwen3-4B-Instruct-2507)
Context length 32,768 tokens active (architecture supports up to 262,144)
Action channels computer_use (11 GUI primitives, coordinates in [0, 999]) and bash
Output format <think>...</think>, then Action:, then <tool_call>...</tool_call>
Working memory 3 most recent screenshots, 4 full responses, older turns folded into Action: summaries
License Apache-2.0

On OSWorld-Verified (361 tasks, Google Drive excluded, 50 steps) the card reports 66.0% as a two-run average. In the same table, ScaleCUA-Qwen3.5-9B scores 68.7 and GPT-5.4-mini scores 69.6, so it is the best 4B result in that table, not the best overall.

Install

Terminal window
pip install "transformers>=4.57.3" accelerate pillow torch torchvision qwen-vl-utils

The architecture is custom (llava_onevision2), so the card says to always pass trust_remote_code=True, and not to assume it works with standard Qwen3-VL classes.

Run it with transformers

The card’s example needs the verbatim MAGE_HYBRID_SYSTEM_PROMPT from its Quick Start section. Copy that prompt into a file called system_prompt.txt first. This script then loads it and the model:

step.py
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
model_path = "microsoft/Mage-VL-Cowork"
with open("system_prompt.txt", encoding="utf-8") as f:
MAGE_HYBRID_SYSTEM_PROMPT = f.read()
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path,
trust_remote_code=True,
torch_dtype=torch.bfloat16,
device_map="auto",
).eval()
screenshot = Image.open("desktop_screenshot.png").convert("RGB")
task_instruction = (
"Merge cells A1:D1 in /home/user/Desktop/budget.xlsx, "
"set the title to 'Q4 Summary', and save the file."
)
messages = [
{"role": "system", "content": MAGE_HYBRID_SYSTEM_PROMPT},
{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": f"Task: {task_instruction}"},
],
},
]
prompt = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = processor(text=[prompt], images=[screenshot], return_tensors="pt").to(model.device)
if "pixel_values" in inputs:
inputs["pixel_values"] = inputs["pixel_values"].to(model.dtype)
with torch.inference_mode():
output_ids = model.generate(
**inputs,
max_new_tokens=4096,
temperature=0.7,
top_p=0.8,
do_sample=True,
)
response = processor.tokenizer.decode(
output_ids[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True
)
print(response)

For the spreadsheet task, the card’s example output chooses bash and edits the file with openpyxl, because it is a structured edit to an existing .xlsx file. That choice between channels is the point of the model.

Serve it with SGLang

The card recommends a pre-built Docker image (docker.io/xiaoyizhang/mage-vl-cowork:0.1.0, with SGLang 0.5.2, PyTorch 2.8.0+cu128, Transformers 5.7.0 and FlashInfer 0.3.1):

Terminal window
export MODEL_DIR=/path/to/Mage-VL-Cowork
docker pull xiaoyizhang/mage-vl-cowork:0.1.0
docker run --rm --name mage-vl-cowork \
--gpus 'device=0' --shm-size=8g \
-p 127.0.0.1:30001:30001 \
--mount "type=bind,src=${MODEL_DIR},dst=/models/Mage-VL-Cowork,readonly" \
xiaoyizhang/mage-vl-cowork:0.1.0

To launch SGLang from your own environment instead, the card gives:

Terminal window
export SGLANG_MAX_PIXELS=4000000
python -m sglang.launch_server \
--model-path microsoft/Mage-VL-Cowork \
--served-model-name Mage-VL-Cowork \
--host 0.0.0.0 \
--port 30001 \
--trust-remote-code \
--dtype bfloat16 \
--context-length 32768 \
--mem-fraction-static 0.82 \
--tool-call-parser qwen25 \
--attention-backend flashinfer \
--mm-attention-backend triton_attn

SGLANG_MAX_PIXELS=4000000 is there to keep full 1920×1080 desktop fidelity. When you send screenshots, the card says to render the prompt with AutoProcessor.apply_chat_template and post base64 images to SGLang’s native POST /generate endpoint using image_data. The card does not show a complete client for this; its bundled MAGEHybridAgent (in osworld_eval/) is the reference.

Reading the model’s turn

Every turn has the same three parts: a <think> block, a one-line Action:, and one or more <tool_call> blocks (at most 15, all calling the same function). Coordinates are normalized to [0, 999]. The card gives the conversion to real pixels as x = round(coord_x * width / 1000), so for a 1920×1080 screen:

coords.py
def to_pixels(coord_x: int, coord_y: int, width: int = 1920, height: int = 1080):
return round(coord_x * width / 1000), round(coord_y * height / 1000)
print(to_pixels(500, 500))

A bash call comes back as text (merged stdout/stderr in a <tool_response>), while a computer_use call comes back as a new screenshot. Your loop has to feed the right one back. The card does not document a full agent loop beyond its OSWorld harness, so build and test yours against osworld_eval/mm_agents/mage_hybrid_agent.py.

For the 66.0% configuration the card lists temperature 0.7 (or 0.0 for deterministic single-run use), top_p 0.8, and max_new_tokens 4096, shared across <think>, Action: and <tool_call>.

Gotchas

  • It runs commands. The card states the model can execute arbitrary shell commands and GUI actions and is designed for isolated, disposable sandboxes such as Docker containers or snapshot-reverted VMs. Don’t point it at your own desktop.
  • Safety practices from the card: no access to host filesystems or local networks, no personal SSH keys, cloud tokens, cookies or password stores, human confirmation before irreversible actions, and network allow-listing when handling untrusted web content (to limit indirect prompt injection).
  • Use the exact system prompt. The card says to use its prompt verbatim for best performance.
  • Custom code. Always trust_remote_code=True; weights are not drop-in for standard Qwen3-VL classes.
  • Context. The 32,768-token window is what the model was trained and run with. Older screenshots beyond the last three are dropped from view, with earlier steps kept only as one-line Action: summaries.
  • Benchmark scope. The 66.0% comes from the card’s own harness (MAGEHybridAgent, 50 steps, 1920×1080). Don’t expect the same number from a different scaffold.

When to pick it

Pick it if you are experimenting with a small, Apache-2.0 computer-use agent that can mix clicking with scripting, and you can give it a throwaway sandbox. The card’s side-by-side demos report a spreadsheet task finished in 6 steps via Python against 39 GUI steps for a 27B GUI-only model, which is the kind of task where a shell channel helps.

Skip it if you need unattended access to real accounts or personal files, if you need the highest score in the table (larger and proprietary models score higher), or if you want a ready-made agent loop: the card provides evaluation harness code, not a general-purpose product.

Related