# Message roles

Each message has a role: system (the rules), user (the human), assistant (the model) and tool (results of a function your code ran).

AI developers · Part 01: LLM basics · Card 7 of 10 · Last updated 2026-10-13

## Analogy

Like headers on a request. Same body text, but the role tells the model who is talking and how much to trust it.

## Code example

`roles.ts`

```typescript
const messages = [
  { role: "system", content: "You are a terse tutor." },
  { role: "user", content: "Explain tokens." },
  { role: "assistant", content: "Chunks of text, ~4 chars each." },
];
```

## In an agent

An agent's history is a mix of all four roles. The tool role is how results get back to the model.

## Practice

### Flashcards

- **What is a system prompt?** Standing instructions that define the model's role, tone and rules.

## Questions people ask

### What are the system, user, assistant and tool roles?

System holds the rules for the whole conversation. User is what the person typed. Assistant is what the model replied, including any tool calls it asked for. Tool carries the result of a function your code ran. The role tells the model who is speaking and how much to trust that text.

### Why does an agent need the tool role?

The tool role is how results get back to the model. After your code runs a function the model asked for, you add a tool message with the result and the matching tool_call_id. Without it, the model cannot see what the tool returned, so it cannot use the result in its next step.

## Related concepts

- [System prompt](https://studyvisually.com/learn/tech/ai-developers/llm-basics/system-prompt)
- [LLM](https://studyvisually.com/learn/tech/ai-developers/llm-basics/llm)
- [Next-token prediction](https://studyvisually.com/learn/tech/ai-developers/llm-basics/next-token-prediction)
- [Who decides the next step](https://studyvisually.com/learn/tech/ai-developers/llm-basics/ai-levels)

Web page: https://studyvisually.com/learn/tech/ai-developers/llm-basics/message-roles
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=message-roles
