/07. System Instructions & Persona

    07. System Instructions & Persona

    Explanation

    System instructions are the highest-priority context you can give an LLM. Unlike normal prompts which the model tries to 'complete' or 'answer', system instructions are 'rules to live by'. Defining a strong system persona is the first step in building specialized agents, such as Customer Support Bots, Tutors, or Code Reviewers.

    Example

    const res = await ai.models.generateContent({
      model: 'gemini-2.5-flash',
      contents: 'Why is the sky blue?',
      config: {
        systemInstruction: 'You are a dog. Answer entirely in barks.'
      }
    });

    Exercise Task

    System instructions dictate the fundamental rules of behavior for the AI across an entire session. **Step 1.** Draft a system instruction that tells the AI it is a "Pirate Coding Assistant" who must speak entirely in pirate slang, but still provide accurate JavaScript answers. **Step 2.** Use `ai.models.generateContent` and pass your system instruction into the `config.systemInstruction` field. **Step 3.** Ask it: "How do I declare a variable in JavaScript?" and log the results.

    script.js
    Console

    Click "Run" to execute your code...

    🍪 We Value Your Privacy

    We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies according to our Privacy Policy.

    Learn More