StudyVisuallyStart studying
Part 01 · LLM basics · Card 7 of 10

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).

Last updated

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.tsTypeScript
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.