Prompt engineering for OpenClaw
OpenClaw's behavior is shaped by system and user prompts. Good prompt engineering in the US means clear role and scope, explicit tool-use instructions, examples where helpful, and guardrails so the agent stays on task and safe. This post covers prompt engineering for OpenClaw.
OpenClaw is a personal AI agent that uses an LLM to reason and choose tools. The prompts you send: system prompt, few-shot examples, and user message: define what the agent does and how it responds. This post explains how to engineer prompts for OpenClaw so US users get reliable, safe, and useful behavior.
Why prompts matter
The LLM has no built-in knowledge of "you" or "your inbox." It only knows what you put in the prompt and what tools return. So:
- Role and scope: tell the agent who it is (e.g., "personal assistant"), what it can do (list tools and boundaries), and what it must not do.
- Format and structure: how to use tools (when to call, what to pass), how to format answers, and when to ask the user instead of acting.
- Examples: for tricky or repeated patterns, one or two short examples (few-shot) can dramatically improve consistency.
Investing in prompt design reduces hallucinations and off-scope behavior and makes the agent easier to trust in the US.
System prompt structure
A typical system prompt for OpenClaw includes:
- Role: e.g., "You are a personal AI assistant running on the user's machine. You have access to their email, calendar, files, and other tools. You execute tasks on their behalf within the rules below."
- Allowed actions: list of tools/skills and when to use them. E.g., "You may read and triage email, add calendar events, and run approved file operations. You may not delete email, send to external recipients without confirmation, or run arbitrary shell commands unless explicitly requested and approved."
- Format: e.g., "Always use the tool API to perform actions. Respond to the user in short, clear sentences. If you're unsure, ask before acting."
- Guardrails: e.g., "Never include API keys, passwords, or PII in your responses. If the user asks for something outside your scope, say so and suggest what they can do instead."
- Optional: current context (time, timezone), user preferences (e.g., "user prefers morning briefings before 9am"), or recent memory summary.
Keep the system prompt within the model's context limit. If you have many tools, summarize and point to tool docs rather than inlining everything.
User prompt and context
- User message: the request (e.g., "Triage my inbox and move newsletters to the Newsletter folder"). Be clear and specific in testing; real users will be varied, so the system prompt should handle ambiguity (e.g., "if unclear, ask").
- Context injection: before the user message, you may inject: current time, unread count, next meeting, or a short memory summary. That makes the agent context-aware without pasting huge logs. See Context-aware automation strategies.
- Conversation history: if you keep multi-turn history, trim or summarize old turns so you don't blow the context window. Prefer summarizing older turns and keeping the last N full messages.
Tool use instructions
- Tool list: the model needs to know available tools, their names, and parameters. OpenClaw or your client usually sends this in the API (function/tool definitions). In the system prompt, add high-level guidance: "Use read_inbox to get messages; use move_to_folder to move a message. Prefer batching when the user asks to triage many items."
- When to call: e.g., "Call a tool for every action that changes state (send, move, create). Do not describe an action without calling the tool unless the user asked for a plan only."
- Errors: e.g., "If a tool returns an error, explain briefly and suggest a fix or ask the user. Do not retry indefinitely."
Clear tool instructions reduce "I'll do it" without actually calling the tool, and reduce invalid or redundant calls.
Few-shot examples
For workflows that are easy to get wrong, add 1–3 examples in the system prompt.
- Example: User: "File this email." Assistant: [calls get_message, then move_to_folder with the right folder based on sender]. Keep examples short and generic (no real PII). They teach format and decision logic.
- Where: triage rules ("newsletters go to Newsletter"), escalation ("if sender is unknown, put in Review"), or response style ("confirm in one line after acting").
Don't overdo it; long few-shot blocks use context and can confuse. Prefer clear rules plus one or two examples over many examples.
Guardrails in text
Reinforce in the prompt:
- No secrets: "Do not repeat or log API keys, passwords, or tokens."
- Scope: "Do not perform actions outside the allowed tool list. If the user asks, say it's not supported and suggest alternatives."
- Confirmation: "For destructive or high-impact actions (delete, send to external), confirm with the user first unless they explicitly said to proceed."
- US-specific: if relevant: "User is in the US; use US timezone and date format unless otherwise specified."
Guardrails in prompts are not enough by themselves: enforce in code (e.g., tool allowlists, confirmation flows). But prompts set the agent's default behavior.
Iteration and measurement
- Test: run common and edge-case requests; check that the agent uses the right tools and doesn't hallucinate or go off-scope. Adjust prompts and re-test.
- Log: log prompt length, tool calls, and outcomes (success, user correction). Over time you'll see which prompts lead to the best results. SingleAnalytics can help US teams track agent events and outcomes so you can tune prompts based on data.
Prompt engineering for OpenClaw: structure system prompts (role, scope, tools, guardrails), inject context and trim history, add few-shot where it helps, and reinforce safety in text. For US users, that builds a reliable and safe agent. When you want to measure how prompt changes affect behavior, SingleAnalytics gives you one platform for analytics.