马来西亚云服务

A chatbot responds. An agent acts.

When you ask a chatbot a question, it generates a response and stops. An agent, by contrast, enters a perceive → reason → act → observe loop. It receives a goal, figures out what steps are needed, executes those steps using tools, observes the results, and then plans its next move — repeating this cycle until the task is complete.

The Four Pillars

Reasoning

The LLM core that plans, decides, and interprets results at each step.

Tools

Functions the agent can call — web search, file I/O, calculators, APIs.

Memory

Short-term context within a run and long-term storage across sessions.

Action

The ability to make real changes — write files, send requests, trigger automations.

Real-world uses for personal agents include automated research pipelines, coding assistants that can run and test their own code, personal data analysts that work on your local files, and scheduled bots that monitor services and alert you to changes.

3. Prerequisites

A. Knowledge

B. System Requirements

C. Accounts & API Keys

✅ Tip

If you’d rather not pay for an API key right away, OpenClaw supports Ollama for running local models like Mistral or LLaMA 3 at zero cost. Performance will be lower, but it’s a great way to experiment first.

4. Installing OpenClaw

OpenClaw can be installed in three ways. For most users, the pip install route is the fastest path to a working setup.

Option A — pip (Recommended)

    
     # Create and activate a virtual environment
python -m venv openclaw-env
source openclaw-env/bin/activate  # Windows: openclaw-env\Scripts\activate

# Install OpenClaw
pip install openclaw

# Verify
openclaw --version
    
   

Option B — Docker

    
     docker pull openclaw/openclaw:latest
docker run -it --rm \
  -e OPENAI_API_KEY=your_key_here \
  -v $(pwd)/workspace:/workspace \
  openclaw/openclaw:latest
    
   

Option C — From Source

    
     git clone https://github.com/openclaw/openclaw.git
cd openclaw
pip install -e ".[dev]"
    
   

Environment Configuration

Create a .env file in your project directory with your credentials:

    
     OPENAI_API_KEY=sk-...
OPENCLAW_MODEL=gpt-4o
SERPAPI_KEY=your_search_key   # optional
OPENCLAW_LOG_LEVEL=INFO
    
   
⚠️ Security

Never commit your .env file to version control. Add it to .gitignore immediately. Your API keys are credentials — treat them like passwords.

5. Core Concepts in OpenClaw

Before building, it helps to understand OpenClaw’s mental model. Everything revolves around a single YAML config file that describes your agent’s identity, capabilities, and constraints.

Agent Anatomy

An OpenClaw agent is composed of three layers:

  • Brain — the LLM that does reasoning (GPT-4o, Claude, Mistral, etc.).
  • Body — the tools it can use to interact with the world.
  • Memory — the context it retains within and across sessions.

The Planning Loop

When you give your agent a task, it enters a reasoning loop powered by the ReAct pattern (Reasoning + Acting). At each step the model thinks out loud — deciding what action to take — calls a tool, receives the result, and decides what to do next. This loop continues until the agent determines the task is complete.

    
     User Goal → [Reason] → [Act: call tool] → [Observe result]
               ↑______________↓
            (repeat until done)
    
   

Memory Types

Short-Term

The active conversation window. Cleared when the session ends.

Long-Term

A vector database (Chroma, Pinecone) that persists between runs.

Working Memory

A scratchpad the agent writes to mid-task for intermediate results.

6. Building Your First Agent

Create a new directory for your project and add an agent.yaml file. This is the single source of truth for your agent.

    
     name: MyFirstAgent
description: A simple personal assistant agent

model:
  provider: openai
  name: gpt-4o
  temperature: 0.3

tools:
  - web_search
  - file_writer
  - calculator

memory:
  short_term: true
  long_term: false

max_iterations: 15
verbose: true
    
   

Now run it for the first time:

    
     openclaw run agent.yaml \
  --task "What are the three most important AI research papers published this month? Summarize each in two sentences."
    
   

You’ll see OpenClaw’s planning loop in your terminal — each step labelled with [THINK][ACT], and [OBSERVE]. Watch as the agent searches the web, reads results, and composes a structured answer.

💡 Reading the Output

If you set verbose: true, each reasoning step is printed to stdout. Look for the [THINK] blocks — this is the raw inner monologue of the agent, and it’s the best way to understand why it makes each decision.

7. Giving Your Agent Tools

Tools are what transform an agent from a text generator into something that can do things. OpenClaw ships with a set of built-in tools you can enable instantly.

Built-in Tools

  • web_search: Search the web via SerpAPI, Brave, or DuckDuckGo. Returns titles, URLs, and snippets. Requires API key.
  • file_reader: Read text files, PDFs, or CSVs from your local filesystem. No key needed.
  • file_writer: Write or append to files. Useful for saving results, logs, or notes. No key needed.
  • calculator: evalsuate mathematical expressions safely. Avoids LLM arithmetic errors. No key needed.
  • http_get: Fetch the contents of any public URL. Useful for reading documentation or APIs. No key needed.
  • python_exec: Execute Python code in a sandbox. Powerful — use with caution. Sandboxed.

Writing a Custom Tool

Any Python function can become an agent tool with a single decorator:

    
     from openclaw import tool

@tool(
    name="get_weather",
    description="Get the current weather for a given city."
)
def get_weather(city: str) -> str:
    # Your implementation here
    response = requests.get(f"https://wttr.in/{city}?format=3")
    return response.text
    
   

Then reference it by name in your agent.yaml under tools, and OpenClaw will make it available to the agent automatically.

