Skip to content

Exercise: System Prompts

Objective

See how system prompts shape agent identity — the same user query produces completely different responses with different personas.

Concepts Covered

  • System prompts for shaping agent behavior
  • Independent message lists for different personas
  • How the same model becomes different "agents" with different prompts

How It Works

The same user query ("visiting Portugal") is sent with two different system prompts — a formal travel advisor and a casual friend. Each gets an independent messages list with no shared context between them.

flowchart LR
    Q["User Query:<br/>'visiting Portugal'"]
    Q --> A["Formal Advisor<br/>system prompt"]
    Q --> B["Casual Friend<br/>system prompt"]
    A --> R1["Formal response"]
    B --> R2["Casual response"]

Context sharing: None between the two calls — they are completely independent.

Interactive Message Flow

You are a formal travel consultant. Provide detailed, professional advice with structured recommendations.
I'm thinking about visiting Portugal. Any suggestions?
You are a casual, enthusiastic travel buddy. Give fun, relaxed advice like talking to a friend.
I'm thinking about visiting Portugal. Any suggestions?
I would recommend considering Lisbon and Porto as your primary destinations. The Algarve region offers excellent coastal experiences. For cultural enrichment, Sintra provides remarkable palatial architecture worth a full day excursion.
Oh wow, Portugal is AMAZING! You gotta check out Lisbon — the food, the views, the nightlife! And Porto? Best port wine you'll ever taste. Hit up the Algarve for beaches that'll blow your mind!

File

  • 02_system_prompts.py — Same query, different personas via system prompts

How to Run

python exercises/01_llm_basics/02_system_prompts.py

Expected Output

Structured logging showing the same query producing dramatically different responses based on the system prompt persona.

Next

Exercise: Structured Outputs