Personalizing Your Tutor with System Prompts

Welcome to the next step in your journey of creating a personal tutor with DeepSeek! In the previous lessons, you learned how to send messages to DeepSeek's language model, explored model parameters, and understood the importance of maintaining tutoring session history. Now, we will focus on personalizing your AI tutor by using system prompts. System prompts allow you to define the tutor's personality and expertise, enabling you to customize the behavior and tone of the AI's responses. This lesson will guide you through creating a specialized math and science tutor, demonstrating how system prompts can shape the tutor's interactions.

Creating a System Prompt

A system prompt is a key tool for customizing the AI tutor's behavior, setting the stage for how it interacts with students. It acts as a directive that defines the tutor's personality and expertise, guiding its responses to align with a specific teaching style or subject focus. We call it a "system prompt" because it serves as an overarching instruction to the AI, distinct from user or assistant messages, which are part of the ongoing tutoring session. While user messages are inputs from the student interacting with the tutor, and assistant messages are the tutor's responses, the system prompt is a one-time setup that influences all subsequent interactions within a session.

The system prompt does not persist across multiple sessions; it is reset each time a new session begins. If you change the system prompt mid-session, the AI will immediately adopt the new personality and expertise as defined by the updated prompt. However, for consistency and to avoid confusion, it's generally recommended to set the system prompt at the beginning of a session and maintain it throughout. Let's see a practical example of setting system prompts:

from openai import OpenAI

# Initialize the OpenAI client
client = OpenAI()

# Define the tutor's personality and expertise
system_prompt = "You are an experienced and patient tutor specialized in math and science, providing clear and concise explanations."

# Structure the tutoring session with a system prompt and student query
session = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "Can you help me understand the concept of derivatives in calculus?"},
]

In this example, the system prompt is set first, establishing the AI as an experienced math and science tutor. This setup ensures that when the student asks a question, the AI responds in a manner consistent with its defined role. By placing the system prompt at the start, you create a cohesive and educational interaction, allowing the AI to maintain its teaching approach throughout the tutoring session.

Talking to Your Specialized Tutor

To illustrate how a system prompt shapes the AI tutor's behavior, let's interact with an AI that has the math and science tutor personality set in our system prompt.

# Function to send a query and receive an explanation
def send_query(messages):
    response = client.chat.completions.create(
        model="deepseek-ai/DeepSeek-V3",
        messages=messages,
        stream=False
    )
    return response.choices[0].message.content.strip()

# Request explanation from the personalized tutor
reply = send_query(session)

# Display the tutor's response
print("Tutor Response:", reply)

When we send this query to the AI tutor, it generates a response that reflects the experienced math and science tutor personality. The output might look something like this:

Tutor Response: Derivatives in calculus represent the rate of change of a function at a specific point. Think of it as finding the slope of the tangent line to a curve at any given point.

The derivative of a function f(x) is written as f'(x) or df/dx, and it tells us how quickly the output value changes as we slightly adjust the input value.

For example, if f(x) = x², then f'(x) = 2x. This means that at any point x, the rate of change is 2x. At x = 3, the derivative equals 6, indicating the function is increasing at a rate of 6 units per unit change in x at that point.

Would you like me to explain how to calculate derivatives using specific rules or provide more examples?

This educational response showcases how the system prompt shapes the tutor's interactions, allowing it to respond with clear, concise explanations focused on mathematical concepts — precisely what we defined in our system prompt.

Customizing Tutor Expertise

One of the powerful aspects of system prompts is that they can be tailored to create tutors with different specializations or teaching styles. Let's look at how we might create a tutor with a different focus:

# Define a different tutor specialization
history_tutor_prompt = "You are a passionate history tutor who specializes in making historical events engaging and memorable through storytelling and interesting facts."

# Structure a new tutoring session
history_session = [
    {"role": "system", "content": history_tutor_prompt},
    {"role": "user", "content": "Can you tell me about the Industrial Revolution?"}
]

# Get response from the history-focused tutor
history_reply = send_query(history_session)
print("History Tutor Response:", history_reply)

Running this code results in an an ouput similar to the following:

History Tutor Response: Absolutely! The **Industrial Revolution** was one of the most transformative periods in human history, marking the shift from agrarian, handcraft-based economies to industrialized, machine-driven production. It began in **Britain in the late 18th century** (around the 1760s) and later spread to Europe, North America, and the rest of the world.  

### **Key Features of the Industrial Revolution**  
1. **Technological Innovations**  
  - **Steam Engine** (James Watt, 1775) – Powered factories, trains, and ships.  
  - **Spinning Jenny & Power Loom** – Revolutionized textile production.  
  - **Bessemer Process** (1850s) – Made steel production faster and cheaper.
[...]

By simply changing the system prompt, you can create tutors with different expertise areas, allowing you to build specialized educational tools for various subjects.

Summary and Next Steps

In this lesson, you learned how to personalize your AI tutor using system prompts. By defining the tutor's personality and expertise, you can customize its behavior and tone, creating educational interactions tailored to specific subject areas. We walked through an example of building a specialized math and science tutor, demonstrating how system prompts influence the tutor's responses.

As you move on to the practice exercises, I encourage you to experiment with different system prompts to see how they affect the tutor's behavior. This hands-on practice will reinforce what you've learned and prepare you for the next unit, where we'll explore managing multiple tutoring sessions. Keep up the great work, and enjoy the journey of creating your personal tutor with DeepSeek!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal