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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(brain): delegated realtime turns run on the Tool Model pick
Ruben Lütke7eebc302e79c
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.pyindex 10597c02e3..2242c9ce10 100644--- a/jarvis/brain/manager.py+++ b/jarvis/brain/manager.py@@ -2292,11 +2292,11 @@ class BrainManager:Reads ``[brain.computer_use].provider`` FRESH per call (like``_cu_model``), so an in-memory switch (``/api/computer-use/switch``)takes effect on the very next CU dispatch. ``""`` means "not- configured" — the CU-only dispatch hoist in- ``jarvis.cu.brain_call.call_vision_brain`` then leaves the fallback- chain untouched (CU keeps running on ``brain.primary``, current- behavior). Never raises (getattr-chain safe): a config hiccup must- not break Computer-Use dispatch (AP-21/22).+ configured" — the dispatch hoists (the CU-only one in+ ``jarvis.cu.brain_call.call_vision_brain`` and the delegated-turn+ ``_hoist_tool_model``) then leave the fallback chain untouched.+ Never raises (getattr-chain safe): a config hiccup must not break+ dispatch (AP-21/22)."""try:cu_cfg = getattr(self._config.brain, "computer_use", None)@@ -2304,6 +2304,26 @@ class BrainManager:except Exception: # noqa: BLE001 — config hiccup must not block dispatchreturn ""+ def _hoist_tool_model(+ self, chain: list[tuple[str, str | None]]+ ) -> list[tuple[str, str | None]]:+ """Hoist the Tool-Model pick to the head of a turn's fallback chain.++ Mirrors the CU-only hoist in ``jarvis.cu.brain_call.call_vision_brain``:+ reads ``[brain.computer_use].provider`` FRESH per call (an in-memory+ switch takes effect on the very next delegated turn), resolves the+ model via ``_cu_model``, and leaves the rest of the chain untouched as+ the cross-family fallback (AP-21/22). A keyless/dead pick is skipped+ here so the honest empty-chain diagnostic still fires unchanged. Only+ the exact duplicate entry is filtered — other entries of the same+ provider stay as legitimate same-provider fallbacks.+ """+ pref = self._cu_provider()+ if not pref or pref in self._dead_providers:+ return chain+ entry = (pref, self._cu_model(pref))+ return [entry] + [e for e in chain if e != entry]+def _get_brain(self, name: str, model: str | None = None) -> Brain:"""Retrieves a Brain instance from the cache, or builds a new one."""key = (name, model)diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex b082197734..fee2260bd2 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -899,14 +899,20 @@ class RealtimeVoiceSession:async def _dispatch_brain_turn(self, text: str) -> str:# allow_voice_confirm=True is load-bearing: without it an ask-tier# tool blocks on a UI approval no voice user can give (the classic- # pipeline passes the same flag).+ # pipeline passes the same flag). prefer_tool_model routes the+ # delegated turn onto the Tool-Model pick. Two-step degrade: an older+ # brain that rejects the new kwarg must keep voice-confirm rather+ # than dropping straight to the bare call.generate = getattr(self._brain, "generate", None)if callable(generate):- try:- return str(await generate(text, allow_voice_confirm=True) or "")- except TypeError:- # Bare callables / older brains without the kwarg.- pass+ for kwargs in (+ {"allow_voice_confirm": True, "prefer_tool_model": True},+ {"allow_voice_confirm": True},+ ):+ try:+ return str(await generate(text, **kwargs) or "")+ except TypeError:+ continuereturn str(await self._brain(text) or "")async def _finish_with_hangup(self) -> None:diff --git a/tests/unit/brain/test_tool_model_turn.py b/tests/unit/brain/test_tool_model_turn.pynew file mode 100644index 0000000000..dd1ca686d4--- /dev/null+++ b/tests/unit/brain/test_tool_model_turn.py@@ -0,0 +1,73 @@+"""Delegated realtime turns run on the Tool-Model pick.++``generate(prefer_tool_model=True)`` hoists the [brain.computer_use] provider+(the Tool Model tab's selection) to the head of the turn's fallback chain —+fresh per call, cross-family fallback intact (AP-21/22), no global state.+"""+from __future__ import annotations++from jarvis.brain.manager import BrainManager+from jarvis.core.bus import EventBus+from jarvis.core.config import BrainTierConfig, load_config+++def _manager(tool_provider: str | None = "gemini") -> BrainManager:+ cfg = load_config()+ cfg.brain.router.provider = "openrouter"+ if tool_provider is None:+ cfg.brain.computer_use = None+ else:+ cfg.brain.computer_use = BrainTierConfig(provider=tool_provider)+ return BrainManager.from_tier_config("router", cfg, EventBus())+++_CHAIN: list[tuple[str, str | None]] = [+ ("openrouter", "fast-model"),+ ("groq", None),+ ("gemini", "gemini-3.5-flash"),+]+++def test_hoist_puts_tool_model_first_and_filters_exact_duplicate():+ mgr = _manager("gemini")+ mgr._config.brain.providers["gemini"].model = "gemini-3.5-flash"+ mgr._config.brain.providers["gemini"].cu_model = None++ hoisted = mgr._hoist_tool_model(list(_CHAIN))++ assert hoisted[0] == ("gemini", "gemini-3.5-flash")+ # The exact duplicate is gone; everything else keeps its order.+ assert hoisted[1:] == [("openrouter", "fast-model"), ("groq", None)]+++def test_hoist_keeps_same_provider_entries_with_other_models():+ mgr = _manager("gemini")+ mgr._config.brain.providers["gemini"].cu_model = "gemini-3.1-pro-preview"++ hoisted = mgr._hoist_tool_model(list(_CHAIN))++ assert hoisted[0] == ("gemini", "gemini-3.1-pro-preview")+ # The chain's own gemini entry differs by model and survives as a+ # legitimate same-provider fallback.+ assert ("gemini", "gemini-3.5-flash") in hoisted[1:]+++def test_hoist_is_a_no_op_when_unconfigured():+ mgr = _manager(None)+ assert mgr._hoist_tool_model(list(_CHAIN)) == _CHAIN+++def test_hoist_skips_a_dead_tool_provider():+ mgr = _manager("gemini")+ mgr._dead_providers.add("gemini")+ assert mgr._hoist_tool_model(list(_CHAIN)) == _CHAIN+++def test_hoist_reads_the_pick_fresh_per_call():+ """/api/computer-use/switch semantics: an in-memory switch takes effect+ on the very next delegated turn, no session rebuild."""+ mgr = _manager("gemini")+ assert mgr._hoist_tool_model(list(_CHAIN))[0][0] == "gemini"++ mgr._config.brain.computer_use = BrainTierConfig(provider="groq")+ assert mgr._hoist_tool_model(list(_CHAIN))[0][0] == "groq"diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 1258c42f0e..c332e2cb5b 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -1000,7 +1000,10 @@ async def test_delegate_call_dispatches_raw_transcript_with_voice_confirm():await asyncio.sleep(0.02)assert brain.calls == [- ("please open the settings view", {"allow_voice_confirm": True})+ (+ "please open the settings view",+ {"allow_voice_confirm": True, "prefer_tool_model": True},+ )]assert provider.session.tool_results == [(@@ -1196,3 +1199,42 @@ async def test_delegate_brain_exception_sends_safe_failure():assert result["success"] is Falseassert "failed safely" in result["error"]await sess.end(reason="test")+++async def test_delegate_degrades_kwargs_but_keeps_voice_confirm():+ """An older brain without the prefer_tool_model kwarg must still get+ allow_voice_confirm=True via the degrade step (exactly one real call)."""++ class LegacyBrain:+ def __init__(self):+ self.calls = []++ async def generate(self, text, *, allow_voice_confirm=False):+ self.calls.append((text, allow_voice_confirm))+ return "done legacy"++ async def __call__(self, text):+ raise AssertionError("bare call must not be reached")++ brain = LegacyBrain()+ provider = FakeProvider(+ [+ RealtimeEvent(type="input_transcript", text="open it", is_final=True),+ RealtimeEvent(+ type="tool_call",+ call_id="c-9",+ tool_name="jarvis_action",+ tool_args={"request": "open it"},+ ),+ ]+ )+ sess = _session(provider, brain=brain)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await asyncio.sleep(0.02)++ assert brain.calls == [("open it", True)]+ assert provider.session.tool_results[0][2]["spoken_reply"] == "done legacy"+ await sess.end(reason="test")