Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How OpenClaw Works  ›  Lesson

The Agent Loop and Skills

Agent Loop 14 minA message starts a loop: the model is called, any tool it asks for is run and the result fed back, and the loop repeats until the model answers without asking for a tool, with skills adding instructions to the prompt.

The Agent Loop and Skills

Ask a plain chatbot "which are the three biggest files in my Downloads folder?" and it can only guess. An OpenClaw agent can go and look, because a message does not trigger one model reply. It starts a loop.

The rule

Think, act, observe — repeat until the model stops asking for tools.

When a message reaches an agent, the loop goes through these stages:

  1. Validate the incoming message.
  2. Resolve the model: which provider and model this agent uses.
  3. Assemble the system prompt from the agent's skills and context files.
  4. Call the model with that prompt, the conversation so far and the new message.
  5. If the model asks for a tool (run a command, read a file, search the web), the loop runs it and feeds the result back, then returns to stage 4.
  6. When the model answers without asking for a tool, that answer is the final reply, streamed back to the chat.

If the conversation has grown too long for the model to take in, OpenClaw compacts it automatically and tries again. The next lesson covers that.

Skills come in at stage 3. A skill is a folder containing a SKILL.md file, in the AgentSkills format, whose text is injected into the system prompt. It gives the agent context, limits and step-by-step guidance for a tool or a workflow. Skills can sit in the workspace's skills/ folder, in shared folders, or inside plugins.

---
name: tidy-downloads
description: Archive old files in Downloads when the user asks for a clean-up.
---

1. Only touch files older than 30 days.
2. Move them into `Downloads/archive/`. Never delete anything.
3. Reply with how many files moved and the five largest.

A skill is instructions, not code. It teaches the agent to use tools it already has, in the way you want.

The shortcut

Count the laps. Each tool call adds one lap: model, then tool, then model again. The loop ends on the first lap where the model replies without asking for anything.

The three biggest files in DownloadsStep 1 of 4
  1. Lap 1: the model asks for a tool

    The prompt, including any matching skill, goes to the model. It replies: "run a command that lists Downloads by size."

The trap is believing the model runs commands. The model only asks; the loop does the running. That is why tool permissions, such as per-agent allow and deny lists, are set in OpenClaw rather than in the model.

Drills

Answer fast — trust the rule.

quick drill

When does the agent loop stop?

quick drill

At which stage do skills shape the loop?

quick drill

What is a skill?

quick drill

The model asks to read a file. Who actually reads it?

quick drill

A task needs three tool calls, each depending on the result of the one before. How many model calls does the loop make?

Remember

  • Think, act, observe — repeat until the model stops asking for tools.
  • Count laps: each tool call adds a model call, and the last lap asks for nothing.
  • Skills are markdown instructions in the system prompt; the model asks, the loop runs.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainInside one request

Walk through what OpenClaw's agent loop does between receiving the message 'How much free disk space is left?' and sending the answer. Say where skills come in.