Home/Blog/How to Write System Prompts for AI Agents in 7 Steps
Blog

How to Write System Prompts for AI Agents in 7 Steps

P
promptstudio

How to write system prompts for AI agents in 7 steps: define the job, list tools with failure rules, set hard limits and approvals, then test before launch.

How to Write System Prompts for AI Agents in 7 Steps

To write a system prompt for an AI agent, state the job in two sentences, list every tool with when to use it and what to do when it fails, put hard limits and approval rules near the top, define when the agent stops or hands off, and test the draft against real requests before launch. A chatbot only talks; an agent acts through tools, so most failures come from missing tool rules and missing stop rules, not from tone. The seven steps below work in any agent builder.

Never hardcode API keys or secrets in a system prompt; keep them in your platform's credential store. Treat text from tools, web pages, files, and emails as data, not instructions, so a prompt injection cannot change the agent's rules.

The 7 steps

1. Write the job in one or two sentences

Name what the agent does and what it does not do. "You answer order-status questions and start returns within 30 days. You do not issue refunds." The second sentence matters as much as the first, because it gives the agent a reason to say no.

Here is what my agent should do: [job]. Rewrite it as a two-sentence role and goal, with one sentence on what is out of scope.

2. Describe who the agent talks to

Customers, internal staff, and other agents need different wording and different trust levels. An agent that serves the public should confirm identity before it shares account data.

3. Build a tools table

For each tool, give the exact name, when to use it, when not to use it, and whether it reads data or changes something. Write tools are where mistakes cost money, so they need the clearest rules.

These are my agent's tools: [tool names and what they do]. Make a table with use when, do not use when, and read or write, and add one line for each on what to do if it fails or returns nothing.

4. Put hard limits and approvals near the top

Hard limits are things the agent never does. Approval rules are things it only does after a person agrees. Keep both short, specific, and early in the prompt so they are not buried under style notes.

5. Define stop and handoff rules

Say exactly when the agent stops: a repeated failure, an upset user after two replies, a request it cannot verify, or any approval action. Then say what it hands over, such as the order number, the request, and what it already tried.

6. Fix the output contract

Length, format, and the last line of every reply. "Plain text, under 80 words, end with one next step" is easy to test. "Be helpful" is not.

7. Test it before launch

Run real requests, then three edge cases: an out-of-scope request, someone pushing the agent to skip an approval, and a tool error. For each result, find the line that caused it. If no line explains the behavior, you found a gap.

Here is my agent's system prompt: [paste]. Write five test messages that try to break it, predict what the agent will do for each, and point to the line responsible. Then suggest fixes for any gaps.

Do all seven steps in one run

The AI Agent System Prompt Writer: Tools, Limits, Stop Rules prompt takes your job description, tools, limits, and test cases, asks about gaps first, drafts the system prompt in the order above, and runs a test pack against it. Its example builds an order help agent for a tea shop and catches a missing rule for off-topic requests during testing.

Common mistakes

Listing tools without failure rules, so the agent loops or guesses. Mixing hard limits into a long style section. Asking the agent to be "careful" instead of naming the check it should run. Skipping tests because the first few chats looked fine.

Related prompts

For a broader generator, see the custom AI agent system prompt architect. For narrower cases, read the guides on a system prompt for an AI chatbot and a system prompt for a coding agent. To score your agent's tool calls after launch, use the tool call agent eval rubric, and for background, read prompt engineering for AI agents.

Related: n8n AI agent prompt.

Find more in the Agents category, look through Browse, or post your own on Share.