> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/en/build/agent/system-prompt.md).

# Role Instruction Design Guide

A guide to designing system prompts, covering four pillars, practical templates, advanced techniques, length control, and common questions to create a consistent, controllable AI customer service pers

{% hint style="info" %}
Use MaiAgent's [AI tool for generating system prompts](https://chat.maiagent.ai/web-chats/4b67b140-db5f-40dc-bce3-f2217e9574bd) to help refine your system prompt
{% endhint %}

## 🎭 What is a "system prompt"? <a href="#what-is-system-prompt" id="what-is-system-prompt"></a>

Imagine directing a movie: you need to tell the actors what roles to play, what personalities they have, and how they should speak. A **system prompt** is like a "script" for AI, telling it what kind of customer service representative to play.

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-37ae97af9a95ef0fa6cfe0ee8986844fc0ba233a%2F636b6ac8-d482-4a72-99ce-c3764441c2e9.jpg?alt=media" alt=""><figcaption></figcaption></figure>

### 📚 Technical glossary <a href="#technical-glossary" id="technical-glossary"></a>

Before we begin, let's get to know a few important concepts:

**🤖 AI Agent**

* **Analogy**: a virtual employee you hire
* **Description**: an AI system that can carry out tasks autonomously; in customer service, it acts as your digital service representative

**💬 Prompt**

* **Analogy**: a "job description" for AI
* **Description**: instructions that tell AI what to do and how to do it

**🎯 Context**

* **Analogy**: the "memory" and "background information" of a conversation
* **Description**: relevant information AI needs to understand the current conversation

**🔄 Token**

* **Analogy**: a "unit" AI uses to understand text, like breaking sentences into small pieces
* **Description**: the basic unit of text processing for AI, affecting processing efficiency and cost

***

## 🌟 Why are system prompts so important? <a href="#why-system-prompt-matters" id="why-system-prompt-matters"></a>

#### AI customer service without a system prompt 😵 <a href="#ai-agent-without-system-prompt" id="ai-agent-without-system-prompt"></a>

```
User: "Why hasn't my order arrived yet?"
AI: "According to the system data, your order status is processing."
```

*It feels like talking to a robot: cold and impersonal*

#### AI customer service with a good system prompt 😊 <a href="#ai-agent-with-good-system-prompt" id="ai-agent-with-good-system-prompt"></a>

```
User: "Why hasn't my order arrived yet?"
AI: "I completely understand your concern! Let me check your order status right away.
     According to the tracking information, your package is currently at the distribution center
     and is expected to arrive tomorrow afternoon. Would you like the tracking number?"
```

*It feels like talking to a real customer service representative: warm and professional*

***

## 🏗️ The four pillars of a system prompt <a href="#four-pillars-of-system-prompt" id="four-pillars-of-system-prompt"></a>

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-ede1fe891c61968c4a59f762a85401ab7a5661e8%2F7c0349c3-94f0-4644-ba55-c7313a35dad2%20(1)%20(1).jpg?alt=media" alt=""><figcaption></figcaption></figure>

#### 1. 🎭 Identity (Who) <a href="#identity-positioning" id="identity-positioning"></a>

Tell AI "who you are"

**❌ Vague identity**

```
You are a customer service representative
```

**✅ Clear identity**

```
You are "Xiaomei," a senior customer service representative at MaiAgent,
with 5 years of customer service experience, specializing in product inquiries and problem solving.
```

#### 2. 🗣️ Tone and style (How) <a href="#tone-and-style" id="tone-and-style"></a>

Tell AI "how to speak"

**Guide to choosing a tone:**

* **Professional and formal**: suitable for finance, law, and healthcare
* **Friendly and approachable**: suitable for retail, dining, and everyday services
* **Lively and youthful**: suitable for gaming, entertainment, and fashion
* **Warm and caring**: suitable for education, health, and social services

**Example: a friendly and approachable style**

```
Respond in a warm, friendly tone.
Use respectful forms of address where appropriate.
You may include friendly phrases such as "Happy to help,"
but avoid being overly enthusiastic or using too many exclamation marks.
```

#### 3. 🎯 Professional capabilities (What) <a href="#professional-capabilities" id="professional-capabilities"></a>

Tell AI "what you can do"

```
Your professional capabilities include:
- Explaining product features and providing usage guidance
- Looking up orders and tracking shipments
- Explaining return and exchange policies
- Performing initial technical troubleshooting
- Handling account and payment issues

When a question is beyond your capabilities,
proactively refer the customer to a human agent.
```

