25 KiB
status, date, decision-makers, consulted, informed
| status | date | decision-makers | consulted | informed | ||
|---|---|---|---|---|---|---|
| accepted (fleet-wide primary: DeepSeek-V4.1-Flash-1017; updated 2026-10-17) | 2026-09-13 |
|
ADR 0002: OpenClaw Full-Spectrum Model Selection, Multimodal Tiering, and Cost Governance
Context and Problem Statement
OpenClaw serves as the 24/7 personal AI concierge, family assistant, and operational orchestrator for Moritz Graf and his family. It interacts across Telegram, voice notes, webhooks, and background automations, bridging to personal knowledge (Obsidian wiki), smart home systems (Home Assistant, Sonos), fitness tracking (Garmin Connect), and cluster monitoring (Prometheus, Gitea).
During early September 2026, OpenClaw consumed 143.26 million tokens over 7 days, accumulating $12.55+ in raw OpenRouter API costs. Forensic analysis revealed that over 80% of this spend was architectural waste:
- Unbounded Context Re-transmission: An uncompacted session (
agent:main:main) reached 381k tokens (2,650 events, 5.7 MB JSON). Every minor turn re-ingested this entire history, costing $12.20 (97.2% of total spend). - Heartbeat Amplification Loop: Background heartbeats firing every 30 minutes targeted the active user session (
target: last), re-evaluating the 381k context 48 times/day simply to outputNO_REPLY($5.16 wasted). - Expensive & Deprecated Model Allocations: Frontier models (
claude-3.7-sonnetanddeepseek-v4-pro) were configured without clear cost-benefit boundaries, with subagents frequently timing out (>300s). In addition, legacy model generations (e.g., Gemini 2.5) lingered in configuration despite superior, newer generations being available. - Modality Conflation (Image Input vs. Image Generation): Vision perception (analyzing an uploaded photo) was conflated with text-to-image synthesis (drawing an image). Configuring chat models like
z-ai/glm-5.3-flashfor image synthesis caused runtime HTTP 404 failures because pure LLMs lack diffusion/raster generation heads.
Moritz established two foundational requirements for the repository:
- "I want high quality, but it should not be too expensive."
- "We always want to use the newest models (as they usually are the best)."
How do we architect the full-spectrum model selection across all modalities (text, subagents, heartbeats, vision, image generation, audio transcription, text-to-speech, web search, and vector embeddings) to deliver premium quality, sub-10s latency, and a total operating budget of <$2.00 / week?
Decision Drivers
- State-of-the-Art Recency: Exclusively employ the latest generation models (e.g. DeepSeek V4.1 Flash 1017, Gemini 3.8/3.1, GLM 5.3, Whisper V3 Turbo, Sonar Pro). Completely decommission legacy generations (e.g. Gemini 2.5).
- Conversational & Reasoning Quality: High emotional intelligence, nuanced German fluency, personal context recall, and strict adherence to tool-calling protocols (ADR 0001).
- Strict Modality Decoupling: Each capability must route to its dedicated, best-in-class engine:
- Text & Agentic Reasoning
- Native Multimodal Vision (reading user photos)
- Text-to-Image Generation (synthesizing new pictures)
- Speech-to-Text / Audio Input (transcribing voice messages)
- Text-to-Speech / Audio Output (synthesizing briefings and podcasts)
- Web Search & Retrieval (grounded search)
- Semantic Embeddings (vector memory)
- Inference Economics: Low per-token costs for large conversational contexts (15k–80k tokens), high prompt-cache discount efficiency (
cacheRead), zero background bleed, and predictable billing. - Latency & Turn Responsiveness: Conversational turns on Telegram must return within 4–10 seconds, avoiding provider queuing or massive prefill bottlenecks.
- Resilience & Fault Tolerance: Automated fallback chains and strict quantization/provider pins (
fp8/bf16,tool_choicesupport) across independent providers on OpenRouter.
Full-Spectrum Model Architecture & Concrete Allocations
┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ OpenClaw Ingress Gateway │
└──────────────────────────────────────────────────┬─────────────────────────────────────────────────────┘
│
┌───────────────────┬─────────────────────┼─────────────────────┬───────────────────┐
▼ ▼ ▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Text Conductor │ │ Subagent Engine │ │ Background & │ │ Image Synthesis │ │ Voice & Audio │
│ & Vision Input │ │ (sessions_spawn)│ │ Heartbeat │ │ (Text-to-Image) │ │ (STT & TTS) │
├─────────────────┤ ├─────────────────┤ ├─────────────────┤ ├─────────────────┤ ├─────────────────┤
│ Tier 1 │ │ Tier 2 │ │ Tier 3 │ │ Tier 4 │ │ Tier 5 │
│ • Low Latency │ │ • Deep Analysis │ │ • target: none │ │ • Nano Banana 2 │ │ • Whisper V3 │
│ • Tool Routing │ │ • Autonomous │ │ • Zero Bleed │ │ • Dedicated │ │ • Gemini 3.1 │
│ • Decoupled OCR │ │ • Isolated Run │ │ • 30m Polling │ │ Raster Head │ │ Flash TTS │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Primary: │ │ Primary: │ │ Primary: │ │ Primary: │ │ STT: │
│ deepseek/ │ │ deepseek/ │ │ deepseek/ │ │ google/ │ │ openai/ │
│ deepseek-v4.1- │ │ deepseek-v4.1- │ │ deepseek-v4.1- │ │ gemini-3.1- │ │ whisper-large- │
│ flash-1017 │ │ flash-1017 │ │ flash-1017 │ │ flash-image │ │ v3-turbo │
│ │ │ │ │ │ │ │ │
│ Fallbacks: │ │ Fallbacks: │ │ Fallbacks: │ │ Fallbacks: │ │ TTS: │
│ 1. v4.1-flash │ │ 1. v4.1-flash │ │ 1. v4.1-flash │ │ 1. gemini-3.1- │ │ google/ │
│ 2. glm-5.3-flash│ │ 2. glm-5.3-flash│ │ 2. glm-5.3-flash│ │ flash-preview│ │ gemini-3.1- │
│ 3. qwen3.8-flash│ │ 3. qwen3.8-flash│ │ 3. qwen3.8-flash│ │ 2. gemini-3-pro-│ │ flash-tts │
│ │ │ │ │ │ │ image │ │ (FB: MiniMax 2.8│
│ Vision (OCR): │ │ │ │ │ │ │ │ Speech HD) │
│ google/ │ │ │ │ │ │ │ │ │
│ gemini-3.8- │ │ │ │ │ │ │ │ │
│ flash │ │ │ │ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
Modality Specifications & Cost-Benefit Analysis
1. Interactive Conductor & Agentic Reasoning (Tier 1)
- Primary (Fleet-Wide Standard as of 2026-10-17):
openrouter/deepseek/deepseek-v4.1-flash-1017- 1017 Snapshot Upgrade (Pareto Jump in Quality & Price): Released on October 17, 2026,
deepseek/deepseek-v4.1-flash-1017boosts the Artificial Analysis Intelligence Index from 24.7 to 39.5 (+60%) via Reinforcement Learning with Self-Feedback (RLSF) while cutting DeepInfrafp8pricing by an additional 30% ($0.098/Mprompt,$0.294/Mcompletion, and$0.00294/McacheReadvs.$0.140/$0.420/$0.0042on the 0910 baseline). - Provider Pinning & Tool-Compatibility Verification:
- Pinned
order: ["deepinfra", "cloudflare", "inference-net", "fireworks", "parasail"],quantizations: ["fp8", "bf16", "unknown"], andignore: ["morph", "baseten", "deepseek", "open-inference", "decart", "sail-research", "wafer"]. - Cloudflare (#2 Promotion): Promoted ahead of InferenceNet and Parasail because Cloudflare delivers a 97% cache discount (
$0.003/McacheRead), 3× lower completion costs ($0.60/Mvs.$1.20/Mon Parasail), and a massive 943,718 completion token limit. - Fireworks (#4 Addition): Onboarded as a high-reliability enterprise tier-1 provider (
$0.30/Mprompt,$1.20/Mcompletion,$0.006/McacheRead, 100% uptime, 943k max completion tokens, full tool choice and structured outputs support). - Completion Token Headroom Guardrail (
maxTokens: 65536): Because reasoning models share the completion token budget between internal chain-of-thought (reasoningTokens, typically 2k–4k tokens) and the actual tool-call payload, omittingmaxTokenspreviously allowed OpenClaw/OpenRouter to default to an 8,192 token ceiling. During large multi-kilobyte code or website generation, hitting 8,192 tokens abruptly truncated tool-call JSON mid-payload (Provider returned an incomplete or malformed tool call). Explicitly configuringmaxTokens: 65536andparams.max_tokens: 65536provides ample headroom for complex reasoning and large outputs. - Live OpenRouter routing forensics verified that
morph/fp8is filtered out by OpenRouter'sFilter by Tool Compatibilitywhentoolsare passed,deepseek(official) is filtered by account privacy guardrails (Paid model training violation), andbasetenreturnsHTTP 429. Meanwhile,deepinfra,cloudflare,inference-net,fireworks, andparasaildeliver 100% tool-calling reliability and sub-second to 3s latency.
- Pinned
- Post-Trial Evaluation of
z-ai/glm-5.3-flash(2026-09-13 to 2026-10-17):- While
z-ai/glm-5.3-flashwas trialed as primary conductor, 17-day production telemetry (Oct 1–17, 2026) revealed 12 mid-stream tool-call aborts (stopReason: "error",errorMessage: "Provider returned an incomplete or malformed tool call") across 5 agents (main,grabengasse_media,koch,hebamme,doktor) when generating nestedtool_call({ id, args })payloads aftertool_describe, as well as occasional thinking-only whitespace stalls (Issue 23) and long-context attention drift (Issues 22 & 25). - Promoting
deepseek/deepseek-v4.1-flash-1017to primary across all agents eliminates malformed tool-call stream aborts AND lowers total monthly cost by >50% compared to GLM 5.3 Flash.
- While
- Decoupled Vision Override:
deepseek/deepseek-v4.1-flash-1017,deepseek/deepseek-v4.1-flash, andz-ai/glm-5.3-flashare registered withinput: ["text"]undermodels.providers.openrouter.modelsso that OpenClaw always routes user photos throughtools.media.image(google/gemini-3.8-flash) for high-precision German OCR before handing enriched text to the chat model (Issue 29).
- 1017 Snapshot Upgrade (Pareto Jump in Quality & Price): Released on October 17, 2026,
- Fallbacks:
openrouter/deepseek/deepseek-v4.1-flash(0910baseline across 25+ providers, pinned todeepinfra,streamlake,inference-net,digitalocean,venice,nebius).openrouter/z-ai/glm-5.3-flash: Secondary fallback pinned tofp8/bf16providers (morph,near-ai,digitalocean,venice,streamlake).openrouter/qwen/qwen3.8-flash: Provider diversity.
2. Autonomous Subagents (Tier 2)
- All Subagents & Specialists:
openrouter/deepseek/deepseek-v4.1-flash-1017- Execution: Spawned via
sessions_spawnwith a 300-second timeout. Provides high-precision reasoning, rock-solid nested JSON tool loops (tool_search->tool_describe->tool_call), and zero syntax drift.
- Execution: Spawned via
- Fallback:
openrouter/deepseek/deepseek-v4.1-flash/openrouter/z-ai/glm-5.3-flash/openrouter/qwen/qwen3.8-flash.
3. Background Daemon & Heartbeats (Tier 3)
- Configuration:
heartbeat.model: "openrouter/deepseek/deepseek-v4.1-flash-1017",heartbeat.target: none,heartbeat.lightContext: true. - Rationale: Because background heartbeats have a 75%+
cacheReadshare (22.86McacheReadvs.7.73Muncached input over 17 days), DeepSeek V4.1 Flash 1017's $0.00294/M cache read rate on DeepInfra reduces 17-day heartbeat cost to <$0.90 while keeping prompt cache warm on the primary provider.
4. Vision Input vs. Text-to-Image Generation (Tier 4)
- Crucial Distinction:
- Vision Input (
imageModelvs. Dedicated Primary): Reading photos sent to Telegram (e.g. food ingredients, nutrition tables, plants, receipts). Note: OpenClaw only invokesimageModelif the primary model lacks image input modality. Sincez-ai/glm-5.3-flashadvertises image modality on OpenRouter, OpenClaw does not auto-divert toimageModel. Therefore, vision-intensive agents (specificallykoch) must explicitly configureprimary: "openrouter/google/gemini-3.8-flash"to leverage Google's SOTA OCR and dense-table recognition. - Text-to-Image Synthesis (
mediaModels.image): Creating new pictures upon user request (e.g. "Zeichne mir ein Profilbild von Octobot"). Chat LLMs return 404 here.
- Vision Input (
- Image Synthesis Engine:
- Primary:
openrouter/google/gemini-3.1-flash-image(Nano Banana 2).- Cost: $0.00006 per generated image + $0.50/1M prompt.
- Latency: ~4.5 seconds.
- Fallbacks:
openrouter/google/gemini-3.1-flash-image-previewopenrouter/google/gemini-3-pro-image(Nano Banana Pro)
- Decommissioned: Gemini 2.5 is completely removed from all image configurations.
- Primary:
5. Voice, Audio & Podcast Synthesis (Tier 5)
- Speech-to-Text (Audio Input):
- Engine:
openrouter/openai/whisper-large-v3-turbo - Capabilities: Fast, highly accurate transcription of German and English Telegram voice notes, with local gateway fallback.
- Engine:
- Text-to-Speech (Audio Dossiers & Podcasts):
- Engine:
google/gemini-3.1-flash-tts-previewviatext-to-audioskill. - Voices:
- German Solo/Host:
Puck(warm, natural, dynamic). - German Deep/Calm:
Charon. - German Co-Host / Expert:
Aoede. - English:
Zephyr.
- German Solo/Host:
- Fallback:
minimax/speech-2.8-hdfor studio-grade multi-speaker podcasts when Google TTS is throttled.
- Engine:
6. Grounded Web Search & Vector Embeddings
- Live Search:
perplexity/sonar-provia OpenRouter (replacing raw web scraping with grounded citations). - Memory Embeddings:
text-embedding-3-smallvia OpenRouter for the Obsidian personal knowledge wiki.
Context Lifecycle & Daytime Headroom Policy
To balance the user's desire to retain full conversation context across the entire day while avoiding the 70-second latency penalty that uncompacted transcripts impose on OpenRouter providers:
- Daytime Headroom (
maxActiveTranscriptBytes: "3mb"): The active transcript is permitted to retain the day's back-and-forth interactions so OpenClaw recalls earlier topics and instructions naturally. - Deterministic Nightly Compaction:
Scheduled daily at 03:30 AM Europe/Berlin (
ce39bbf8-b83f-453e-be53-04e27db27b78):Executes in 2.1 seconds using 0 LLM tokens, ensuring every morning begins with a lean, fast ~15k token transcript.openclaw sessions compact "agent:main:main" --max-lines 250
Open Clarifying Questions for Moritz
To align on remaining edge cases before final sign-off:
- Active Trial with GLM-5.3-Flash as Primary Conductor:
- As requested,
z-ai/glm-5.3-flashis now deployed as the Primary Conductor for interactive chat and autonomous subagents, equipped with the prompt guardrails against direct tool calls and XML leakage. deepseek/deepseek-v4.1-flashstands ready as the zero-latency primary fallback.- We will observe real-world performance, tool adherence, and cost over the next several days.
- As requested,
- Thinking / Reasoning Mode on Telegram:
- Currently,
thinking: mediumis enabled, emitting 100–300 reasoning tokens before generating conversational text. - Question: Would you like to disable thinking mode (
thinking: none) for standard Telegram chat turns (for near-instant replies) and keep reasoning active only for subagents?
- Currently,
- On-Demand Frontier Model:
- With all standard workloads handled by Flash-tier models, do you ever want an explicit escape hatch to a frontier model (e.g.
claude-3.7-sonnetorgemini-3.1-pro-previewtriggered exclusively via/expert <query>)?
- With all standard workloads handled by Flash-tier models, do you ever want an explicit escape hatch to a frontier model (e.g.
OpenRouter Provider Qualification Criteria & Re-Evaluation Playbook
Whenever a new model snapshot (such as deepseek/deepseek-v4.1-flash-1017) is evaluated or re-checked as new hosting providers join OpenRouter, every candidate provider MUST pass the following 7-point qualification gate before being added to extra_body.provider.order in openclaw-instance.secret.yaml:
1. Hard Technical Gates (Must Pass All)
- Quantization Precision (
fp8/bf16Only):- Rule: Must run
fp8orbf16(or verified full-precisionunknownfrom trusted cloud hosts like Cloudflare). - Reject: Any
fp4,nvfp4,mxfp4, orint4quantization (decart,sail-research,wafer,open-inference,phalafp4). 4-bit quantizations severely degrade nested JSON tool-call syntax and German grammar.
- Rule: Must run
- OpenRouter Routing Funnel & Guardrail Compatibility (
tools+tool_choice: "auto"Pass):- Rule: Must not be stripped by OpenRouter's internal routing filters (
Filter by Tool CompatibilityorFilter by Guardrails) when a request includestools: [...]andtool_choice: "auto". - Why: Metadata in
/api/v1/models/.../endpointscan claimsupports_tool_choice: trueeven when OpenRouter's live router blocks the provider on actual tool calls (e.g.morph/fp8is stripped byFilter by Tool Compatibility, anddeepseekofficial is stripped byPaid model training violationaccount privacy settings).
- Rule: Must not be stripped by OpenRouter's internal routing filters (
- Nested MCP
tool_callSerialization Integrity (2/2 Live Pass):- Rule: Must cleanly emit
finish_reason: "tool_calls"with valid, parseable nested JSON arguments ({"id": "mcp:...", "args": {...}}) across back-to-back test runs without mid-stream SSE aborts (Provider returned an incomplete or malformed tool call) or HTTP429upstream rate limits.
- Rule: Must cleanly emit
- Context Window & Completion Headroom:
- Rule:
context_length >= 262,144(1,048,576 preferred) andmax_completion_tokens >= 131,072. - Why: Active daytime sessions with system prompts and tool schemas reach 20k–80k tokens.
- Rule:
- Uptime & Reliability:
- Rule:
uptime_last_1d >= 95%anduptime_last_30m == 100%.
- Rule:
2. Economic & Latency Ranking (How to Order Passing Providers)
Among providers passing all 5 technical gates, rank them in extra_body.provider.order by effective production cost and turn latency:
- Implicit Prompt Cache Read Rate (
input_cache_read) — Highest Weight:- Because 73%–94% of OpenClaw's token volume (both interactive multi-turn chats and 30m background heartbeats) consists of cached prompt reads (
cacheRead), a provider withsupports_implicit_caching: trueand a 95%–98% cache discount (<= $0.005 / 1Mtokens, e.g.deepinfraat$0.00294/Morstreamlakeat$0.0030/M) is vastly cheaper in net monthly spend than a provider with slightly cheaper uncached input but weak or missingcacheReaddiscounts (e.g.nebiuswithcache_read: nullormodal/primeintellectat$0.030/M).
- Because 73%–94% of OpenClaw's token volume (both interactive multi-turn chats and 30m background heartbeats) consists of cached prompt reads (
- Base Prompt & Completion Pricing:
- Target
prompt <= $0.18 / 1Mandcompletion <= $0.65 / 1Mfor top-priority slots; allow higher-priced providers (<= $0.30 / $1.20) only in lower fallback slots (#3/#4) for outage resilience.
- Target
- End-to-End Tool-Call Latency:
- Target 1.0s – 5.5s for a ~300-token reasoning + tool-call turn.
3. One-Shot Live Verification Command (For Future Checks)
Any agent (including a fast/lightweight model) can audit all currently available OpenRouter endpoints for deepseek/deepseek-v4.1-flash-1017 in one step by running:
# 1. Inspect current endpoint metadata, pricing, cache_read, and 24h uptime:
curl -s https://openrouter.ai/api/v1/models/deepseek/deepseek-v4.1-flash-1017/endpoints | \
jq -r '.data.endpoints[] | "\(.provider_name) | tag=\(.tag) | quant=\(.quantization) | ctx=\(.context_length) | prompt=\(.pricing.prompt) | comp=\(.pricing.completion) | cache=\(.pricing.input_cache_read) | uptime1d=\(.uptime_last_1d)"'
# 2. Live-test candidate providers inside openclaw-0 with real nested tool_call payloads:
kubectl exec openclaw-0 -n openclaw -c openclaw -- python3 -c '
import os, json, time, urllib.request
api_key = os.environ["OPENROUTER_API_KEY"]
tools = [{"type": "function", "function": {"name": "tool_call", "parameters": {"type": "object", "properties": {"id": {"type": "string"}, "args": {"type": "object"}}, "required": ["id", "args"]}}}]
candidates = ["deepinfra", "streamlake", "inference-net", "venice", "digitalocean", "novita", "parasail", "cloudflare", "nebius"]
for prov in candidates:
req = urllib.request.Request(
"https://openrouter.ai/api/v1/chat/completions",
data=json.dumps({
"model": "deepseek/deepseek-v4.1-flash-1017",
"messages": [{"role": "user", "content": "Call tool_call with id=\"mcp:homeassistant:homeassistant__ha_get_state\" and args={\"entity_id\": \"media_player.bad\"}"}],
"tools": tools, "tool_choice": "auto", "max_tokens": 250,
"provider": {"order": [prov], "allow_fallbacks": False}
}).encode(),
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
)
t0 = time.time()
try:
with urllib.request.urlopen(req, timeout=20) as r:
b = json.loads(r.read().decode())
tc = b["choices"][0]["message"].get("tool_calls")
args = tc[0]["function"]["arguments"] if tc else "NONE"
print(f"PASS | {prov:15s} | {time.time()-t0:4.2f}s | actual={b.get(\"provider\")} | args={args}")
except urllib.error.HTTPError as e:
print(f"FAIL | {prov:15s} | HTTP {e.code} | {e.read().decode()[:140]}")
except Exception as e:
print(f"FAIL | {prov:15s} | ERR {e}")
'
Consequences
Positive
- Unified Latest-Generation Stack: Completely eliminates legacy Gemini 2.5 models; standardizes exclusively on DeepSeek V4.1 Flash 1017, Gemini 3.8/3.1, GLM 5.3, Whisper V3 Turbo, and Sonar Pro.
- 100% Reliable Image Generation: Correctly routes image generation requests to Nano Banana 2 (
google/gemini-3.1-flash-image), completely eliminating HTTP 404 generation errors. - Cohesive Voice & Audio Pipeline: Clear architectural documentation of the Whisper V3 Turbo and Gemini 3.1 Flash TTS integration for dossiers and podcasts.
- Guaranteed Cost Ceiling: Drops weekly expenditure from $12.55 to ~$0.80–$1.40 (~90% savings) through DeepSeek V4.1 Flash 1017's
$0.00294/Mcache reads, decoupled heartbeats, and nightly compaction.
Negative & Mitigations
- OpenRouter Provider Rollout Lag on Day-0 Model Releases: Newly released snapshots initially launch with 5–10 providers before the full fleet (25+ providers) joins over subsequent days.
- Mitigation: Codified the 7-point provider qualification gate and one-shot test script above, and configured automatic model fallback to the
0910snapshot (openrouter/deepseek/deepseek-v4.1-flash).
- Mitigation: Codified the 7-point provider qualification gate and one-shot test script above, and configured automatic model fallback to the