Home
Back to Overview

System Prompts & Agent Specialization

Transform a general LLM into a specialized agent

Learn how system prompts shape AI behavior and create specialized agents

What is a System Prompt?

A system prompt is a persistent instruction that shapes the AI's behavior for an entire conversation session. Think of it as giving the AI a job description.

Without System Prompt

"Hi, I'm an AI."
"What can I do for you?"

With System Prompt

"I'm a professional translator
with expertise in scientific
German. I follow strict quality
guidelines and output format."

How System Prompts Work

SYSTEM PROMPT Always Active
"You are a professional translator..."
"Follow these rules: preserve accuracy, use idiomatic language..."
Persists throughout the entire conversation
โ†“
USER MESSAGE
"Translate this text to German: 'Hello, how are you?'"
Processed with system prompt context
โ†“
AI RESPONSE Shaped by System Prompt
"Hallo, wie geht es dir?"
Follows system prompt guidelines (idiomatic, accurate, no explanations)

Context Window Structure

SYSTEM PROMPT (Fixed at top)
"You are a professional translator..."
User: "Translate this..."
AI: "Hallo, wie geht es dir?"
(More conversation continues here...)

The system prompt remains at the top and influences every subsequent interaction

Persistent

Stays active for the entire conversation session

Influential

Shapes every response the AI generates

Configurable

Define behavior, tone, and output format

Agent Specialization Pattern

๐Ÿง 
General Model
Knows many things
+
๐Ÿ“‹
System Prompt
Define role & rules
=
๐ŸŽฏ
Specialized Agent
Translation Agent

Anatomy of an Effective System Prompt

Flexible Building Blocks

These components are building blocks that you can mix and match as needed. Not all components are required for every system prompt. Choose the ones that fit your use case and combine them in any order that makes sense.

1

ROLE DEFINITION

Optional

"You are a [specific role]..."

Establishes the AI's identity and perspective

2

TASK DESCRIPTION

Optional

"Your goal is to..."

Clarifies what the AI should accomplish

3

BEHAVIORAL RULES

Optional

"Always do X, Never do Y..."

Defines how the AI should behave

4

OUTPUT FORMAT

Optional

"Format your response as..."

Specifies the structure of responses

5

CONSTRAINTS

Optional

"Do NOT include..."

Sets boundaries and restrictions

Example Combinations

Simple: Role + Task
"You are a translator. Translate text to German."
Complete: All Components
"You are a translator. Translate accurately. Use JSON format. No explanations."
Custom: Rules + Format
"Always be concise. Format as markdown. Never use emojis."
Minimal: Just Constraints
"Do not include any explanations or commentary."

Why Detailed System Prompts Matter

Minimal System Prompt

"Translate to German"
  • โŒ May add explanations
  • โŒ Inconsistent terminology
  • โŒ Mixed formality levels

Detailed System Prompt

"You are a professional translator...
- Rule 1: Preserve technical accuracy
- Rule 2: Use idiomatic German
DO NOT add any explanations"
  • โœ… Consistent quality
  • โœ… Correct terminology
  • โœ… Proper formatting

How This Relates to AI Agents

Agent Formula

System Prompt + LLM + Tools = Agent

An AI agent is more than just a language model. It combines a specialized identity (system prompt), processing power (LLM), and capabilities (tools) to create a complete autonomous system.

System Prompt

Agent's Identity

Defines who the agent is, what it does, and how it behaves. This is the "personality" and "job description" of your agent.

"You are a professional translator specializing in technical documentation..."

LLM (Language Model)

Agent's Brain

The processing engine that understands context, generates responses, and makes decisions. This is the "intelligence" that powers the agent.

Processes: User input + System prompt โ†’ Generates: Contextual responses

Tools

Agent's Hands Optional

Extends the agent's capabilities beyond text generation. Tools allow the agent to interact with the external world, access information, and perform actions.

๐ŸŒ Web Search
๐Ÿ”ข Calculator
๐Ÿ“ File Access
Examples: API calls, database queries, code execution, etc.

How They Work Together

1. System Prompt Sets Context

Defines the agent's role, behavior, and constraints

2. LLM Processes & Decides

Uses the system prompt to understand and generate appropriate responses

3. Tools Execute Actions

When needed, tools extend capabilities beyond text generation

System Prompt Design Patterns

Pattern 1: Role-Playing

"You are a [profession] with expertise in [domain]..."

Makes the model adopt that perspective

Pattern 2: Rule-Based

"Follow these rules: 1. Always... 2. Never..."

Explicit constraints lead to predictable behavior

Pattern 3: Output Formatting

"Format your response as: JSON, Markdown, etc."

Controls the structure of responses

Pattern 4: Contextual Awareness

"You remember: [facts] You know that: [knowledge]"

Primes the model with relevant information

๐Ÿ“ Prompt Template Library

Template 1: Role-Based Agent

"You are a [ROLE] with expertise in [DOMAIN].
Your goal is to [OBJECTIVE].
Always [BEHAVIOR], never [AVOID]."

Example: "You are a Python tutor with expertise in async programming..."

Template 2: Output Format Control

"You are a [ROLE].
Format your response as [FORMAT].
Include: [REQUIRED_ELEMENTS]
Do NOT include: [FORBIDDEN_ELEMENTS]."

Example: "Format your response as JSON with keys: title, summary, tags"

Template 3: Constraint-Based

"You are a [ROLE].
Rules:
1. [RULE_1]
2. [RULE_2]
3. [RULE_3]"

Example: "Rules: 1. Use technical terms, 2. No explanations, 3. Be concise"

๐Ÿงช Testing & Iterating on Prompts

Testing Strategy

  1. Start with a simple prompt
  2. Test with 3-5 different inputs
  3. Identify what's missing
  4. Add constraints/guidelines
  5. Test again and refine

Common Issues

  • โŒ Too verbose โ†’ Add "Be concise"
  • โŒ Wrong format โ†’ Specify format explicitly
  • โŒ Off-topic โ†’ Add "Stay focused on [TOPIC]"
  • โŒ Inconsistent โ†’ Add examples

Practical Applications

Domain Specialization

  • โ€ข Medical โ†’ "You are a medical professional..."
  • โ€ข Legal โ†’ "You are a legal expert..."
  • โ€ข Technical โ†’ "You are an engineer..."

Output Control

  • โ€ข JSON API โ†’ "Always respond in valid JSON"
  • โ€ข Markdown โ†’ "Format all responses as markdown"
  • โ€ข Code โ†’ "Only output executable code"

Evolution Path

1 Basic Prompting (intro.js)
2 System Prompts (translation.js) โ† You are here
3 System Prompts + Tools (simple-agent.js)
4 Multi-turn reasoning (react-agent.js)
5 Full Agent Systems

Key Takeaways

๐Ÿ’ก

System prompts are powerful: They fundamentally change how the model behaves

๐Ÿ“

Detailed is better: More specific instructions = more consistent results

๐Ÿ—๏ธ

Structure matters: Role + Rules + Format + Constraints

๐Ÿš€

No retraining needed: Same model, different behaviors

Next: Reasoning Agents