#### 4. 📋 Behavioral rules (Rules) <a href="#behavioral-rules" id="behavioral-rules"></a>

Tell AI "what you can and cannot do"

```
Principles you must follow:
✅ Protect user privacy and do not disclose personal information
✅ Admit when you do not know something; do not fabricate answers
✅ Stay calm when handling complaints; apologize first, then resolve the issue
✅ Keep responses concise and within 100 characters

Strictly prohibited:
❌ Making promises you cannot keep
❌ Arguing with or contradicting users
❌ Disclosing internal company information
❌ Processing refund requests beyond your authority
```

***

## 🛠️ Practice: design your first system prompt <a href="#design-your-first-system-prompt" id="design-your-first-system-prompt"></a>

#### Step 1: Analyze your business requirements <a href="#step-1-analyze-business-requirements" id="step-1-analyze-business-requirements"></a>

**Consider these questions:**

* Who are your customers? (Age, occupation, usage habits)
* What makes your products/services distinctive?
* What questions do customers ask most often?
* What kind of service experience do you want to give customers?

#### Step 2: Choose a suitable persona <a href="#step-2-choose-role-configuration" id="step-2-choose-role-configuration"></a>

**🏪 E-commerce customer service example**

```
You are "Shopping Assistant," a professional online shopping advisor.
You are familiar with all product information, excel at recommending suitable products,
and can quickly handle order-related issues.
Speak in a friendly, natural way, caring about customer needs as a friend would.
```

**🏥 Healthcare customer service example**

```
You are "Health Helper," a professional healthcare service advisor.
You have basic medical knowledge and can provide information on appointment booking and examination procedures,
but never provide medical diagnoses.
Speak in a professional, warm tone that puts patients at ease.
```

#### Step 3: Write a complete system prompt <a href="#step-3-write-complete-system-prompt" id="step-3-write-complete-system-prompt"></a>

**📝 System prompt template**

```
# Role identity
You are [Role Name], a [Position] at [Company Name].
[Role background and professional experience]

# Service objectives
Your main task is [Core Task],
helping customers [Achieve Goal] through [Service Method].

# Language style
- Tone: [Choose a suitable tone]
- Wording: [Specific wording requirements]
- Length: [Response length limit]

# Professional capabilities
You can handle the following issues:
- [Capability 1]
- [Capability 2]
- [Capability 3]

# Behavioral rules
Must follow:
✅ [Rule 1]
✅ [Rule 2]

Strictly prohibited:
❌ [Prohibition 1]
❌ [Prohibition 2]

# Handling special situations
When [Special Situation] occurs, please [Handling Method].
```

***

## 🎨 Advanced techniques: make your system prompt more vivid <a href="#advanced-tips-for-vivid-system-prompt" id="advanced-tips-for-vivid-system-prompt"></a>

#### 1. 🎪 Add personality traits <a href="#add-personality-traits" id="add-personality-traits"></a>

**Basic version:**

```
You are a customer service representative responsible for answering questions.
```

**Vivid version:**

```
You are "Xiaozhi," a tech enthusiast full of curiosity.
You are always excited about new features and enjoy using simple analogies
to explain complex technical concepts so everyone can understand them easily.
```

#### 2. 🎯 Contextual instructions <a href="#contextual-instructions" id="contextual-instructions"></a>

Adjust responses to different situations:

```
# Context-aware instructions
- When a customer expresses dissatisfaction: respond with empathy first, then provide a solution
- When a customer asks a technical question: explain using everyday analogies
- When a customer hesitates to purchase: provide objective advice without pressure to buy
- When a customer praises a product: express thanks and ask whether they need further assistance
```

#### 3. 🔄 Dynamic adjustment mechanism <a href="#dynamic-adjustment-mechanism" id="dynamic-adjustment-mechanism"></a>

```
# Conversation adaptability
Adjust your style based on the customer's responses:
- If the customer uses formal language, respond with a similarly formal tone
- If the customer is impatient, be more concise and efficient
- If the customer is talkative, you can expand the conversation a little
```

#### **4. Version control friendly** <a href="#ban-ben-kong-zhi-you-hao" id="ban-ben-kong-zhi-you-hao"></a>

* Include a version number and changelog
* Maintain backward compatibility so existing workflows continue to work after a system prompt update

Example:

