const messages = [
{ role: 'user', content: `Rules: answer in French.\nUser: ${input}\nBot: ${lastReply}` },
];const messages = [
{ role: 'system', content: 'Answer in French.' },
{ role: 'user', content: previousQuestion },
{ role: 'assistant', content: lastReply },
{ role: 'user', content: input },
];Separate roles keep developer rules, user text and past replies apart, so the model knows who said what.
Models are trained to weigh system instructions above user text, and keeping them apart makes injection harder. Some APIs take it as a separate parameter.
Yes. Many APIs accept 'assistant' messages you write, for example to replay history or show examples. Keep untrusted input in 'user' messages.
Some APIs use a 'tool' role or a tool result block to return function results to the model, linked to the call by an id.