Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

perf(cu): step missions on the provider's FAST vision model + action aliases

Ruben Lütke3444356b1da3
diff --git a/jarvis/brain/model_catalog.py b/jarvis/brain/model_catalog.py
index b315e9ff2c..0a4f597752 100644
--- a/jarvis/brain/model_catalog.py
+++ b/jarvis/brain/model_catalog.py
@@ -372,6 +372,59 @@ def pick_vision_model(provider: str) -> str | None:
return usable[0].id if usable else None
+#: Name markers of the FAST model class (low-latency siblings). Computer-Use
+#: issues one vision call per step, so step latency — not peak intelligence —
+#: dominates mission wall-clock (live forensic 2026-07-02: think=60.8s of a
+#: 75.8s mission on a flagship model). Data, not logic; extend by adding a row.
+_FAST_CLASS_MARKERS: tuple[str, ...] = (
+ "flash", "haiku", "mini", "lite", "turbo", "air", "nano",
+)
+
+
+def pick_fast_vision_model(provider: str) -> str | None:
+ """The best FAST vision-capable model of ``provider`` (or ``None``).
+
+ Same candidate set as :func:`pick_vision_model` (vision input + the brain
+ filter), but the fast class leads: a "flash"/"haiku"/"mini"-style sibling
+ of a known family beats the flagship. Within each band the picker's
+ relevance sort decides. Falls back to the plain vision pick when the
+ provider has no fast vision sibling.
+ """
+ from jarvis.core import config as _cfg # noqa: PLC0415
+
+ cache_path = _cfg.DATA_DIR / "model_catalog_cache.json"
+ try:
+ data = json.loads(cache_path.read_text(encoding="utf-8"))
+ entries = data.get(provider, {}).get("models", [])
+ except Exception: # noqa: BLE001 — missing/corrupt cache → no pick
+ return None
+ candidates: list[ModelInfo] = []
+ for m in entries:
+ mid = str(m.get("id") or "").strip()
+ inp = m.get("input_modalities")
+ if not mid or not (isinstance(inp, list) and "image" in inp):
+ continue
+ out_mods = m.get("output_modalities")
+ params = m.get("supported_parameters")
+ candidates.append(ModelInfo(
+ id=mid,
+ label=str(m.get("label") or mid),
+ output_modalities=tuple(out_mods) if isinstance(out_mods, list) else None,
+ input_modalities=tuple(str(x) for x in inp),
+ supported_parameters=tuple(params) if isinstance(params, list) else None,
+ ))
+ usable = sort_models(provider, filter_brain_models(candidates))
+ if not usable:
+ return None
+ # Fast class first — but only KNOWN families (family rank > 0), so an
+ # obscure "-mini" of an unknown vendor never beats a Gemini Flash / Haiku.
+ for m in usable:
+ low = m.id.lower()
+ if _family_rank(m.id) > 0 and any(mark in low for mark in _FAST_CLASS_MARKERS):
+ return m.id
+ return usable[0].id
+
+
def _output_modalities(entry: dict) -> tuple[str, ...] | None:
"""Pull ``architecture.output_modalities`` from a model entry as a tuple.
diff --git a/jarvis/cu/brain_call.py b/jarvis/cu/brain_call.py
index d99ba1faf8..b52f48d308 100644
--- a/jarvis/cu/brain_call.py
+++ b/jarvis/cu/brain_call.py
@@ -50,46 +50,73 @@ class BrainReply:
PromptBuilder = Callable[[str, Any], tuple[str, str]]
-def _rescue_blind_models(
+def _speed_tune_chain(
chain: list[tuple[str, str | None]],
+ *,
+ pinned: set[str] = frozenset(), # type: ignore[assignment]
) -> list[tuple[str, str | None]]:
- """Swap a KNOWN-blind configured model for the provider's best
- vision-capable sibling, per candidate.
-
- Computer-Use is screenshot-grounded; a text-only model choice (e.g. an
- OpenRouter DeepSeek pin) previously knocked the WHOLE provider out of the
- chain even though the user's key unlocks plenty of vision models — a
- "works with whatever key you have" violation (AP-22). Only an explicit
- ``vision is False`` verdict from the model catalog triggers the swap;
- unknown capability stays untouched (no regression for providers without
- modality metadata). Never raises — any lookup problem keeps the original
- pair.
+ """Per candidate: keep an explicit CU pin verbatim; otherwise put the
+ provider's FAST vision-capable model on the mission steps.
+
+ Two problems, one move (both live-measured 2026-07-02):
+
+ * A KNOWN-blind configured model (OpenRouter DeepSeek pin) knocked the
+ whole provider out of the chain although the same key unlocks vision
+ models (AP-22) — it must be swapped regardless.
+ * A flagship configured model made every step THINK for seconds
+ (think=60.8s of a 75.8s mission on Opus over OpenRouter). Computer-Use
+ issues one small vision call per step — the fast class (flash/haiku/
+ mini) answers in a fraction of the time at no relevant quality loss
+ for "click/type/verify" decisions.
+
+ Providers whose catalog exposes no modality data (direct Gemini/Claude
+ endpoints) return no pick and stay untouched — their configured fast-tier
+ model already IS the fast class. Never raises; any lookup problem keeps
+ the original pair.
"""
try:
from jarvis.brain.model_catalog import ( # noqa: PLC0415
model_capabilities,
- pick_vision_model,
+ pick_fast_vision_model,
)
except Exception: # noqa: BLE001
return chain
- rescued: list[tuple[str, str | None]] = []
+ tuned: list[tuple[str, str | None]] = []
for provider, model in chain:
+ if provider in pinned:
+ tuned.append((provider, model))
+ continue
try:
- if model and model_capabilities(provider, model).get("vision") is False:
- alt = pick_vision_model(provider)
- if alt and alt != model:
+ caps = model_capabilities(provider, model) if model else {}
+ blind = caps.get("vision") is False
+ alt = pick_fast_vision_model(provider)
+ if alt and alt != model and (blind or model):
+ if blind:
logger.info(
"[cu] %s model %s cannot see the screen — using the "
"vision-capable %s for this mission",
provider, model, alt,
)
- rescued.append((provider, alt))
- continue
- except Exception: # noqa: BLE001 — rescue is best-effort
- logger.debug("[cu] vision-model rescue failed for %s", provider,
- exc_info=True)
- rescued.append((provider, model))
- return rescued
+ else:
+ logger.info(
+ "[cu] %s: stepping with the fast vision model %s "
+ "instead of %s (pin a Computer-Use model in Settings "
+ "to override)",
+ provider, alt, model,
+ )
+ tuned.append((provider, alt))
+ continue
+ if blind:
+ # Known-blind and no vision sibling — the selector's
+ # blind-skip will drop it; nothing better to offer.
+ logger.info(
+ "[cu] %s model %s cannot see the screen and no vision "
+ "sibling is known", provider, model,
+ )
+ except Exception: # noqa: BLE001 — tuning is best-effort
+ logger.debug("[cu] speed-tune failed for %s", provider, exc_info=True)
+ tuned.append((provider, model))
+ return tuned
async def call_vision_brain(
@@ -135,19 +162,27 @@ async def call_vision_brain(
raise CUBrainCallError("BrainManager fallback chain is empty")
# Per-provider CU model override (Settings can pin a dedicated CU model).
+ # A PIN is the user's explicit word and is never second-guessed; every
+ # unpinned candidate is speed-tuned below.
cu_model = getattr(manager, "_cu_model", None)
+ pinned_providers: set[str] = set()
if callable(cu_model):
resolved_chain: list[tuple[str, str | None]] = []
for provider, model in chain:
try:
- resolved_chain.append((provider, cu_model(provider) or model))
+ pin = cu_model(provider)
except Exception: # noqa: BLE001
+ pin = None
+ if pin:
+ pinned_providers.add(provider)
+ resolved_chain.append((provider, pin))
+ else:
resolved_chain.append((provider, model))
chain = resolved_chain
images_attached = bool(images)
if images_attached:
- chain = _rescue_blind_models(chain)
+ chain = _speed_tune_chain(chain, pinned=pinned_providers)
selector = ComputerUsePlannerSelector(manager=manager, chain=chain)
attempted = 0
diff --git a/jarvis/cu/conventions.py b/jarvis/cu/conventions.py
index 4ff72e6149..0946bf30e6 100644
--- a/jarvis/cu/conventions.py
+++ b/jarvis/cu/conventions.py
@@ -138,11 +138,32 @@ class ActionParseError(ValueError):
"""The model reply held no valid action list."""
+#: Tolerated action-name aliases -> (canonical action, field overrides).
+#: Models drift on the vocabulary ("double" instead of click+double, live
+#: 2026-07-02); mapping the obvious synonyms saves a full re-plan round-trip.
+#: Overrides never clobber a field the model set explicitly.
+_ACTION_ALIASES: dict[str, tuple[str, dict[str, Any]]] = {
+ "double": ("click", {"double": True}),
+ "double_click": ("click", {"double": True}),
+ "doubleclick": ("click", {"double": True}),
+ "right_click": ("click", {"button": "right"}),
+ "rightclick": ("click", {"button": "right"}),
+ "left_click": ("click", {}),
+ "type_text": ("type", {}),
+ "hotkey": ("key", {}),
+ "keypress": ("key", {}),
+}
+
+
def _validate(obj: Any) -> dict[str, Any]:
"""Validate + normalize one raw action dict. Raises ActionParseError."""
if not isinstance(obj, dict):
raise ActionParseError(f"action is not an object: {obj!r}")
action = str(obj.get("action", "")).strip().lower()
+ if action in _ACTION_ALIASES:
+ canonical, overrides = _ACTION_ALIASES[action]
+ obj = {**{k: v for k, v in overrides.items() if k not in obj}, **obj}
+ action = canonical
if action not in VALID_ACTIONS:
raise ActionParseError(f"unknown action: {action!r}")
out: dict[str, Any] = {"action": action}
diff --git a/tests/unit/brain/test_pick_vision_model.py b/tests/unit/brain/test_pick_vision_model.py
index 410b647fbd..9a941227ab 100644
--- a/tests/unit/brain/test_pick_vision_model.py
+++ b/tests/unit/brain/test_pick_vision_model.py
@@ -11,7 +11,8 @@ import json
import jarvis.core.config as cfg
from jarvis.brain.model_catalog import pick_vision_model
-from jarvis.cu.brain_call import _rescue_blind_models
+from jarvis.brain.model_catalog import pick_fast_vision_model
+from jarvis.cu.brain_call import _speed_tune_chain
def _write_cache(tmp_path, models, provider="openrouter"):
@@ -79,7 +80,7 @@ def test_chain_swaps_blind_model_for_vision_sibling(monkeypatch, tmp_path):
{"id": "qwen/qwen3-vl", "input_modalities": ["text", "image"]},
])
chain = [("openrouter", "deepseek/deepseek-v4-flash")]
- assert _rescue_blind_models(chain) == [("openrouter", "qwen/qwen3-vl")]
+ assert _speed_tune_chain(chain) == [("openrouter", "qwen/qwen3-vl")]
def test_chain_keeps_vision_and_unknown_models(monkeypatch, tmp_path):
@@ -92,7 +93,7 @@ def test_chain_keeps_vision_and_unknown_models(monkeypatch, tmp_path):
("gemini", "gemini-3.5-flash"), # unknown -> untouched
("claude-api", None), # no explicit model -> untouched
]
- assert _rescue_blind_models(chain) == chain
+ assert _speed_tune_chain(chain) == chain
def test_chain_keeps_blind_model_when_no_sibling_exists(monkeypatch, tmp_path):
@@ -103,4 +104,44 @@ def test_chain_keeps_blind_model_when_no_sibling_exists(monkeypatch, tmp_path):
])
chain = [("openrouter", "x/text-a")]
# No vision sibling -> unchanged; the selector's blind-skip handles it.
- assert _rescue_blind_models(chain) == chain
+ assert _speed_tune_chain(chain) == chain
+
+
+# ---------------------------------------------------------------------------
+# Fast-class preference (mission wall-clock is dominated by step THINK time)
+# ---------------------------------------------------------------------------
+
+_FAST_CATALOG = [
+ {"id": "anthropic/claude-opus-4.8", "input_modalities": ["text", "image"]},
+ {"id": "google/gemini-3.5-flash", "input_modalities": ["text", "image"]},
+ {"id": "deepseek/deepseek-v4-flash", "input_modalities": ["text"]},
+]
+
+
+def test_fast_pick_prefers_fast_class_over_flagship(monkeypatch, tmp_path):
+ monkeypatch.setattr(cfg, "DATA_DIR", tmp_path)
+ _write_cache(tmp_path, _FAST_CATALOG)
+ assert pick_fast_vision_model("openrouter") == "google/gemini-3.5-flash"
+
+
+def test_fast_pick_falls_back_to_flagship_without_fast_sibling(monkeypatch, tmp_path):
+ monkeypatch.setattr(cfg, "DATA_DIR", tmp_path)
+ _write_cache(tmp_path, [
+ {"id": "anthropic/claude-opus-4.8", "input_modalities": ["text", "image"]},
+ ])
+ assert pick_fast_vision_model("openrouter") == "anthropic/claude-opus-4.8"
+
+
+def test_chain_steps_flagship_down_to_fast_vision(monkeypatch, tmp_path):
+ monkeypatch.setattr(cfg, "DATA_DIR", tmp_path)
+ _write_cache(tmp_path, _FAST_CATALOG)
+ chain = [("openrouter", "anthropic/claude-opus-4.8")]
+ assert _speed_tune_chain(chain) == [("openrouter", "google/gemini-3.5-flash")]
+
+
+def test_chain_respects_an_explicit_cu_pin(monkeypatch, tmp_path):
+ monkeypatch.setattr(cfg, "DATA_DIR", tmp_path)
+ _write_cache(tmp_path, _FAST_CATALOG)
+ chain = [("openrouter", "anthropic/claude-opus-4.8")]
+ # The user pinned this model for CU — never second-guess it.
+ assert _speed_tune_chain(chain, pinned={"openrouter"}) == chain
diff --git a/tests/unit/cu/test_conventions_ledger_verify.py b/tests/unit/cu/test_conventions_ledger_verify.py
index c024fd0bda..5be6ab45c4 100644
--- a/tests/unit/cu/test_conventions_ledger_verify.py
+++ b/tests/unit/cu/test_conventions_ledger_verify.py
@@ -86,6 +86,21 @@ def test_numeric_strings_are_tolerated():
assert actions[0]["x"] == 512.0 and actions[0]["y"] == 300.5
+def test_action_aliases_map_to_canonical_actions():
+ # "double" (live model drift 2026-07-02) -> click with double=true.
+ a = conv.parse_actions('{"action":"double","x":10,"y":20}')[0]
+ assert a["action"] == "click" and a["double"] is True
+ a = conv.parse_actions('{"action":"right_click","x":10,"y":20}')[0]
+ assert a["action"] == "click" and a["button"] == "right"
+ a = conv.parse_actions('{"action":"type_text","text":"hi"}')[0]
+ assert a["action"] == "type" and a["text"] == "hi"
+ a = conv.parse_actions('{"action":"hotkey","keys":["ctrl","t"]}')[0]
+ assert a["action"] == "key" and a["keys"] == ["ctrl", "t"]
+ # An explicit field always beats the alias override.
+ a = conv.parse_actions('{"action":"double","x":1,"y":2,"double":false}')[0]
+ assert a["action"] == "click" and a["double"] is False
+
+
def test_wait_is_capped():
actions = conv.parse_actions('{"action":"wait","ms":3600000}')
assert actions[0]["ms"] == conv.MAX_WAIT_MS