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(brain): agent-instructions block names the real file and gains a length cap
Ruben Lütkedc8dd7a8ce4a
diff --git a/jarvis/brain/agent_instructions.py b/jarvis/brain/agent_instructions.pyindex 47bebf8a11..f49581df0f 100644--- a/jarvis/brain/agent_instructions.py+++ b/jarvis/brain/agent_instructions.py@@ -186,29 +186,36 @@ def reset_agent_instructions(config: Any) -> bool:return False-def render_for_prompt(config: Any) -> str:+def render_for_prompt(config: Any, *, max_chars: int | None = None) -> str:"""The system-prompt block for the current user-instructions state.The block is framed so the model treats the content as *preferences* — itrefines tone/language/defaults but never overrides safety rules, confirmationgates, or capabilities, and never authorises new tools or actions.++ ``max_chars`` caps the *content* (not the framing) for latency-sensitive+ callers that re-send the block often (the realtime voice session re-sends+ its instructions on every turn). Truncation is marked explicitly so the+ model never mistakes a cut-off file for the complete instructions."""content = read_agent_instructions(config)filename = instructions_filename(config)if not content:return (f"USER PREFERENCES & STANDING INSTRUCTIONS (from {filename}):\n"- "No active user preferences are currently set in Jarvis.md. "- "Ignore any earlier Jarvis.md instructions from previous turns. "+ f"No active user preferences are currently set in {filename}. "+ f"Ignore any earlier {filename} instructions from previous turns. ""Do not continue, infer, or imitate older style, address, tone, ""language, or wording rules that are absent from this current block.\n\n""END USER PREFERENCES & STANDING INSTRUCTIONS")+ if max_chars is not None and max_chars > 0 and len(content) > max_chars:+ content = content[:max_chars].rstrip() + "\n[... truncated for length]"return (f"USER PREFERENCES & STANDING INSTRUCTIONS (from {filename}):\n""The following are personal preferences written by the user for how you ""should work with them. Only the instructions inside this current block are "- "active; ignore any earlier Jarvis.md instructions from previous turns that "+ f"active; ignore any earlier {filename} instructions from previous turns that ""are absent or conflict. Treat the current block as binding for tone, ""language, formatting, default choices, forms of address, and standing facts ""about the user. They override default style/address/tone/language guidance "diff --git a/tests/unit/brain/test_agent_instructions.py b/tests/unit/brain/test_agent_instructions.pyindex 4ea90e00b5..6d3b909e3e 100644--- a/tests/unit/brain/test_agent_instructions.py+++ b/tests/unit/brain/test_agent_instructions.py@@ -94,7 +94,10 @@ def test_render_for_prompt_without_file_emits_current_empty_state():block = agent_instructions.render_for_prompt(cfg)assert "Ruben.md" in blockassert "No active user preferences are currently set" in block- assert "Ignore any earlier Jarvis.md instructions" in block+ # The stale-style guard must reference the assistant's ACTUAL file name,+ # never a hardcoded product name (the file is Ruben.md here, not Jarvis.md).+ assert "Ignore any earlier Ruben.md instructions" in block+ assert "Jarvis.md" not in blockassert "END USER PREFERENCES & STANDING INSTRUCTIONS" in block@@ -152,6 +155,26 @@ def test_render_for_prompt_wraps_content_with_filename_and_guardrail():assert "never override" in block.lower()+def test_render_for_prompt_max_chars_passes_short_content_untouched():+ cfg = make_config(name="Ruben")+ agent_instructions.save_agent_instructions(cfg, "Speak with a Bavarian accent.")+ block = agent_instructions.render_for_prompt(cfg, max_chars=4000)+ assert "Speak with a Bavarian accent." in block+ assert "truncated" not in block+++def test_render_for_prompt_max_chars_truncates_with_explicit_marker():+ cfg = make_config(name="Ruben")+ agent_instructions.save_agent_instructions(cfg, "x" * 500)+ block = agent_instructions.render_for_prompt(cfg, max_chars=100)+ assert "x" * 100 in block+ assert "x" * 101 not in block+ # Truncation must be marked so the model never mistakes a cut-off file+ # for the complete instructions.+ assert "[... truncated for length]" in block+ assert "END USER PREFERENCES & STANDING INSTRUCTIONS" in block++# --------------------------------------------------------------------------- ## Rename-follows-the-name migration ## --------------------------------------------------------------------------- #