0Pricing
AI Agents · Lesson

System vs User vs Assistant Roles

Understand the three message roles in modern chat APIs and how they affect what the model trusts and obeys.

System vs User vs Assistant Roles is a free AI Agents lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Three Roles, One Conversation

Every chat API uses three message roles:

  • system — meta-instructions, persona, rules
  • user — input from the human or upstream
  • assistant — the model's output

Why Roles Exist

Models are trained to treat these roles differently. The system role gets the highest trust; user messages are the lowest.

This is how the model knows your instructions take priority over what an attacker types in user input.

The System Slot Is Yours

The system message is your contract with the model. Put here:

  • Identity and goal
  • Hard rules (never reveal X, always do Y)
  • Output format requirements
  • Tool usage policy

Keep System Stable, User Dynamic

The system message should rarely change inside a session. Anything that changes per turn belongs in user messages.

This pattern also unlocks prompt caching — see the Cost Optimisation course.

Example: A Customer-Support Agent

A typical setup:

messages = [
    {'role': 'system', 'content': '''
You are SupportBot, the customer-support agent for Acme Corp.
You help with order status, returns, and product info.
You never share internal pricing or roadmap info.
Answer in 2-3 sentences. Use the search_orders tool when asked about orders.
'''},
    {'role': 'user', 'content': 'Where is my order #1234?'},
]
for m in messages:
    print(f"[{m['role']}] {m['content'].strip()}")

Multiple System Messages

Most APIs only support one system message. If you need to layer instructions, concatenate them or use separate XML sections inside the system content.

Assistant Messages and Memory

Past assistant turns are part of context. The model sees its own past output and stays consistent.

This is why "yes, I will follow your rules" from the model in a previous turn nudges it to actually follow them.

Pre-filling Assistant Turn (Anthropic)

Anthropic allows you to start the assistant message with text the model will continue:

messages = [
    {'role': 'user', 'content': 'Return a JSON object with name and age.'},
    {'role': 'assistant', 'content': '{'}
]
# The model continues from '{', forcing JSON output.
for m in messages:
    print(f"{m['role']}: {m['content']}")
print("The model continues from '{', forcing JSON output.")

The Tool Role

Modern APIs add a fourth role: tool (OpenAI) or content blocks with tool_result (Anthropic).

You append a tool message after running a function the model requested.

Role-Mixing Mistakes

Common bugs:

  • Putting tool results in user messages — confuses the trust hierarchy
  • Forgetting to send tool_call_id — API errors
  • Two consecutive user or assistant messages — most APIs reject this

The Instruction Hierarchy

OpenAI publishes a model spec saying:

"In case of conflict, the model should follow the instruction higher in the hierarchy: platform > developer (system) > user > tool."

Anthropic has similar guidance. The system slot wins.

Role Slots

Where should a hard rule like "never expose internal pricing" go?

Recap

Three roles, three trust levels. Use system for rules, user for input, assistant for replays. Add tool messages after function calls.

Frequently asked questions

Is the “System vs User vs Assistant Roles” lesson free?

Yes — the full text of “System vs User vs Assistant Roles” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.

What will I learn in “System vs User vs Assistant Roles”?

Understand the three message roles in modern chat APIs and how they affect what the model trusts and obeys. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AI Agents?

No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “System vs User vs Assistant Roles” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AI Agents lesson?

Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Zero-shot, Few-shot and Chain-of-Thought
  2. System vs User vs Assistant Roles
  3. Output Formatting (JSON, XML, Markdown)
  4. Avoiding Prompt Injection in Inputs
← Back to AI Agents