The difference between a mediocre OpenClaw agent and a great one is almost always the prompt. This tutorial distils the patterns we use daily into practical, copy-pasteable templates.
1. The anatomy of a great system prompt
A reliable system prompt has four parts:
- Role β who the agent is.
- Mission β what it should accomplish.
- Constraints β what it must not do.
- Output format β exactly what the response should look like.
You are a senior copy-editor. (role)
Mission: Tighten the user's draft into clear, concise prose
suitable for a B2B SaaS landing page. (mission)
Constraints:
- Do not invent facts.
- Preserve the user's voice; only remove redundancy. (constraints)
Output format:
- Return the revised text first.
- Then a 3-bullet list of the most important changes. (format)
2. Few-shot examples
When the format is tricky, show β don't tell. OpenClaw strongly generalises from in-context examples.
Convert the user's note into a SQL WHERE clause.
Example 1:
Input: "all orders from Germany last week that weren't shipped"
Output: country = 'DE' AND created_at > NOW() - INTERVAL '7 days' AND status != 'shipped'
Example 2:
Input: "premium customers in Tokyo with more than 3 orders"
Output: plan = 'premium' AND city = 'Tokyo' AND order_count > 3
Now convert this:
"subscribers in Brazil who cancelled in the last 30 days"
3. Chain-of-thought (CoT)
For multi-step reasoning, ask the model to "think before answering". With OpenClaw you can do this either via a single prompt:
instructions = """Solve the problem step by step.
First outline your plan, then execute it, then verify."""
β¦or via the built-in reasoning_effort parameter:
agent = Agent(name="math-tutor", model="openclaw-1", reasoning_effort="high")
4. Tool-calling discipline
Tools are powerful but easy to misuse. Two rules of thumb:
- Be explicit about when to call a tool. Vague prompts produce spurious tool calls.
- Validate the inputs. Even though the LLM is constrained, never trust its arguments blindly.
5. Defensive patterns
Three patterns we use in every production agent:
a) Self-check
instructions += "\n\nBefore returning, double-check that your answer
directly addresses the user's question. If not, revise."
b) Citation
instructions += "\n\nFor every factual claim, append the source URL in
square brackets, e.g. [https://β¦]. Never fabricate sources."
c) Refusal
instructions += "\n\nIf you don't know the answer, say 'I don't know'
rather than guessing."
6. Testing prompts
Use the openclaw.eval module to regression-test your prompts:
from openclaw.eval import EvalSuite
suite = EvalSuite(agent, dataset="support-tickets-v3.json")
report = suite.run()
print(report.pass_rate) # β 0.94
Run it in CI and alert on regressions. Prompt quality is code quality.
The OpenClaw team has published a full prompt library on GitHub β see the resources page for links.