OpenClaw Advanced Guide: Model Selection, Memory Restructuring & Gateway Auto-Repair

Four advanced OpenClaw techniques: model selection, memory optimization, search integration, and auto-repair
This article systematically covers four advanced techniques for the OpenClaw AI Agent platform: model selection strategy (Opus 4.6 for complex Agent tasks, GPT-5.2 for cost-effectiveness, MiniMax M2.1 as open-source supplement), topic-based memory splitting upgradeable to LanceDB vector retrieval, packaging Codex deep search as a Skill to build a three-tier search decision tree, and implementing unattended Gateway crash auto-diagnosis and repair using systemd and Claude Code.
OpenClaw (OpenCloud), as a powerful AI Agent platform, has accumulated extensive practical experience through intensive use. Based on an in-depth sharing from a Bilibili content creator, this article systematically covers core advanced techniques including model selection strategies, memory system optimization, deep search integration, and Gateway crash auto-repair, helping users elevate their OpenClaw efficiency to the next level.

Model Selection Strategy: Less Is More
After prolonged intensive use, the author ultimately retained only three core models in OpenClaw, each with clearly defined use cases.
Claude Opus 4.6: First Choice for Complex Tasks
Although Anthropic recently released Claude Sonnet 4.6, extensive testing revealed that Sonnet 4.6's Agentic capabilities are significantly inferior to Opus 4.6. Agentic capability refers to an AI model's comprehensive ability to autonomously plan tasks, invoke tools, process intermediate results, and iteratively execute within an Agent framework. This is fundamentally different from traditional single-turn Q&A or pure text generation—Agent scenarios require models to have stable Function Calling capabilities, context retention across multi-step reasoning, and self-correction when tools return anomalies. When executing complex Agent tasks in OpenClaw that require multi-step reasoning and tool invocation, Opus 4.6 remains the irreplaceable first choice.
This finding reminds us: a model's overall capability ranking does not equate to its actual performance in Agent scenarios—selection must be tested against specific use cases. Benchmarks often focus on single-turn capabilities, while Agent scenarios test a model's robustness and consistency across long execution chains. Anthropic's Opus series places greater architectural emphasis on long-context reasoning and tool-use stability, giving it a unique advantage in Agent scenarios.
GPT-5.2: Best Value for Money
OpenAI Codex's built-in GPT-5.2 model is suitable for medium-complexity tasks, and its quota is much more generous than Anthropic's Opus 4.6. A notable detail: while GPT-5.3 Codex has stronger coding capabilities, it's not well-suited for Agentic tasks in OpenClaw—it's more oriented toward pure coding scenarios.
When using GPT-5.2, you can set the thinking level via the Think command (disabled by default), choosing Low/Medium/High based on task complexity. For example, setting it to High can significantly improve reasoning quality for complex tasks. The Think command is essentially explicit control over the model's Reasoning Budget—modern large language models undergo an internal reasoning process (Chain-of-Thought) before generating their final answer, and the Think level directly affects the computational resources invested in this phase. Low level suits simple information extraction or format conversion, where the model nearly skips deep reasoning and outputs directly; Medium level suits tasks requiring some logical judgment; High level allows the model to perform thorough multi-step reasoning, similar to OpenAI's o1/o3 series deep thinking mode. Note that higher Think levels mean more token consumption and longer response times, so dynamically adjusting based on task complexity is the optimal strategy.
MiniMax M2.1: Best Open-Source Companion
If you need an open-source model as a supplement, MiniMax M2.1 is currently the best pairing with OpenClaw. It excels among open-source models in both response speed and reasoning capability, making it suitable for handling lightweight tasks to conserve quota for primary models.
Memory System Optimization: From Single File to Topic-Based Management
The memory system is one of OpenClaw's core capabilities, but the default single-file Markdown memory approach encounters serious retrieval efficiency issues as knowledge volume grows.
Splitting Memory Files by Topic
Before splitting, the author's memory.md file was a 15KB single file with all knowledge mixed together, resulting in poor retrieval hit rates. The solution is to have OpenClaw split memory by Topics:
- Input a command in OpenClaw requesting topic-based splitting of the memory.md file
- OpenClaw automatically analyzes the content and creates a
memory/topics/folder - Different categories of memory are stored in independent files, for example:
- Multi-Agent collaboration tips and techniques
- OpenClaw configuration-related memories
- Browser automation experiences
- Docker configuration-related memories
- Node configuration-related memories
After splitting, the main memory file retains only the index and key rules, shrinking from 15KB to 2.3KB. Each topic file grows independently without interference, and new knowledge can be precisely appended to the corresponding topic.
Advanced Direction: LanceDB Vector Memory System
The author went further by restructuring OpenClaw's Markdown memory system into a LanceDB-based vector memory system. Traditional Markdown memory systems rely on keyword matching or simple text search, which fails when the user's query phrasing doesn't match the original wording in memory. For example, if memory records "solution for Docker container port mapping conflicts" but the user asks "what to do about container network configuration errors," keyword matching may completely miss the target.
LanceDB is a lightweight embedded vector database that converts text into high-dimensional vectors through Embedding models and performs similarity calculations in semantic space. This means that even with completely different wording, content can be retrieved as long as the semantics are similar. This approach achieves 100% hit rate on stored pitfall experiences, technical details, and methodologies when executing complex tasks. Compared to cloud-based vector databases like Pinecone and Weaviate, LanceDB's zero-dependency nature allows it to run locally without external services and supports incremental updates, making it ideal as a knowledge base engine for personal developers' local Agent scenarios. Compared to text matching, vector retrieval has fundamental advantages at the semantic understanding level, especially suitable for users with large memory volumes and complex scenarios.
Deep Search Integration: Leveraging Codex's Research Capabilities
OpenClaw's built-in search functionality is quite limited—WebSearch requires configuring a Brave API, and WebFetch can only fetch URL content. For complex multi-dimensional research needs, these two tools are far from sufficient.
Packaging Codex Deep Search as a Skill
The author's solution is to package Codex CLI's Deep Research capability as an OpenClaw Skill. The Skill mechanism in OpenClaw is essentially a plugin-based capability registration system—each Skill defines a set of input parameters, execution logic, and output format. After receiving a user request, the Agent selects the most appropriate execution path from the registered Skill list based on intent recognition results. The process of packaging Codex CLI as a Skill is essentially registering a new external capability node in OpenClaw's toolchain, which the Agent can invoke just like built-in tools. This architectural design follows microservice and Unix philosophy—each tool does one thing well, achieving complex functionality through composition.
Codex's built-in search functionality is extremely powerful, operating at a true deep research level. Its Deep Research feature automatically decomposes a complex question into multiple sub-queries, searches them separately, then synthesizes the analysis, conducting multiple rounds of search and generating comprehensive retrieval reports—far exceeding the search depth of a single API call.
The integrated search decision tree works as follows:
- User inputs a URL → Directly fetch webpage content via WebFetch, converting to Markdown format
- Simple factual queries → Call Brave search for quick results
- Complex multi-dimensional research → Call Codex CLI for multi-round deep search
In actual testing, after inputting "deeply research the latest advances in AI Agents," the system automatically identified it as a complex query, invoked Codex to complete multi-round research, and delivered core conclusions from the past 3-6 months, specific source links, and detailed analysis reports. This layered search strategy both conserves resources and ensures complex needs are met.
Gateway Crash Auto-Repair: An Unattended Operations Solution
This is the most engineering-valuable section of this article. OpenClaw's Gateway may crash due to plugin bugs and fail to restart. If this occurs during late-night or unattended periods, it severely impacts service availability.
Auto-Repair Mechanism Workflow
The author designed an auto-repair solution based on systemd and Claude Code. systemd is the core initialization and service management framework in Linux systems, defining service startup, shutdown, dependencies, and failure handling strategies through Unit files. Its OnFailure directive allows automatic triggering of another service unit when a service exits abnormally—this is the key mechanism for building self-healing systems. In traditional operations, similar functionality is typically implemented by process monitoring tools like Supervisor or Monit, but systemd as a system-level component offers lower latency and higher reliability.
The innovation of this solution lies in embedding AI diagnostic capabilities into the failure recovery workflow—traditional self-healing systems can only execute predefined repair actions (such as restarting services or rolling back configurations), but with Claude Code introduced, the system gains the ability to understand log semantics, locate unknown error types, and generate targeted repair code. This essentially brings AIOps (Intelligent Operations) concepts down from enterprise infrastructure to the individual developer's toolchain.
The specific workflow is divided into three phases:
Phase 1: Fault Detection and Triggering
- Gateway crashes due to an anomaly
- systemd detects service failure (OnFailure) and automatically starts the repair service
Phase 2: AI Diagnosis and Repair
- The repair script automatically reads Gateway logs
- Log information is passed to Claude Code for analysis
- Claude Code diagnoses the problem type: JSON syntax errors, plugin configuration errors, port conflicts, etc.
- Automatically modifies configuration/code and validates JSON syntax
Phase 3: Verification and Retry
- Restart Gateway after repair
- Wait 8 seconds and check if the process is alive
- If alive → repair successful, log the event
- If crashed → enter second repair cycle
- If both repairs fail → notify user via messaging app for manual intervention
Real-World Case
The author encountered a Gateway crash in the early morning hours. After Claude Code automatically intervened, analysis revealed that the DingTalk plugin threw an uncaught exception during reconnection, causing the entire process to crash.
In single-threaded runtime environments like Node.js, an Uncaught Exception causes the entire process to exit immediately. OpenClaw Gateway, as a long-running service process, integrates multiple plugins (such as DingTalk, WeChat, and other communication plugins), each of which may trigger reconnection logic during network fluctuations. If exceptions during reconnection aren't properly caught by try-catch, or if Promise rejections go unhandled (Unhandled Promise Rejection), they bubble up to the process level and cause a crash. These issues are difficult to reproduce during development because they typically depend on specific network conditions and timing combinations. Claude Code's advantage in fixing such issues is its ability to understand the code's asynchronous execution flow, trace exception propagation paths, and add error handling logic at the correct locations, rather than simply wrapping a global exception catch at the outermost level.
After the repair, Gateway automatically restarted successfully—the entire process required zero manual intervention. When waking up in the morning, the author only needed to check the logs to understand the fault cause and repair process.
The core value of this solution: making AI not just a development tool, but also an operations tool. Through Claude Code's code comprehension and repair capabilities, a truly self-healing system is achieved.
Summary and Outlook
The four advanced techniques shared in this article represent different levels of OpenClaw usage:
- Model selection is the foundation, determining the upper limit of task execution
- Memory optimization is about efficiency, determining the precision of experience reuse
- Search integration is capability extension, compensating for native tool limitations
- Auto-repair is engineering maturity, achieving stable unattended operation
The common thread across these techniques: they don't depend on platform updates, but rather extend OpenClaw's capability boundaries through Skills, scripts, and system configuration. This mindset of "enhancing your AI Agent with your own hands" is worth adopting for every power user.
Related articles
TutorialsCursor + Codex Dual-IDE Collaboration: A Practical Methodology for Open-Source Project Customization
A complete methodology for open-source project customization based on real-world experience, detailing the Cursor+Codex dual-IDE workflow, seven-stage process, MVP validation, and AI source code reading techniques.
TutorialsCursor Multi-Agent in Practice: Building a Full-Stack Next.js Blog in 50 Minutes
Build a full-stack blog in 50 minutes using Cursor IDE's multi-Agent mode with Next.js, Clerk auth, and Supabase. Learn the 4-phase AI Agent workflow and key integration pitfalls.
TutorialsBuilding an AI Software Factory from Scratch: A Cursor Engineer's Hands-On Experience with Multi-Agent Collaboration
Cursor engineer Eric shares practical insights on building an AI software factory: automation levels, guardrail design, parallel Agent management, and scaling to 1000+ Agents for 24/7 development.