## Turn Your Local Ollama Model into a Persistent Messaging Assistant with OpenClaw
You’ve installed Ollama, pulled a capable model, and tested a few queries—results were sharp, latency was low, and everything ran privately on your hardware. But when you closed the terminal, the AI disappeared. That’s the gap **OpenClaw** fills.
OpenClaw, created by macOS developer Peter Steinberger (known for Apple tooling) and released in late 2025 originally as Clawdbot (now renamed), is a personal AI assistant that stays running on your machine. It bridges your local Ollama models to messaging apps you already use—WhatsApp, Telegram, Slack, Discord, and iMessage—without requiring API keys or cloud infrastructure. The project passed 60,000 GitHub stars within weeks, and as of Ollama 0.17, the entire setup collapses to a single command.
This article guides you from zero to a running private research assistant on Telegram, including correct context configuration, channel setup, web search enablement, and headless deployment in Docker.
### What OpenClaw Is and How It Works
Before running commands, it helps to understand the architecture, because it explains several setup decisions. Everything flows through a single daemon called the **Gateway**. It stays running in the background, holds your messaging connections open, and coordinates the AI agent. When you send a message from WhatsApp or Telegram:
1. Your text arrives via the messaging platform’s protocol (Baileys for WhatsApp, Bot API for Telegram).
2. It travels to the Gateway, which routes it to your model via Ollama’s local API.
3. The response returns through the same channel and appears in the messaging app.
This three-layer design differentiates OpenClaw from running a chatbot in a terminal:
– **Messaging layer**: The channel you send messages through—your phone, desktop Telegram client, Slack workspace, etc. You don’t need to be at the machine running Ollama.
– **Gateway daemon**: The coordination layer that persists even when idle, manages multi-step agent tasks, and delivers results when complete.
– **Model layer**: Ollama. This can be a fully local model on your GPU or a cloud-backed model routed through Ollama’s cloud service. The Gateway talks to Ollama’s local API either way.
OpenClaw was previously known as Moltbot and, before that, Clawdbot. It was renamed in early 2026. All old command aliases still work: `ollama launch clawdbot` remains functional.
### System Requirements and Prerequisites
The 64k context window requirement shapes hardware and model decisions. By default, Ollama allocates context based on VRAM: under 24 GB gets 4k, 24–48 GB gets 32k, and 48 GB or more gets 256k. Most consumer hardware defaults to 4k, which is insufficient for agent workloads involving multi-step tool use. You must explicitly set context.
**Hardware recommendations**:
– **OS**: macOS 12+ or Linux (Ubuntu 22.04+ recommended); Windows via WSL.
– **RAM**: 16 GB minimum; 32 GB recommended.
– **GPU VRAM for local models**: 25 GB minimum for models like qwen3-coder or glm-4.7-flash; 48 GB+ recommended.
– **Disk**: 5 GB for OpenClaw and dependencies; 30 GB+ if pulling local models.
– **Cloud models**: No GPU required; runs on Ollama’s cloud.
**Software prerequisites**:
– Ollama 0.17 or later (verify with `ollama –version`).
– Node.js 18 or later (Ollama detects this and prompts if missing).
– An Ollama account for cloud models and web search on local models.
**Model recommendations**: For most users starting out, `kimi-k2.5:cloud` is ideal. It’s free to start, handles agentic tasks well, and requires no VRAM. Cloud models have full context length and built-in web search.
### One-Command Installation with `ollama launch`
With Ollama 0.17+, you don’t manually install OpenClaw or manage the Gateway. Ollama handles bootstrapping:
“`bash
ollama launch openclaw
“`
Or directly specify a model:
“`bash
ollama launch openclaw –model kimi-k2.5:cloud
“`
Ollama then:
1. Checks and installs OpenClaw via npm if needed.
2. Displays a security warning: the agent can read files and execute actions when tools are enabled.
3. Shows a model selector (or uses your `–model` choice).
4. Configures your provider, installs the Gateway daemon, sets the model, and enables web search for cloud models.
5. Launches the Gateway and opens the OpenClaw terminal user interface (TUI).
To reconfigure without starting the agent:
“`bash
ollama launch openclaw –config
“`
If the Gateway is already running, it restarts automatically to pick up changes.
### Configuring Context Length for Agent Workloads
The official docs state a minimum of 64k tokens, but agents doing multi-step research (web search → read → extract → summarize) accumulate context across steps. At 64k, you have enough for a few turns with tool calls. For longer tasks, increase context.
For local models, set context before starting Ollama:
“`bash
# Option 1: Environment variable
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
# For longer tasks, use more if you have VRAM headroom
OLLAMA_CONTEXT_LENGTH=131072 ollama serve
“`
Or via the Ollama app: Settings → Context Length.
Verify the context applied and that the model isn’t offloaded to CPU:
“`
NAME ID SIZE PROCESSOR CONTEXT UNTIL
qwen3-coder:latest a4f2cc91b3e1 28.1 GB 100% GPU 65536 5 minutes from now
“`
Check that `PROCESSOR` shows `100% GPU`. If it shows split usage (e.g., `40% GPU / 60% CPU`), performance degrades significantly. `CONTEXT` should show 65536 or higher; if it shows 4096, your environment variable didn’t take effect (ensure you set it in the same shell where you run `ollama serve`).
If you can’t fit 64k in VRAM, use a cloud model instead—agents need context more than local inference.
### Connecting a Messaging Channel
Once the Gateway is running, connect your messaging platform:
“`bash
openclaw configure –section channels
“`
This interactive selector supports WhatsApp, Telegram, Slack, Discord, and iMessage.
**Setting up Telegram** (recommended for developers):
1. Create a bot with BotFather: `/newbot`, choose a name and username (must end in `bot`).
2. Copy the token (format: `1234567890:AAFxxxxxxxxxxxxxxxxxxxxxxxxxxxx`). You won’t see it again.
3. In the OpenClaw configurator, select Telegram and paste the token.
4. Select Finished to save (required).
5. Search for your bot on Telegram and send `/start`.
WhatsApp uses Baileys and requires QR scanning (links your personal account). Slack and Discord need a bot created via their developer portals with token and channel IDs.
### The Real-World Project: Private Research Assistant on Telegram
The goal: a Telegram bot that:
– Answers questions using your local or cloud model
– Performs web search using Ollama’s built-in web search
– Fetches and summarizes documents and URLs you send
– Handles multi-step research tasks with no data leaving your machine (when using a local model)
Once connected and the Gateway is running, this is functional immediately. OpenClaw handles the agent loop natively.
**Enabling web search**:
– Cloud models: Ollama installs the plugin automatically. Verify with a question requiring current information.
– Local models: First run `ollama signin`, then:
“`bash
openclaw configure –section web
“`
This enables the bundled `web_search` provider.
**A multi-step task in the TUI**:
Send:
“`
Find the three most-cited papers on transformer attention published in 2025 and give me a one-sentence summary of each.
“`
In the OpenClaw TUI you’ll see tool call logs:
“`
[tool] web_search: “most cited transformer attention papers 2025”
[tool] web_fetch:
[reasoning] Identified three papers: …
[response] Sending to Telegram…
“`
The task completes in 20–40 seconds, delivering a formatted message with papers, citation counts, and summaries.
**Python script for programmatic use**:
You can also call Ollama’s web search and chat APIs directly:
“`python
# research_agent.py
import sys
from ollama import chat, web_search, web_fetch
AVAILABLE_TOOLS = {
“web_search”: web_search,
“web_fetch”: web_fetch,
}
def run_research_agent(query: str, model: str = “qwen3.5:cloud”) -> str:
messages = [
{“role”: “system”, “content”: (
“You are a research assistant. Use web_search and web_fetch for ”
“current information and cite sources.”
)},
{“role”: “user”, “content”: query},
]
print(f”Query: {query}nModel: {model}n{‘─’ * 60}”)
while True:
response = chat(
model=model,
messages=messages,
tools=[web_search, web_fetch],
think=True,
)
if response.message.thinking:
print(f”[thinking] {response.message.thinking[:200]}…”)
messages.append(response.message)
if response.message.tool_calls:
for tool_call in response.message.tool_calls:
tool_name = tool_call.function.name
tool_fn = AVAILABLE_TOOLS.get(tool_name)
if not tool_fn:
messages.append({
“role”: “tool”,
“content”: f”Tool ‘{tool_name}’ is not available.”,
“tool_name”: tool_name,
})
continue
args = tool_call.function.arguments
print(f”[tool] {tool_name}({args})”)
result = tool_fn(**args)
result_str = str(result)
print(f”[result] {result_str[:150]}…”)
messages.append({
“role”: “tool”,
“content”: result_str[:8000],
“tool_name”: tool_name,
})
else:
final_answer = response.message.content
print(f”{‘─’ * 60}nAnswer:n{final_answer}”)
return final_answer
if __name__ == “__main__”:
query = sys.argv[1] if len(sys.argv) > 1 else “What are the latest developments in local LLMs?”
run_research_agent(query)
“`
Prerequisites:
“`bash
pip install ollama
ollama signin
ollama pull qwen3.5:cloud
“`
Run:
“`bash
python research_agent.py “What are the three most-cited papers on transformer attention published in 2025?”
“`
**Critical note**: The script truncates tool results at 8,000 characters to avoid consuming your context budget. Without this, a single web fetch can use 20k–40k tokens, starving subsequent steps.
### Non-Interactive and Headless Deployment
For production or Docker deployments, use `–yes` to skip the TUI:
“`bash
ollama launch openclaw –model kimi-k2.5:cloud –yes
“`
This auto-pulls the model, skips interactive prompts, and starts the Gateway immediately. You must specify `–model`.
**Dockerfile for headless OpenClaw**:
“`dockerfile
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl
&& curl -fsSL https://dl.nodejs.org/node/gpgkeys/node-repo.gpg.key | gpg –dearmor -o /usr/share/keyrings/nodejs-archive-keyring.gpg
&& echo “deb [signed-by=/usr/share/keyrings/nodejs-archive-keyring.gpg] https://deb.nodesource.com/node_18.x nodistro main” | tee /etc/apt/sources.list.d/nodesource.list
&& apt-get update && apt-get install -y nodejs
RUN curl -fsSL https://ollama.com/install.sh | sh
RUN npm install -g openclaw
ENV OLLAMA_CONTEXT_LENGTH=64000
COPY start.sh /start.sh
RUN chmod +x /start.sh
EXPOSE 11434
CMD [“/start.sh”]
“`
`start.sh`:
“`bash
#!/bin/bash
set -e
ollama serve &
OLLAMA_PID=$!
echo “Waiting for Ollama to start…”
for i in $(seq 1 30); do
curl -s http://localhost:11434 > /dev/null && break
sleep 1
done
ollama launch openclaw
–model “${OLLAMA_MODEL:-kimi-k2.5:cloud}”
–yes
wait $OLLAMA_PID
“`
Build and run:
“`bash
docker build -t openclaw-agent .
docker run -d –gpus all –env-file .env –name openclaw openclaw-agent
docker logs -f openclaw
“`
For local models without GPU, remove `–gpus all` and set `OLLAMA_MODEL` to a cloud model.
Stop the Gateway cleanly with:
“`bash
openclaw gateway stop
“`
It will restart automatically on next `ollama launch`.
### Stopping the Gateway and Troubleshooting
– Use `openclaw gateway stop` to terminate cleanly.
– Check if the Gateway is running: `pgrep -la openclaw`.
– Outdated answers: verify `ollama signin`.
– `context length exceeded`: increase `OLLAMA_CONTEXT_LENGTH` and restart `ollama serve`.
– Model partially on CPU (split % in `ollama ps`): reduce context, switch models, or use cloud.
### Conclusion
OpenClaw and Ollama close the gap between terminal-based AI and persistent, anywhere access. The Gateway runs in the background while your messaging app becomes the interface—one command sets up the entire stack.
Multi-step research tasks that once took 20 minutes now complete in the background, delivered as formatted messages to your phone. File handling, calendar management, and inbox processing are all expanding through OpenClaw’s skill library.
For privacy-conscious users, a capable local model with one context-length configuration delivers a fully private agent. For quick starts, cloud models are one command away. Either way, the result is an AI assistant that answers messages, does research, and runs on infrastructure you control.
### Resources
– Shittu Olumide — software engineer and technical writer focused on cutting-edge technologies. [Twitter](https://twitter.com/Shittu_Olumide_)
– [OpenClaw on GitHub](https://github.com/gradio-app/openclaw)
– [Ollama](https://ollama.com)
—
**Original article**: [Running OpenClaw with Ollama](https://www.kdnuggets.com/running-openclaw-with-ollama), KDnuggets.



