prompt-engineering
Crafting effective prompts for AI models to optimize outputs and performance.
What this skill does
## prompt-engineering
### Purpose
This skill enables OpenClaw to craft and optimize prompts for AI models, improving output quality, accuracy, and efficiency in tasks like text generation, classification, or code completion. It uses techniques such as chain-of-thought prompting and few-shot learning to fine-tune interactions with LLMs.
### When to Use
Use this skill when AI outputs are suboptimal, such as vague responses, hallucinations, or poor performance in NLP tasks. Apply it for model fine-tuning, debugging AI behavior, or integrating prompts into applications like chatbots or automated content generators.
### Key Capabilities
- Generate prompt templates with variables (e.g., `{input_text}`) for dynamic reuse.
- Optimize prompts using metrics like perplexity or response length via built-in analyzers.
- Support for popular models like GPT-4 or BERT through adapters.
- Iterative refinement: Automatically suggest variations based on feedback loops.
- Integration with embedding services for semantic similarity checks using the provided embedding hint.
### Usage Patterns
Always start with a base prompt and iterate: 1) Define the prompt structure, 2) Test with sample inputs, 3) Analyze outputs, 4) Refine using optimization flags. For CLI, chain commands like `openclaw prompt create` followed by `openclaw prompt test`. In code, wrap prompts in functions for modular reuse. Use JSON config files for complex setups, e.g., specify `"model": "gpt-4"` and `"temperature": 0.7`.
### Common Commands/API
Use the OpenClaw CLI for quick operations; authenticate via `$OPENCLAW_API_KEY` environment variable. For API, send requests to `https://api.openclaw.ai/v1/prompts` with JSON payloads.
- CLI Command: Create a prompt
`openclaw prompt create --name myPrompt --template "Summarize {text} in 50 words" --model gpt-4`
This generates a reusable prompt template.
- CLI Command: Test and optimize a prompt
`openclaw prompt test --prompt-id 123 --input "Long article text here" --optimize perplexity`
Runs the prompt and applies optimization based on the specified metric.
- API Endpoint: Create prompt (POST to /v1/prompts)
Headers: `Authorization: Bearer $OPENCLAW_API_KEY`
Body: `{"name": "myPrompt", "template": "Translate {text} to French", "model": "gpt-4"}`
Response includes a prompt ID for future references.
- Code Snippet: Basic prompt execution in Python
```python
import openclaw
client = openclaw.Client(api_key=os.environ['OPENCLAW_API_KEY'])
response = client.prompts.execute(prompt_id='123', input_data={'text': 'Hello world'})
```
### Integration Notes
Integrate this skill by loading prompts into other OpenClaw skills or external tools. For example, reference a prompt ID in a workflow config file like:
`{ "skill": "prompt-engineering", "prompt_id": "123", "dependencies": ["aimlops/data-processing"] }`
When combining with services like Hugging Face, use the embedding hint in queries, e.g., pass `"embedding_hint": "prompt engineering ai ml nlp optimization"` to match related vectors. Ensure API keys are set as env vars (e.g., `$HUGGINGFACE_API_KEY`) for cross-service calls. Always validate prompt outputs against schemas to prevent injection risks.
### Error Handling
Common errors include authentication failures (e.g., 401 Unauthorized: ensure `$OPENCLAW_API_KEY` is set and valid), invalid prompt structures (e.g., missing variables: use `openclaw prompt validate --id 123` to check), or model timeouts (e.g., rate limits: retry with exponential backoff). For API errors, parse the response JSON for codes like "error_code": "INVALID_TEMPLATE" and fix by editing the template string. In code, wrap calls in try-except blocks:
```python
try:
response = client.prompts.execute(...)
except openclaw.errors.AuthenticationError:
print("Set $OPENCLAW_API_KEY and retry")
```
### Concrete Usage Examples
1. **Text Summarization Prompt**: To summarize articles, create a prompt with: `openclaw prompt create --name summaryPrompt --template "Summarize the following text: {text} in under 100 words" --model gpt-4`. Then test: `openclaw prompt test --prompt-id <returned_id> --input "This is a long article about AI..."`. This yields a concise summary; iterate by adding `--optimize length` if outputs are too verbose.
2. **Code Generation Prompt**: For generating Python functions, use: `openclaw prompt create --name codePrompt --template "Write a Python function that {task_description}" --model gpt-4`. Execute with: `openclaw prompt test --prompt-id <id> --input "sorts a list of numbers"`. Refine by checking for syntax errors and re-running with variations like `--template "Write secure Python function that {task_description}"` to add safety.
### Graph Relationships
- Related to cluster: aimlops (e.g., shares dependencies with data-processing and model-training skills).
- Connected via tags: ai (links to general AI tools), ml (integrates with machine learning workflows), nlp (direct overlap for language tasks), prompts (core relation to prompt optimization skills).
- Embedding relationships: Uses embedding hint for semantic links, e.g., to nlp-processing skill for vector-based prompt enhancements.
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.