System messages สำหรับควบคุมพฤติกรรม

Claude Models เบื้องต้น

Nikhil Rangarajan

Data Scientist

System messages คืออะไร?

  • บอต Support
  • ข้อกำหนด:
    • สุภาพ
    • กระชับ
    • ลงท้ายทุกคำตอบด้วย "Is there anything else I can help you with today?"

บอต

Claude Models เบื้องต้น

System messages คืออะไร?

  • System messages กำหนดกฎพฤติกรรมโดยรวมให้ Claude
  • ใช้กับทั้งการสนทนา ไม่ใช่แค่การตอบครั้งเดียว
  • ควบคุมโทน ข้อจำกัด รูปแบบผลลัพธ์ และบทบาท

บอตถามว่า "Is there anything else I can help you with today?"

Claude Models เบื้องต้น

การเขียน system prompt ที่มีประสิทธิภาพ

  • ระบุพฤติกรรมและข้อจำกัดให้ชัดเจน
  • กำหนดบทบาทที่ต้องการให้ Claude รับ
system_msg = "Be helpful." # Weak

system_msg = "You are a technical writer. Use active voice, under 100 words, actionable advice only." # Strong
messages = [{"role": "user", "content": "How do I improve documentation?"}] response = client.messages.create(model="claude-sonnet-4-6", max_tokens=150, system=system_msg, messages=messages)
Claude Models เบื้องต้น

รูปแบบ system message ที่พบบ่อย

  • แบบกำหนดบทบาท: ระบุว่า Claude ควรเป็นใคร

$$

  • แบบกำหนดข้อจำกัด: กำหนดความยาวหรือรูปแบบ

$$

  • แบบกำหนดโทน: ควบคุมสไตล์การสื่อสาร

$$

  • แบบเฉพาะงาน: ให้คำแนะนำสำหรับงานนั้น ๆ
# Role-based
"You are a customer service rep."

# Constraint-based  
"Respond in exactly 3 bullet points,
max 50 words."

# Tone-based
"Use enthusiastic, encouraging tone."

# Task-specific
"Debug Python code. Always ask for 
error messages first."
Claude Models เบื้องต้น

การทดสอบและปรับปรุง system messages

  • ทดสอบด้วย input หลากหลายเพื่อค้นหา edge case
  • ติดตามผลลัพธ์ที่ไม่ต้องการหรือพฤติกรรมที่เปลี่ยนไป
  • ปรับภาษาให้ชัดเจนขึ้นเมื่อจำเป็น
# System message causing issues
"Be concise and helpful."

# Problem: Responses too short, 
# missing context
"Provide helpful responses in 2-3 
sentences. Include relevant context 
but avoid unnecessary details."

# Test with various prompts 
Claude Models เบื้องต้น

เทคนิค system message ขั้นสูง

$$

  • รวมคำสั่งพร้อมลำดับความสำคัญที่ชัดเจน
  • ใช้ logic แบบเงื่อนไขสำหรับสถานการณ์ต่าง ๆ
  • ใส่ตัวอย่างไว้ใน system message
  • ใช้ร่วมกับ few-shot prompting
system_msg = """Code reviewer. 
Priority: 1) Security 2) Performance 
3) Style
If no issues: "Code looks good" 
+ suggest improvement
Example: "Security: No issues. 
Performance: Consider caching here."
"""

messages = [{"role": "system", 
             "content": system_msg},
    {"role": "user", 
     "content": "Review: [code]"}]
Claude Models เบื้องต้น

มาฝึกกันเถอะ!

Claude Models เบื้องต้น

Preparing Video For Download...