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.

fix(brain): make the active provider/model self-aware in the system prompt

Ruben Lütkeb20ee243f170
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index 7e3b7bf7a9..68e446d50c 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -137,6 +137,63 @@ PROVIDER_ALIASES = {
"openrouter": "openrouter",
}
+# Human-readable display names for each brain provider id. Used to tell the
+# answering LLM which provider/model it is embodying this turn (the system
+# prompt never carried this before, so a "which model are you?" question got a
+# guessed answer that defaulted to "Gemini" — forensic 2026-06-20, voice session
+# 15:15: Grok was live and answering, yet Jarvis claimed to be Gemini). Kept
+# self-contained in the brain layer (no UI-catalog import — that would invert the
+# layer dependency) and defensive: an unmapped id degrades to a readable label.
+_PROVIDER_DISPLAY_NAMES: dict[str, str] = {
+ "claude-api": "Anthropic Claude",
+ "openai": "OpenAI GPT",
+ # Both the CLI brain id ("codex") and the sub-agent value ("openai-codex")
+ # map to the same readable label, so whichever surfaces as a turn prov_name
+ # is named correctly (the user explicitly wants "Codex / GPT-5.5" recognised).
+ "codex": "OpenAI Codex (GPT-5.5)",
+ "openai-codex": "OpenAI Codex (GPT-5.5)",
+ "openrouter": "OpenRouter",
+ "gemini": "Google Gemini",
+ "grok": "Grok (xAI)",
+ "antigravity": "Google Antigravity (Gemini)",
+}
+
+
+def _provider_display_name(provider: str) -> str:
+ """A readable label for a brain provider id (never crashes on unknown ids)."""
+ pid = (provider or "").strip()
+ mapped = _PROVIDER_DISPLAY_NAMES.get(pid)
+ if mapped:
+ return mapped
+ # Unknown id → readable fallback: "some-new_provider" → "Some New Provider".
+ return pid.replace("-", " ").replace("_", " ").title() or "the configured provider"
+
+
+def _provider_identity_directive(provider: str, model: str | None, name: str) -> str:
+ """Authoritative, anti-guessing self-identity line for the system prompt.
+
+ The single source of truth for "which AI model am I right now?". Names the
+ *actual* provider/model answering this turn (set per fallback-chain attempt
+ in ``generate()``), and carves out the one allowed exception to the persona's
+ "never discuss your technical nature" rule: a direct provider/model question
+ gets an honest, specific answer instead of a guessed "Gemini".
+ """
+ label = _provider_display_name(provider)
+ model_str = (model or "").strip() or "the provider's default"
+ return (
+ f"ACTIVE BRAIN MODEL — INFRASTRUCTURE FACT (authoritative): You are right "
+ f"now running on the brain provider {label} (model: {model_str}). {label} "
+ f"is the provider actually generating your reply this turn. If the user "
+ f"asks which provider, backend, or AI model is powering you right now, "
+ f"answer truthfully and specifically with this — never guess, and never "
+ f"name a provider other than the one stated here (a recurring failure was "
+ f'wrongly claiming to be "Gemini"). This is the one allowed exception to '
+ f"the persona rule about not discussing your own technical nature: a "
+ f"direct question about your underlying provider/model gets an honest, "
+ f"specific answer; otherwise you stay {name} and never raise it unprompted."
+ )
+
+
# Mapping of Credential-Manager slot -> Brain provider ID. Brain slots only;
# TTS/STT providers have their own lifecycles outside BrainManager.
# Used by the SecretConfigured subscriber to remove the corresponding provider
@@ -1194,6 +1251,13 @@ class BrainManager:
self._registry = BrainProviderRegistry()
self._active_name: str = config.brain.primary
+ # The (provider, model) actually answering the CURRENT turn. Set per
+ # fallback-chain attempt in generate() right before the dispatcher is
+ # built, consumed by _build_system_prompt to inject the authoritative
+ # self-identity line (forensic 2026-06-20: the answering LLM never knew
+ # which provider it was, so a provider question got a guessed "Gemini").
+ # None outside a turn → no identity block on helper prompt builds.
+ self._active_turn_identity: tuple[str, str | None] | None = None
# Last persist-to-disk outcome of ``switch(..., persist=True)``.
# ``None`` = no persisting switch attempted yet. The provider route
# reads this to report the ACTUAL disk result instead of echoing the
@@ -2036,6 +2100,26 @@ class BrainManager:
if self._wiki_context_suffix and not self._cache_optimized():
parts.append(self._wiki_context_suffix)
+ # Active-model self-awareness: tell THIS turn's actually-answering
+ # provider/model who it is, so a "which model are you?" question gets an
+ # honest answer instead of a guessed "Gemini" (forensic 2026-06-20: Grok
+ # was live and answering yet claimed to be Gemini). Set per fallback-chain
+ # attempt in generate(), where the real prov_name/model are known; absent
+ # on non-turn prompt builds (compression / wiki-delta base) → no block.
+ # Placed late for high recency so it overrides the persona's "never
+ # discuss your technical nature" line; provider-stable across same-provider
+ # turns, so it stays prompt-cache-friendly. On a fallback the block's
+ # provider label changes between attempts within the turn, invalidating
+ # the prefix cache for the second attempt — acceptable, since a fallback
+ # is already a slow path (and matches the pre-existing per-turn mutable
+ # flags). getattr: tolerates __new__-constructed test managers that bypass
+ # __init__ (the attr is always set in __init__ for the production path).
+ identity = getattr(self, "_active_turn_identity", None)
+ if identity:
+ parts.append(
+ _provider_identity_directive(identity[0], identity[1], name)
+ )
+
# Reply-language directive LAST — highest recency-salience so it wins
# over the otherwise German prompt above it. Byte-stable across turns
# (only changes on an explicit language switch), so it stays prompt-
@@ -4175,6 +4259,9 @@ class BrainManager:
self._last_turn_all_failed = False
self._last_turn_suppressed = False
self._last_turn_executed_action_tool = False
+ # Clear last turn's provider identity so a helper prompt build before the
+ # fallback loop (wiki-delta base) does not carry a stale provider name.
+ self._active_turn_identity = None
turn_trace_id = trace_id or uuid4()
# auto mode: resolve this turn's language so _reply_language_directive()
@@ -4667,6 +4754,12 @@ class BrainManager:
has_image=bool(images),
pointing_turn=pointing_turn,
)
+ # Active-model self-awareness: stamp the provider/model that is about
+ # to answer so _build_system_prompt injects the correct, specific
+ # self-identity (anti-"I'm Gemini" hallucination, forensic 2026-06-20).
+ # Set here — after dead/cooldown skips — so it always names the
+ # provider that genuinely runs this attempt, including a fallback win.
+ self._active_turn_identity = (prov_name, model)
disp = self._build_dispatcher(brain, tools_override=_turn_tools)
try:
# CostMeter: start per-trace tracking (idempotent if already started).
diff --git a/tests/unit/brain/test_active_model_awareness.py b/tests/unit/brain/test_active_model_awareness.py
new file mode 100644
index 0000000000..5cceacf522
--- /dev/null
+++ b/tests/unit/brain/test_active_model_awareness.py
@@ -0,0 +1,118 @@
+"""The active brain provider/model must reach the system prompt.
+
+User mandate 2026-06-20 (voice session 15:15): Jarvis kept hallucinating that
+it was "Gemini" when asked which provider was active — even though Grok was the
+live provider that actually answered the turn (sessions.db: provider=grok,
+tool_calls=[]). Root cause: ``_build_system_prompt`` never told the answering
+LLM which provider/model it was embodying, so a provider question got a guessed
+answer that defaulted to "Gemini".
+
+These lock that the per-turn provider identity (set in the generate() fallback
+loop, where the real ``prov_name``/``model`` are known) flows into the system
+prompt as an authoritative, anti-guessing infrastructure fact.
+"""
+from __future__ import annotations
+
+from jarvis.brain.manager import (
+ BrainManager,
+ _provider_display_name,
+ _provider_identity_directive,
+)
+from jarvis.core.config import load_config
+
+
+def _manager(*, wake_phrase: str = "Hey Jarvis") -> BrainManager:
+ """A BrainManager with __init__ bypassed — only the attrs the prompt needs."""
+ m = BrainManager.__new__(BrainManager)
+ m._soul = None
+ m._user_profile = None
+ m._people = None
+ m._core_memory = None
+ m._awareness_manager = None
+ m._system_prompt_extra = "ROUTER DISCIPLINE BLOCK"
+ m._wiki_context_suffix = ""
+ m._reply_language = "auto"
+ m._active_turn_identity = None
+ cfg = load_config()
+ cfg.performance.cache_optimized_prompt = False
+ cfg.trigger.wake_word.phrase = wake_phrase
+ m._config = cfg
+ return m
+
+
+# --------------------------------------------------------------------------
+# Pure helper: provider display names
+# --------------------------------------------------------------------------
+
+
+def test_display_name_known_providers() -> None:
+ assert "Grok" in _provider_display_name("grok")
+ assert "Gemini" in _provider_display_name("gemini")
+ assert "Claude" in _provider_display_name("claude-api")
+ # The user explicitly wants Codex/GPT-5.5 to be recognised.
+ codex = _provider_display_name("openai-codex")
+ assert "Codex" in codex or "GPT" in codex
+
+
+def test_display_name_unknown_provider_falls_back_readably() -> None:
+ # Never crash on an unmapped id — produce a readable label.
+ assert _provider_display_name("some-new-provider")
+ assert "_" not in _provider_display_name("some-new-provider")
+
+
+# --------------------------------------------------------------------------
+# Pure helper: the directive text
+# --------------------------------------------------------------------------
+
+
+def test_identity_directive_names_provider_and_model() -> None:
+ d = _provider_identity_directive("grok", "grok-4.3", "Jarvis")
+ assert "Grok" in d
+ assert "grok-4.3" in d
+ # Must instruct against guessing / defaulting to Gemini.
+ assert "Gemini" in d # named as the forbidden default
+ assert "never" in d.lower() or "not" in d.lower()
+
+
+# --------------------------------------------------------------------------
+# Integration: it reaches _build_system_prompt
+# --------------------------------------------------------------------------
+
+
+def test_active_grok_identity_in_system_prompt() -> None:
+ m = _manager()
+ m._active_turn_identity = ("grok", "grok-4.3")
+ prompt = m._build_system_prompt()
+ assert "Grok" in prompt
+ assert "grok-4.3" in prompt
+ # The anti-hallucination instruction is present (generic anti-guess rule,
+ # with the known "Gemini" failure named as the forbidden exemplar).
+ assert "never guess" in prompt.lower()
+ assert "Gemini" in prompt
+
+
+def test_active_codex_identity_says_gpt() -> None:
+ m = _manager()
+ m._active_turn_identity = ("openai-codex", "gpt-5.5")
+ prompt = m._build_system_prompt()
+ assert ("Codex" in prompt) or ("GPT" in prompt)
+ assert "gpt-5.5" in prompt
+
+
+def test_no_identity_block_when_unset() -> None:
+ m = _manager()
+ m._active_turn_identity = None
+ prompt = m._build_system_prompt()
+ # No authoritative model block, and crucially no spurious provider claim.
+ assert "ACTIVE BRAIN MODEL" not in prompt
+
+
+def test_grok_active_does_not_claim_to_be_gemini() -> None:
+ # The exact regression: Grok is live, the prompt must not assert the model
+ # IS Gemini. "Gemini" may appear only as the explicitly-forbidden default.
+ m = _manager()
+ m._active_turn_identity = ("grok", "grok-4.3")
+ prompt = m._build_system_prompt()
+ assert "running on the brain provider Grok" in prompt
+ # It must never say it is *running on* Gemini.
+ assert "running on the brain provider Google Gemini" not in prompt