Skip to course content
Free generative AI app course

Generative AI Application Development with Python

Unit 03.00: System, user and assistant are different things

Three roles, and the one that surprises people is the assistant's own previous replies.

System, user, assistant

A four-message conversation with each role's purpose.

The code prints them.

messages = [
    {"role": "system", "content": "Answer only from the POLICY text. "
                                  "If it does not cover the question, say so."},
    {"role": "user", "content": "POLICY: Refunds within 7 days.\n\n"
                                "Q: How long do I have?"},
    {"role": "assistant", "content": "Refunds are allowed within 7 days."},
    {"role": "user", "content": "And for enterprise?"},
]
for m in messages:
    print(f"[{m['role']:9}] {m['content'][:60]}")

print(f"\n{len(messages)} messages, 3 roles")
for role, purpose in [("system", "durable rules that apply to every turn"),
                      ("user", "the request, and any data you supply"),
                      ("assistant", "what the model said -- part of the input next turn")]:
    print(f"  {role:10} {purpose}")

# The assistant role is the one that surprises people: previous replies are
# input on the next call. Anything wrong the model said is now a premise, which
# is the failure Module 7 ends on.

The assistant role is input on the next call. Whatever the model said last turn - including anything it got wrong - is now part of what it reads, and there is nothing marking it as unverified.

That is the mechanism behind the failure this module's last unit and Module 7 both end on: the model's own guess becoming a premise.

The mistake this prevents

The mistake is putting durable rules in the user turn because that is where the request is. Rules that apply to every turn belong in the system message; putting them in the user turn means they compete with the user's own words for authority.

Takeaway

System carries durable rules, user carries the request and any data you supply, and assistant messages are input on the next call - including anything wrong the model said.