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
fix(realtime): never promise a callable function to a transport that has none
rubenluetke10-beepc64176c4254c
diff --git a/jarvis/plugins/realtime/codex_subscription.py b/jarvis/plugins/realtime/codex_subscription.pyindex f75b0f4175..07ae10b81a 100644--- a/jarvis/plugins/realtime/codex_subscription.py+++ b/jarvis/plugins/realtime/codex_subscription.py@@ -1681,9 +1681,16 @@ class _CodexSubscriptionRealtimeSession:# session.update. The handoff item stays the one model-initiated action# channel. Say so once instead of discarding wordlessly (AP-30).if tools:- log.debug(+ # INFO once per session, DEBUG afterwards: the discard repeats on+ # every turn, but a session that silently swallows the entire tool+ # surface is exactly the AP-30 failure mode.+ already_noted = getattr(self, "_tools_discard_noted", False)+ self._tools_discard_noted = True+ log.log(+ logging.DEBUG if already_noted else logging.INFO,"Codex subscription realtime cannot declare %d tool(s): the "- "app-server realtime RPC surface has no session.update",+ "app-server realtime RPC surface has no session.update — "+ "actions travel as handoffs/delegation instead",len(tools),)del toolsdiff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex f02524eb39..cb0df3b5ca 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -422,6 +422,73 @@ _DELEGATE_PENDING_DIRECTIVE = ("If the user asks about it, say only that you are still working on it. The ""trusted result will be injected as soon as it is ready.")+++def _handoff_variant(directive: str) -> str:+ """Render a function-vocabulary directive for a transport without tools.++ A transport like ChatGPT-Live cannot receive tool declarations, so a+ directive promising a callable ``jarvis_action`` (or ``end_call``) is+ unfollowable there — the model "complies" by SPEAKING the request, which a+ live session shows as the assistant voicing "Could you look up the+ weather…" as its own answer. The rules themselves (delegate the user's+ world, never announce without acting, never invent results) apply+ unchanged; only the mechanism differs: on these transports the model+ REQUESTS A HANDOFF and the supervisor injects the trusted result. Deriving+ the text from the live directive keeps future rule edits in both variants;+ the trailing catch-all keeps a future rephrasing from resurrecting the+ dead function name (a parity test pins this).+ """+ return (+ directive.replace(+ "You have ONE action function: jarvis_action. It hands",+ "You cannot call functions on this transport. Your ONE action "+ "mechanism is the handoff request: it hands",+ )+ .replace("CALL jarvis_action", "REQUEST a handoff")+ .replace("A jarvis_action round trip", "A handoff round trip")+ .replace(+ "call jarvis_action (again, with the user's correction folded in)",+ "request a handoff (again, with the user's correction folded in)",+ )+ .replace(+ "either call jarvis_action in the same response",+ "either request the handoff in the same response",+ )+ .replace(+ "An announcement without a function call in the same response",+ "An announcement without a handoff request in the same response",+ )+ .replace(+ "the latest successful jarvis_action result",+ "the latest trusted injected result",+ )+ .replace(+ "The function returns spoken_reply: deliver that content to the "+ "user in your own voice, in the conversation language, without "+ "reading JSON. If spoken_reply asks a confirmation question, ask "+ "the user and call jarvis_action again with their answer.",+ "The trusted result arrives as injected speech: deliver its "+ "content to the user in your own voice, in the conversation "+ "language. If it asks a confirmation question, ask the user and "+ "request another handoff with their answer.",+ )+ .replace(+ "Use end_call only when the user says goodbye.",+ "When the user says goodbye, answer with a brief goodbye — the "+ "call system ends the call itself.",+ )+ .replace("Call jarvis_action on this turn ONLY", "Request a handoff on this turn ONLY")+ .replace("calling any function", "requesting a handoff")+ .replace("jarvis_action", "a handoff")+ .replace("end_call", "a handoff")+ )+++_DELEGATE_ROLE_DIRECTIVE_HANDOFF = _handoff_variant(_DELEGATE_ROLE_DIRECTIVE)+_DELEGATE_DISCOURAGED_DIRECTIVE_HANDOFF = _handoff_variant(+ _DELEGATE_DISCOURAGED_DIRECTIVE+)# Delivering a result whose turn already closed must never race the live turn:# the session waits until it is at rest, then speaks the result as an explicit# follow-up. The bound only decides how long a result may wait for that silence.@@ -1795,7 +1862,7 @@ class RealtimeVoiceSession:provider=str(getattr(provider, "name", "") or ""),model=model,language_is_pinned=self._language_is_pinned,- tool_directive=self._tool_directive(),+ tool_directive=self._tool_directive(provider=provider),preferences=_preferences_block(self._config),workspace_directive=self._workspace_directive(),),@@ -4845,18 +4912,26 @@ class RealtimeVoiceSession:delegate_required: bool = False,action_pending: bool = False,delegate_discouraged: bool = False,+ provider: Any = None,) -> str:if self._delegate_enabled:+ # Capability, not provider name (AP-21): a transport that cannot+ # receive tool declarations must never be promised a callable+ # function — the model can only "comply" by speaking the call.+ target = provider if provider is not None else self._provider+ if not bool(getattr(target, "supports_direct_tools", True)):+ role = _DELEGATE_ROLE_DIRECTIVE_HANDOFF+ discouraged = _DELEGATE_DISCOURAGED_DIRECTIVE_HANDOFF+ else:+ role = _DELEGATE_ROLE_DIRECTIVE+ discouraged = _DELEGATE_DISCOURAGED_DIRECTIVEif delegate_required:- return f"{_DELEGATE_ROLE_DIRECTIVE}\n\n{_DELEGATE_REQUIRED_DIRECTIVE}"+ return f"{role}\n\n{_DELEGATE_REQUIRED_DIRECTIVE}"if action_pending:- return f"{_DELEGATE_ROLE_DIRECTIVE}\n\n{_DELEGATE_PENDING_DIRECTIVE}"+ return f"{role}\n\n{_DELEGATE_PENDING_DIRECTIVE}"if delegate_discouraged:- return (- f"{_DELEGATE_ROLE_DIRECTIVE}\n\n"- f"{_DELEGATE_DISCOURAGED_DIRECTIVE}"- )- return _DELEGATE_ROLE_DIRECTIVE+ return f"{role}\n\n{discouraged}"+ return roleif self._tool_bridge is not None:return _TOOL_ROLE_DIRECTIVEreturn ""diff --git a/tests/unit/realtime/test_tool_directive_capability.py b/tests/unit/realtime/test_tool_directive_capability.pynew file mode 100644index 0000000000..8edebdebbc--- /dev/null+++ b/tests/unit/realtime/test_tool_directive_capability.py@@ -0,0 +1,71 @@+"""The delegate tool directive must match the transport's real capabilities.++A transport that cannot receive tool declarations (``supports_direct_tools``+False, e.g. ChatGPT-Live through the Codex app-server) must never be promised+a callable ``jarvis_action`` or ``end_call``: the model can only "comply" by+speaking the call, which a live session shows as the assistant voicing+"Could you look up the weather…" as its own answer. Capability decides the+wording (AP-21), never a provider name.+"""++from __future__ import annotations++from types import SimpleNamespace++import jarvis.realtime.session as session_mod+++def _bare_session(provider: object) -> session_mod.RealtimeVoiceSession:+ """A session shell carrying exactly what ``_tool_directive`` reads."""+ session = session_mod.RealtimeVoiceSession.__new__(+ session_mod.RealtimeVoiceSession+ )+ session._delegate_enabled = True+ session._tool_bridge = None+ session._provider = provider+ return session+++def test_handoff_variant_never_promises_a_callable_function() -> None:+ for text in (+ session_mod._DELEGATE_ROLE_DIRECTIVE_HANDOFF,+ session_mod._DELEGATE_DISCOURAGED_DIRECTIVE_HANDOFF,+ ):+ assert "jarvis_action" not in text+ assert "end_call" not in text+ assert "handoff" in text.lower()+++def test_handoff_variant_keeps_the_load_bearing_rules() -> None:+ text = session_mod._DELEGATE_ROLE_DIRECTIVE_HANDOFF+ # The honesty rules survive the mechanism swap verbatim in spirit.+ assert "announcement without a handoff request" in text.lower()+ assert "general world knowledge is yours" in text.lower()+ assert "never tell the user that you lack a tool" in text.lower()+++def test_capability_limited_provider_gets_the_handoff_directive() -> None:+ limited = SimpleNamespace(supports_direct_tools=False)+ directive = _bare_session(limited)._tool_directive()+ assert directive == session_mod._DELEGATE_ROLE_DIRECTIVE_HANDOFF++ directive = _bare_session(limited)._tool_directive(delegate_discouraged=True)+ assert directive.startswith(session_mod._DELEGATE_ROLE_DIRECTIVE_HANDOFF)+ assert directive.endswith(session_mod._DELEGATE_DISCOURAGED_DIRECTIVE_HANDOFF)+ assert "jarvis_action" not in directive+++def test_direct_tool_provider_keeps_the_function_directive() -> None:+ capable = SimpleNamespace(supports_direct_tools=True)+ directive = _bare_session(capable)._tool_directive()+ assert directive == session_mod._DELEGATE_ROLE_DIRECTIVE+ assert "jarvis_action" in directive+++def test_open_probes_the_candidate_provider_not_the_last_active_one() -> None:+ """During ``_open`` the directive must follow the provider being opened."""+ active_capable = SimpleNamespace(supports_direct_tools=True)+ candidate_limited = SimpleNamespace(supports_direct_tools=False)+ session = _bare_session(active_capable)+ directive = session._tool_directive(provider=candidate_limited)+ assert directive == session_mod._DELEGATE_ROLE_DIRECTIVE_HANDOFF