KV Cache Stability, Static Prompts & Instructions
CONTENTS
Most input token cost in multi-step coding agents comes from re-reading prefix context. Any per-second timestamp inside system instructions, unintended tool schema churn, or dynamic per-step disk scans invalidates server-side KV / Prompt Cache prefixes. Mizar enforces prefix stability across prompts, tool lists, workspace instructions, and wire adapters.
Lean Static English System Prompt (mizar-system-prompt)
Sections assemble by numeric order using a lean static English template (no built-in philosophy or default personality block; only explicit non-empty personality in settings.json is inserted):
order | Section ID | Responsibility |
|---|---|---|
0 | identity | DEFAULT_IDENTITY (You are a coding assistant running inside Mizar... and language-matching rule) |
20 | personality (optional) | Inserted only when settings.json sets a non-empty personality (omitted/blank = 0 bytes) |
30 | tools_guide | <tools> and deduplicated <rules> assembled by mizar-tools-coding::build_tools_guide from declared session tools |
40 | runtime_protocol | DEFAULT_RUNTIME_PROTOCOL describing <environment_context>, <project_instructions>, <system-reminder>, <skill_content>, and <mizar-compaction> |
| tail | emphasis (optional) | Interactive TUI only (unless MIZAR_TUI_EMPHASIS_GUIDANCE=0); omitted in headless exec |
Before Turn 0, mizar-agent-loop fires EVENT_AGENT_PREPARE_TURN to keep system instructions, workspace rules, and history deterministic. Whenever read or bash is declared, mizar-skills injects <available_skills> with <location> pointers or expands /<name> <skill_content>. After compaction or overflow recovery, both system_prompt.build_for_session(Some(&session.id)) and tools.list_declared(Some(&session.id)) refresh together.
Startup-Static Workspace Instructions (mizar-instructions)
AGENTS.md / CLAUDE.md discovery runs once at startup and injects a static read-only section into SystemPrompt via ctx.effect (inject: ["systemPrompt"]), replacing per-step subdirectory stat polling:
- Discovery Roots & Candidates:
- Global:
~/.mizar/(MIZAR_HOME) and~/.agents/(MIZAR_AGENTS_HOME). - Workspace lineage: walks upward from current working directory to
projectRootMarkers([".git"]), loadingcandidates(["AGENTS.md", "CLAUDE.md"]) and local overrideslocalCandidates(["AGENTS.local.md", "CLAUDE.local.md"]).
- Global:
- Deduplication & Budget Eviction:
- Whitespace-normalized SHA-256 deduplicates identical files per group while keeping distinct files.
- Per-file cap
instructions.maxSourceBytes(1,048,576 B= 1 MiB) and total budgetinstructions.maxBytes(65,536 B). When over budget, broadest/furthest ancestors are evicted first to preserve instructions closest to the active directory, with UTF-8 safe truncation.
- Zero Per-Step Disk I/O: Prefix bytes never shift mid-session due to background file edits. Pass
--no-instructionsor setinstructions.enabled: falseto disable.
Lean On-Demand Tool Declarations
To avoid unnecessary prefix bloat and schema churn:
MinimalCoding4-tool default: Declares onlyread,bash,edit, andwriteby default.- On-demand
codemode: Dormant unless enabled via MCPcodemodeconfig,--tools codemode, orcodemode.enabled/onlyMode; in mixed mode,codemodedeclarations and<mcp_servers>summaries stay byte-identical before and after MCP handshake. - Zero-dependency omission:
tool_searchis skipped at 0 MCP tools; the standaloneskilltool has been removed in favor of<available_skills><location>pointers.
Wire-Level Prefix, Breakpoints & Vision Alignment
Each protocol adapter aligns wire formatting to upstream caching and multimodal semantics (see Models & Compat Reference):
- Anthropic Messages (
mizar-llm-messages):- Computes
prefixDigestbefore insertingcache_controlbreakpoints (system, lasttoolsentry gated bysupportsCacheControlOnTools, and lastuserblock;ttl: "1h"forLongretention) so cache strategy switches never invalidate signedthinking/redacted_thinkingreplay. - Encodes tool images as a
tool_result.contentarray of text + base64 image blocks (plain string when text-only).
- Computes
- OpenAI Responses (
mizar-llm-responses):- Defaults to
supportsDeveloperRole: trueanduseTopLevelInstructions: false(inlininginput[0]as"developer", or falling back to"system"whensupportsDeveloperRole: false);supportsStore,supportsTemperature,supportsReasoningEffort, andsupportsPromptCacheKeyomit disabled fields completely. - Replays ordered
outputItemsto preventIN_DROPand sends tool images asfunction_call_output.outputarrays ofinput_text+input_image.
- Defaults to
- OpenAI Completions & DeepSeek (
mizar-llm-completions):- Sends session affinity headers and
prompt_cache_key; when a parallel tool batch returns images, emits allrole: "tool"messages first (appending(see attached image)), followed by one syntheticrole: "user"message carrying all images in order.
- Sends session affinity headers and
- Text-Only Model Degradation (
supportsImages): When a catalog model declaressupportsImages: false(unknown models allow images), all three adapters replace images pre-serialization viamessage_for_modelwith[image omitted: current model does not support image input].