```
Version: v1.0
# Updated: October 26, 2024
# Changelog:
#   - Initial version with basic product recommendation functionality.
#   - Recommend products based on user preferences.
#   - Set the response tone to friendly and professional.
```

MaiAgent also automatically saves every version of your system prompt. Use "<mark style="color:blue;">Edit History</mark>" on the Agent settings page to apply an older version or view conversations from the period when that version was active. See [System Prompt Edit History](/maiagent-user-guide/en/build/agent/add-system-prompt.md#instruction-edit-history).

***

## 🚀 Test and optimize your system prompt <a href="#test-and-optimize-system-prompt" id="test-and-optimize-system-prompt"></a>

#### Phase 1: Basic testing <a href="#phase-1-basic-testing" id="phase-1-basic-testing"></a>

Use common questions to test whether the AI's responses meet expectations

**Example test questions:**

* "What is your return policy?"
* "When will my order arrive?"
* "Is this product suitable for me?"

#### Phase 2: Boundary testing <a href="#phase-2-boundary-testing" id="phase-2-boundary-testing"></a>

Test how AI performs in extreme situations

**Example edge cases:**

* When a customer is upset
* When it encounters a question it cannot answer
* When asked to do something beyond its authority

#### Phase 3: Continuous optimization <a href="#phase-3-continuous-optimization" id="phase-3-continuous-optimization"></a>

**📊 Collect data**

* Customer satisfaction scores
* Issue resolution rate
* Rate of handoffs to human agents

**🔧 Adjust strategies**

* Expand the knowledge base based on common questions
* Adjust the language style based on customer feedback
* Refine behavioral rules based on failed cases

***

## **📝 System Prompt length control tips** <a href="#system-prompt-length-control-tips" id="system-prompt-length-control-tips"></a>

**Best practice guidelines**

The ideal System Prompt length is 500–2000 characters (about 200–800 tokens), with 800–1500 characters often being the sweet spot.

Keep one core principle in mind: "Clarity beats verbosity." Overly long instructions are easily overlooked by the model, while overly short ones can lead to inconsistent behavior.

**Why does length matter?**

First, consider model performance: an overly long prompt divides the model's attention and affects how well it follows key instructions. Second, consider context space limits: the system prompt occupies part of the conversation's context window, leaving less room for user conversations. Finally, consider maintenance costs: concise, structured prompts are easier to optimize and refine over time.

**Three writing techniques**

Structured design: divide the prompt into clear sections and put core instructions first.

Keep it concise: remove repeated descriptions and lengthy background information, retaining only necessary rules.

Continuous validation: run A/B tests with different models (GPT, Claude, Gemini) to find the best length configuration.

**Practical considerations**

Different AI models tolerate long prompts differently, so test and validate each one separately. For token counting, approximately 1 Chinese character equals 1 token, while 1 English token equals about 0.75 words. Since the system prompt carries greater instructional weight, keep its content focused and avoid unnecessary verbosity.

***

## 💡 Common questions and solutions <a href="#common-issues-and-solutions" id="common-issues-and-solutions"></a>

#### Q1: How can I make AI responses more natural? <a href="#q1-how-to-make-ai-responses-more-natural" id="q1-how-to-make-ai-responses-more-natural"></a>

**A:** Include specific conversation examples in the system prompt and set clear language style guidelines.

#### Q2: What if AI keeps answering irrelevant questions? <a href="#q2-ai-answering-irrelevant-questions" id="q2-ai-answering-irrelevant-questions"></a>

**A:** Clearly define the service scope in the system prompt and teach AI how to identify and handle questions outside that scope.

#### Q3: How do I balance professionalism and approachability? <a href="#q3-balance-professionalism-and-approachability" id="q3-balance-professionalism-and-approachability"></a>

**A:** Adjust to your target audience. B2B customers prefer professionalism, while B2C customers prefer approachability. Design A/B tests to find the best balance.

***

## 🎉 Closing: build your own AI customer service representative <a href="#closing-build-your-custom-ai-agent" id="closing-build-your-custom-ai-agent"></a>

Designing a system prompt is like training a new employee: it takes patience and ongoing adjustments. Keep these key principles in mind:

1. **🎯 Clear identity**: tell AI exactly who it is
2. **🗣️ Consistent style**: maintain a consistent language style
3. **📋 Clear boundaries**: specify what it can and cannot do
4. **🔄 Continuous optimization**: keep improving based on real usage

Start designing your first system prompt today! Remember, the best system prompts are refined continuously through real-world use.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/en/build/agent/system-prompt.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
