17 KiB
status, date, decision-makers, consulted, informed
| status | date | decision-makers | consulted | informed | ||
|---|---|---|---|---|---|---|
| accepted (trial: GLM-5.3-Flash) | 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. Gemini 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), 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 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 │
│ • Native Vision │ │ • Isolated Run │ │ • 30m Polling │ │ Raster Head │ │ Flash TTS │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Primary (Trial):│ │ Primary (Trial):│ │ Primary: │ │ Primary: │ │ STT: │
│ z-ai/ │ │ z-ai/ │ │ z-ai/ │ │ google/ │ │ openai/ │
│ glm-5.3-flash │ │ glm-5.3-flash │ │ glm-5.3-flash │ │ gemini-3.1- │ │ whisper-large- │
│ │ │ │ │ │ │ flash-image │ │ v3-turbo │
│ Fallbacks: │ │ Fallbacks: │ │ Fallbacks: │ │ │ │
│ 1. deepseek- │ │ 1. deepseek- │ │ 1. deepseek- │ │ Fallbacks: │ │ TTS: │
│ v4.1-flash │ │ v4.1-flash │ │ v4.1-flash │ │ 1. gemini-3.1- │ │ google/ │
│ 2. qwen3.8-flash│ │ 2. qwen3.8-flash│ │ 2. qwen3.8-flash│ │ flash-preview│ │ gemini-3.1- │
│ │ │ │ │ │ │ 2. gemini-3-pro-│ │ flash-tts │
│ Vision Fallback:│ │ │ │ │ │ image │ │ (FB: MiniMax 2.8│
│ google/ │ │ │ │ │ │ │ │ Speech HD) │
│ gemini-3.1- │ │ │ │ │ │ │ │ │
│ flash-image │ │ │ │ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
Modality Specifications & Cost-Benefit Analysis
1. Interactive Conductor & Agentic Reasoning (Tier 1)
- Primary (Active Trial):
openrouter/z-ai/glm-5.3-flash- Pricing: $0.075 / 1M prompt tokens; $0.300 / 1M completion tokens. This is 50–75% more cost-effective than DeepSeek V4.1-Flash and offers a 1.3M token context window. Under daytime context headroom (
25k–60k tokens), daily cost is only **$0.01–$0.02 / day**. - Performance & Reasoning: SOTA Chinese & English reasoning, competitive coding benchmarks, and native vision perception.
- Forensic Diagnosis & Tool-Calling Protocol Fix:
- Incident: On September 14, 2026, GLM-5.3-Flash emitted raw
<tool_call>supermarket__supermarket_search...</tool_call>XML into Telegram instead of executing tools. - Root Cause Identified: In Zhipu AI's pre-training tokenizer, function calls are emitted as special XML tokens. When models are queried through OpenRouter's OpenAI-compatible API, OpenRouter only intercepts and translates
<tool_call>tokens into JSON if the toolnameexists in the request's registeredtools: [...]array. OpenClaw uses dynamic Tool Search (tools.toolSearch.mode: "directory") where only 3 control tools (tool_search,tool_describe,tool_call) are registered intools. When GLM received deferred schemas (e.g.,supermarket__supermarket_search), its pre-training prior prompted it to call the tool directly. Becausesupermarket__supermarket_searchwas not in OpenRouter'stoolsarray, OpenRouter passed the raw XML through as message text. Once that text entered the session history (events SEQ 297 & 306), GLM was in-context primed to repeat the XML pattern. - Remediation & Verification: We introduced an explicit deferred tool execution protocol into
AGENTS.mdinstructing the model that deferred tools must NEVER be called directly and MUST be routed viatool_call({ id: 'tool_name', args: { ... } }). Direct OpenRouter API probes confirmed that with this rule, GLM-5.3-Flash callstool_callwith 100% compliant JSON and zero XML leakage. Session events were sanitized.
- Incident: On September 14, 2026, GLM-5.3-Flash emitted raw
- Pricing: $0.075 / 1M prompt tokens; $0.300 / 1M completion tokens. This is 50–75% more cost-effective than DeepSeek V4.1-Flash and offers a 1.3M token context window. Under daytime context headroom (
- Fallbacks:
openrouter/deepseek/deepseek-v4.1-flash: Rock-solid JSON tool-calling and sub-3s response times via dedicated OpenRouter ASIC cluster, available immediately if GLM experiences any upstream provider queuing or issues.openrouter/qwen/qwen3.8-flash: Provider diversity.
2. Autonomous Subagents (Tier 2)
- Primary (Active Trial):
openrouter/z-ai/glm-5.3-flash- Execution: Spawned via
sessions_spawnwith a 300-second timeout. Inherits thetool_callprotocol guardrails fromAGENTS.md.
- Execution: Spawned via
- Fallback:
openrouter/deepseek/deepseek-v4.1-flashfor high-concurrency tool execution fallback.
3. Background Daemon & Heartbeats (Tier 3)
- Configuration:
heartbeat.model: "openrouter/z-ai/glm-5.3-flash",heartbeat.target: none,heartbeat.lightContext: true. - Rationale: Decoupled completely from user conversation transcripts. Polling occurs against an isolated, minimal prompt (~400 tokens), dropping weekly heartbeat token burn from 21,000,000 to <150,000 tokens (<$0.02 / week).
4. Vision Input vs. Text-to-Image Generation (Tier 4)
- Crucial Distinction:
- Vision Input (
imageModel): Reading photos sent to Telegram (e.g. food ingredients, plants, receipts). Handled natively byz-ai/glm-5.3-flash, withgoogle/gemini-3.1-flash-imageas fallback. - 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.
Consequences
Positive
- Unified Latest-Generation Stack: Completely eliminates legacy Gemini 2.5 models; standardizes exclusively on Gemini 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 ~$1.20–$1.80 (85–90% savings) through decoupled heartbeats and nightly compaction.
Negative & Mitigations
- OpenRouter Provider Variability: GLM-5.3-Flash prefill throughput varies across OpenRouter hosting providers.
- Mitigation: Daily compaction bounds transcript size; failover to DeepSeek V4.1-Flash is available at zero architectural switching cost.