🤖 AI Agents (OpenClaw)

Build Your First Local AI Agent with OpenClaw and Ollama

15 min read
Updated June 2025
Beginner friendly

A chatbot answers questions. An AI agent goes further: it can use tools, remember what it did in previous sessions, break a complex goal into subtasks, and execute each one — autonomously, step by step — until the job is done.

The practical difference is significant. A chatbot can tell you how to summarize a folder of documents. An agent can actually do it — read each file, draft the summaries, write them to disk, and report back. No copy-pasting required.

OpenClaw is one of the most widely used open-source agent frameworks, and it runs entirely with local models via Ollama — no OpenAI API key, no monthly bill, no data leaving your machine. This guide walks you from zero to a working file-processing agent in about 20 minutes.

Prerequisites

  • Ollama installed and running

    The agent communicates with your model over the Ollama REST API at localhost:11434.

    Install guide →
  • A model with solid tool-calling support

    Tool-calling requires a model large enough to reliably follow JSON schemas. Qwen3 14B is the minimum recommended — Qwen3 32B or Llama 3.3 70B if you have the VRAM.

  • Node.js 18+ or Python 3.10+

    OpenClaw ships packages for both runtimes. The examples below use the Node.js CLI, but every concept maps 1:1 to the Python SDK.

Install OpenClaw

OpenClaw is distributed as both an npm package (for the CLI and Node.js SDK) and a pip package (for the Python SDK). Install whichever matches your preferred runtime:

bash
# Install OpenClaw CLI globally via npm
npm install -g openclaw

# Verify installation
openclaw --version
openclaw 0.9.4

# Alternative: Python package
pip install openclaw

Once installed, run openclaw init inside your project directory. This creates an openclaw.config.json file and a tools/ directory where your custom tool definitions live.

Connect OpenClaw to your local Ollama

Open openclaw.config.json and point it at your local Ollama endpoint. The key fields are provider, endpoint, and model:

json
{
  "model": "qwen3:14b",
  "endpoint": "http://localhost:11434",
  "provider": "ollama",
  "temperature": 0.3,
  "context_window": 8192,
  "memory": {
    "enabled": true,
    "store": "./agent_memory.db"
  }
}

Setting temperature to 0.3 keeps the agent's reasoning deterministic and focused — higher values make it more creative but less reliable when filling in tool call parameters. For agents, lower is almost always better.

Give your agent a tool

Tools are the bridge between the language model's reasoning and the real world. A tool is essentially a function description — the agent sees the name, description, and expected parameters, and decides when and how to call it. OpenClaw uses the same JSON Schema format as the OpenAI function-calling spec, so most existing tool definitions are portable.

Here's a simple read_file tool definition you can drop into tools/read_file.json:

json
// Tool definition — JSON Schema format (used by OpenClaw and most agent frameworks)
{
  "name": "read_file",
  "description": "Read the contents of a file at the given path",
  "parameters": {
    "type": "object",
    "properties": {
      "path": {
        "type": "string",
        "description": "Absolute or relative path to the file"
      }
    },
    "required": ["path"]
  }
}

OpenClaw bundles a standard library of common tools — read_file, write_file, list_dir, run_shell, and http_get — that you can enable by name in config. Custom tools (your own Python or JS functions) are loaded from the tools/ directory and work identically.

Run your first task

With the config in place and at least one tool enabled, you're ready to run your first agent task. Pass a natural-language goal to openclaw run:

bash
# Launch the agent with a natural-language task
openclaw run --task "Summarize every .md file in ./docs and write a one-paragraph overview for each"

━━━ Agent starting ━━━
Model : qwen3:14b @ localhost:11434
Tools : read_file, list_dir, write_file (3 enabled)

[Thought]  I need to find all .md files inside ./docs first.
[Action]   list_dir(path="./docs")
[Obs]      README.md  setup.md  api-reference.md  changelog.md

[Thought]  Four files found. I'll read each one and draft a summary.
[Action]   read_file(path="./docs/README.md")
[Obs]      <file content, 420 words>

[Thought]  Good. Writing summary for README.md now.
[Action]   write_file(path="./summaries/README.summary.md", content="...")
[Obs]      File written successfully.

[...3 more files processed...]

[Final Answer]
Done. Summaries written to ./summaries/ (4 files).
Total tokens used: 6,241 | Time: 48 s

The output shows the agent's full reasoning loop: a Thought (what it plans to do), an Action (the tool call with arguments), an Observation (the tool's return value), and ultimately a Final Answer. This ReAct (Reason + Act) pattern is the standard control loop for most agent frameworks.

Token count and wall-clock time are shown at the end. For a 14B model on a mid-range GPU, expect roughly 1–3 minutes per 5,000 tokens of context. Larger models are slower but make fewer mistakes in multi-step tasks.

⚠️
Agents with tool access can modify your filesystem and run shell commands. Before enabling tools like run_shell or giving write access to sensitive directories, run the agent inside a container or VM with limited permissions. A misbehaving agent (or a sufficiently creative prompt injection via a file it reads) can cause real damage on a machine with broad access. Start with read-only tools, verify behavior, then expand permissions incrementally.
💡
Persistent memory between sessions. When memory.enabled is set to true in your config, OpenClaw stores a compressed summary of each session in a local SQLite database. The next time you run the agent on the same project, it loads prior context automatically — so it remembers files it already processed, decisions it made, and notes it left for itself. This makes OpenClaw genuinely useful for long-running projects that span multiple days.

Troubleshooting

Agent loops without finishing a task

The most common cause is a model that's too small to reliably generate valid tool-call JSON. Models under ~8B parameters often hallucinate tool names or produce malformed argument objects, causing the agent to retry indefinitely. Upgrade to Qwen3 14B or larger:

# Switch to a larger model that handles tool-calling reliably
openclaw config set model qwen3:14b

# Or edit openclaw.config.json directly
"model": "qwen3:14b"   # minimum recommended for tool-calling

If you must use a smaller model, try setting max_iterations in config to cap the loop (e.g., "max_iterations": 10).

Connection refused connecting to localhost:11434

OpenClaw can't reach the Ollama API — the server isn't running. Ollama must be started separately before running the agent:

# Start the Ollama server (required before running any agent)
ollama serve

# Verify it's listening on 11434
curl http://localhost:11434
Ollama is running

On Linux, you can also run "systemctl start ollama" if you installed via the official script, which registers Ollama as a systemd service.

Need a system prompt for your agent?

Use our Prompt Generator — select "AI agent / tool-calling" and get an optimized prompt with tool-use instructions, ReAct reasoning steps, and temperature guidance.

Try it →
💸

Curious what running this as a cloud agent would cost?

Agents make many API calls per task — that adds up fast. See exactly what you'd pay monthly with Claude, GPT, or Gemini vs. $0 with Ollama.

Try our API Cost Calculator →
🚀

Want to know what's trending in AI agents this month?

The local AI ecosystem moves fast. New model releases, framework updates, and hardware breakthroughs happen weekly. Stay current with our Latest Releases section — no newsletter required, no paywalls.

See Latest Releases →

Related guides