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
1
2
3
4
5
6
7
8
9
10
11
import { GoogleGenAI } from 'https://esm.
sh/@google/genai';
const ai = new GoogleGenAI({ apiKey:
'PASTE_YOUR_API_KEY_HERE' });
async function pirateBot() {
const persona = "";
// Ask your coding question using the
persona config
}
Console
Click "Run" to execute your code...