8. Configuring Memory

Memory is what separates a one-shot script from a true agent that improves over time. OpenClaw supports two memory backends out of the box.

Short-Term Memory

Enabled by default. The agent keeps the full history of the current run in its context window. When the run ends, this memory is cleared. It’s perfect for multi-step tasks within a single session.

Long-Term Memory with ChromaDB

Install the extra dependency and update your config:

    
     pip install openclaw[chroma]
    
   
    
     memory:
  short_term: true
  long_term:
    backend: chroma
    path: ./agent_memory
    top_k: 5   # retrieve 5 most relevant memories per query
    
   

With long-term memory enabled, the agent will store key facts and past task outcomes as embeddings. On future runs, it retrieves the most relevant memories and includes them in its reasoning context. Over time, your agent becomes more effective at tasks it has done before.

✅ When to Use Each

Use short-term only for one-off tasks and experimentation. Enable long-term memory when you’re building a recurring assistant that should accumulate domain knowledge over weeks and months.

9. Running & Monitoring Your Agent

Useful CLI Flags

    
     # Run with verbose reasoning shown
openclaw run agent.yaml --task "..." --verbose

# Dry run — plan only, no tool execution
openclaw run agent.yaml --task "..." --dry-run

# Set a token budget to control cost
openclaw run agent.yaml --task "..." --max-tokens 8000

# Save full trace to a log file
openclaw run agent.yaml --task "..." --log-file run.log
    
   

Setting Guardrails

It’s important to constrain what your agent is allowed to do, especially when it can write files or make HTTP requests. Add a safety block to your config:

    
     safety:
  max_iterations: 20
  allowed_file_paths:
    - ./workspace/
  blocked_domains:
    - internal.company.com
  require_approval: false   # set true to confirm each action
    
   

Debugging Common Errors

  • Max iterations reached — increase max_iterations or simplify the task.
  • Tool call failed — check API keys in .env and review the tool’s error log.
  • Context window exceeded — reduce top_k memory retrievals or enable summarization.
  • Agent loops infinitely — add a clearer goal statement; vague tasks cause infinite re-planning.

10. Practical Example: A Personal Research Assistant

Let’s put everything together and build the agent described at the start of this guide — one that searches the web and saves structured research notes to your filesystem.

Full Configuration

    
     name: ResearchAssistant
description: Searches the web and produces structured Markdown research notes.

model:
  provider: openai
  name: gpt-4o
  temperature: 0.2

system_prompt: |
  You are a rigorous research assistant. When given a topic:
  1. Search for 3-5 authoritative sources.
  2. Read each source carefully.
  3. Write a structured Markdown report: Summary, Key Findings, and Sources.
  4. Save the report to ./workspace/{topic}.md

tools:
  - web_search
  - http_get
  - file_writer

memory:
  short_term: true
  long_term:
    backend: chroma
    path: ./memory

safety:
  max_iterations: 25
  allowed_file_paths:
    - ./workspace/
    
   

Running End-to-End

    
     mkdir -p workspace
openclaw run agent.yaml \
  --task "Research the current state of quantum error correction" \
  --verbose
    
   

Watch the agent search for papers, fetch article content, synthesize findings, and write a clean Markdown file to ./workspace/quantum_error_correction.md. The whole process takes about 60–90 seconds with GPT-4o.

🔍 Refinement Tips

If the output isn’t what you wanted, the fastest fix is almost always to improve the system_prompt. Be explicit: specify output format, word count, and what to do when sources are paywalled.

11. Next Steps & Advanced Topics

You’ve got a working agent. Here’s where to go next.

  • Multi-agent workflows — OpenClaw supports orchestrator/worker patterns where one agent delegates subtasks to specialized sub-agents. See the MultiAgent class in the docs.
  • Scheduling — Pair OpenClaw with cron (Linux/macOS) or Task Scheduler (Windows) to run your agent on a recurring schedule. Morning briefings, weekly summaries, and monitoring bots are all fair game.
  • Plugins — The OpenClaw plugin registry hosts community-built tools for Notion, Gmail, GitHub, Slack, and more. Install any with openclaw plugin install <name>.
  • Local models — Replace OpenAI with Ollama to run Mistral, Gemma, or LLaMA 3 entirely offline. Set provider: ollama in your config.
  • evalsuations — Use openclaw evals to run your agent against benchmark tasks and measure accuracy, cost per run, and iteration counts.

Community & Resources

Kaif

Share
Published by
Kaif
2 weeks ago

Recent Posts

Is WordPress 6.9 a Game Changer? Here’s a Look

1. Introduction WordPress 6.9, codenamed "Gene," is the final major release of 2025 and one…

7 days ago

Docker vs Kubernetes: Containerization Showdown

1. Introduction to Containerization 1.1 What Is Containerization and Why It Matters Modern software development…

1 week ago

How to Set Up n8n? A Step-by-Step Guide for Self-Hosted Workflow Automation

1. Introduction If you've ever wanted to automate repetitive tasks — like syncing data between…

3 weeks ago

Top Survival Games Perfect for Dedicated Server Hosting

Introduction Survival games have become one of the most enduring and beloved genres in modern…

1 month ago

Containerize and Deploy Node.js Applications With VPS Malaysia

1. What is Node.js? Node.js lets you use JavaScript to build the "brain" of a…

1 month ago

NVMe vs M.2: What’s the Difference and Which One Do You Need?

1. Introduction If you have ever shopped for a new SSD or tried to upgrade…

1 month ago