How to Write a System Prompt for an AI Agent
Learn to craft effective system prompts for AI agents: structure, tone, constraints, examples, and common pitfalls.

How to Write a System Prompt for an AI Agent
System prompts are the hidden instructions that shape how an AI agent behaves. Unlike a one-off user query, a system prompt sets the stage for every interaction, defining the agent's role, goals, tone, and boundaries. Whether you're building a customer support bot, a coding assistant, or a creative tool, mastering system prompts is essential.
This guide walks you through the core principles, a practical framework, and common mistakes to avoid. You'll also find real examples and links to further resources.
What Is a System Prompt?
A system prompt is the initial instruction given to a language model before any user input. It tells the model who it is (e.g., "You are a helpful legal assistant"), what it should do, and how it should behave. It persists across the conversation, acting as a persistent memory of the agent's purpose.
Think of it as the agent's job description and code of conduct rolled into one. A well-written system prompt can transform a generic model into a specialized tool.
Why System Prompts Matter for AI Agents
AI agents are more than simple chatbots. They can use tools, call APIs, and perform multi-step tasks. A system prompt is crucial because it:
For example, an agent that books flights needs a system prompt that specifies the airline policies, user preferences, and how to handle cancellations. Without it, the agent might invent rules or ignore constraints.
Key Principles of Effective System Prompts
1. Be Specific and Concrete
Vague instructions lead to vague outputs. Instead of "be helpful," say "provide step-by-step instructions for troubleshooting common issues." The more specific you are, the better the model can follow.
Example:
2. Define the Role and Persona
Give the agent a clear identity. This influences vocabulary, tone, and even the type of responses it generates. For instance, a "friendly librarian" will answer differently than a "stern data analyst."
You can draw inspiration from existing system prompts, like the Transformation Architect system prompt in Naval Ravikant's voice, which shows how a persona shapes the entire interaction.
3. Set Boundaries and Constraints
Tell the agent what it cannot do. This is critical for safety and reliability. For example:
Constraints also include format requirements, like "respond in JSON" or "use bullet points."
4. Provide Examples (Few-Shot Learning)
Including examples in the system prompt can dramatically improve output quality. Show the model what a good response looks like. This is especially useful for tasks with specific formats or styles.
Example snippet:
User: What's the weather in Tokyo?
Assistant: The current weather in Tokyo is 22°C, sunny, with a gentle breeze. Expect a high of 25°C and a low of 18°C. Bring a light jacket for the evening.
5. Use Clear Structure and Formatting
Organize your system prompt with sections, bullet points, or numbered lists. This makes it easier for the model to parse and follow. You can also use delimiters like ### to separate instructions from context.
6. Iterate and Test
System prompts are not set-and-forget. You must test them with various inputs and refine based on results. Pay attention to edge cases and adjust accordingly. This is a core part of prompt engineering, as highlighted in the OpenAI prompt engineering guide.
A Step-by-Step Framework for Writing a System Prompt
Here's a practical framework you can adapt:
Let's flesh out an example for a customer support agent:
You are a customer support assistant for TechGadgets Inc.
Your goal is to resolve user issues quickly and politely.
You have access to our FAQ database and order system.
Rules:
Tone: Friendly, empathetic, and concise.
Example:
User: My laptop won't turn on.
Assistant: I'm sorry to hear that. Let's troubleshoot. First, try holding the power button for 10 seconds. If that doesn't work, is the charger connected?
This framework is versatile. For creative tasks, you can adapt it similarly. For instance, the Red Veil Register System Prompt for Image Generation shows how to constrain an image generator with a specific aesthetic.
Common Mistakes to Avoid
1. Being Too Vague
Avoid generic phrases like "be helpful" or "answer questions." They don't give the model enough direction.
2. Overloading with Information
Too much context can confuse the model. Stick to what's essential. If you need more, consider using retrieval-augmented generation (RAG) instead of stuffing everything into the prompt.
3. Ignoring Safety and Bias
System prompts should explicitly address safety. For example, "Do not generate hate speech" or "Avoid stereotypes." This is especially important for public-facing agents.
4. Not Testing Edge Cases
Your agent will encounter weird inputs. Test with typos, ambiguous phrasing, and out-of-scope questions to see how it responds.
5. Forgetting to Update
As your product evolves, your system prompt should too. Version control your prompts and review them regularly.
Advanced Tips for Agent-Specific Prompts
AI agents often have access to tools and external data. Your system prompt should account for that:
For example, a coding agent might have a system prompt like:
You are a Python coding assistant. You have access to a code interpreter. When asked to write code, first explain your approach, then write the code, and finally test it by running it. If the code has errors, debug and retry.
This is more effective than a generic "help with code" prompt.
Real-World Examples and Inspiration
Looking at existing system prompts can spark ideas. Here are a few from our wiki:
These illustrate how system prompts can be tailored for specific domains.
Further Reading and Resources
To deepen your understanding, check out these authoritative guides:
These resources offer deeper dives into specific techniques like chain-of-thought, few-shot learning, and evaluation.
Checklist for Your Next System Prompt
Before you finalize, run through this checklist:
Conclusion
Writing a system prompt is both an art and a science. It requires clarity, specificity, and continuous iteration. By following the principles and framework above, you can create system prompts that make your AI agent reliable, useful, and safe.
Remember, the best system prompts are invisible - they guide the agent so effectively that users never notice the instructions behind the scenes. Start simple, test often, and refine based on real interactions.
For more inspiration, browse our system prompt collection or explore productivity-related prompts. Happy prompting!
Related Articles
- The Best Wan 2.1 Prompts: Open-Source AI Video That Works
Sep 3, 2026 · 7 min read
- Les Meilleurs Prompts Wan 2.1 : Vidéo IA Open-Source Qui Fonctionne
Sep 3, 2026 · 7 min read
- 最佳的Wan 2.1提示词:开源的AI视频,真的能用
Sep 3, 2026 · 7 min read
- As Melhores Prompts do Wan 2.1: Vídeo de IA Open-Source Que Funciona
Sep 3, 2026 · 7 min read
- Las Mejores Instrucciones para Wan 2.1: Video IA de Código Abierto Que Funciona
Sep 3, 2026 · 7 min read