Docs
中文 EN

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):

orderSection IDResponsibility
0identityDEFAULT_IDENTITY (You are a coding assistant running inside Mizar... and language-matching rule)
20personality (optional)Inserted only when settings.json sets a non-empty personality (omitted/blank = 0 bytes)
30tools_guide<tools> and deduplicated <rules> assembled by mizar-tools-coding::build_tools_guide from declared session tools
40runtime_protocolDEFAULT_RUNTIME_PROTOCOL describing <environment_context>, <project_instructions>, <system-reminder>, <skill_content>, and <mizar-compaction>
tailemphasis (optional)Interactive TUI only (unless MIZAR_TUI_EMPHASIS_GUIDANCE=0); omitted in headless exec
Turn-0 Ordering, Skill Catalog & Compaction Refresh

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:
    1. Global: ~/.mizar/ (MIZAR_HOME) and ~/.agents/ (MIZAR_AGENTS_HOME).
    2. Workspace lineage: walks upward from current working directory to projectRootMarkers ([".git"]), loading candidates (["AGENTS.md", "CLAUDE.md"]) and local overrides localCandidates (["AGENTS.local.md", "CLAUDE.local.md"]).
  • 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 budget instructions.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-instructions or set instructions.enabled: false to disable.

Lean On-Demand Tool Declarations

To avoid unnecessary prefix bloat and schema churn:

  • MinimalCoding 4-tool default: Declares only read, bash, edit, and write by default.
  • On-demand codemode: Dormant unless enabled via MCP codemode config, --tools codemode, or codemode.enabled/onlyMode; in mixed mode, codemode declarations and <mcp_servers> summaries stay byte-identical before and after MCP handshake.
  • Zero-dependency omission: tool_search is skipped at 0 MCP tools; the standalone skill tool 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 prefixDigest before inserting cache_control breakpoints (system, last tools entry gated by supportsCacheControlOnTools, and last user block; ttl: "1h" for Long retention) so cache strategy switches never invalidate signed thinking / redacted_thinking replay.
    • Encodes tool images as a tool_result.content array of text + base64 image blocks (plain string when text-only).
  • OpenAI Responses (mizar-llm-responses):
    • Defaults to supportsDeveloperRole: true and useTopLevelInstructions: false (inlining input[0] as "developer", or falling back to "system" when supportsDeveloperRole: false); supportsStore, supportsTemperature, supportsReasoningEffort, and supportsPromptCacheKey omit disabled fields completely.
    • Replays ordered outputItems to prevent IN_DROP and sends tool images as function_call_output.output arrays of input_text + input_image.
  • OpenAI Completions & DeepSeek (mizar-llm-completions):
    • Sends session affinity headers and prompt_cache_key; when a parallel tool batch returns images, emits all role: "tool" messages first (appending (see attached image)), followed by one synthetic role: "user" message carrying all images in order.
  • Text-Only Model Degradation (supportsImages): When a catalog model declares supportsImages: false (unknown models allow images), all three adapters replace images pre-serialization via message_for_model with [image omitted: current model does not support image input].

Search Mizar Docs