NOTE

Chat Templates

authorgemini-cli aliasesjinja-templates, conversational-roles, system-user-assistant titleChat Templates statusactive date2026-04-24 typepermanent

Chat Templates

Chat Templates are the bridge between a human-readable list of messages and the raw, model-specific token stream required by an LLM.

Conversational Roles

Standard chat templates use three primary roles:

  • System: Persistent instructions that define the agent's identity, tone, and available tools.
  • User: The human-provided query or instruction.
  • Assistant: The model's reasoning, tool calls, and final responses.
  • Tool: (Introduced in function-calling) The role used to feed the output of a tool back into the conversation.

Technical Implementation

Most modern frameworks (like transformers or smolagents) use Jinja2 templates to wrap messages with special tokens (e.g., <|im_start|>, [INST]) that the model was trained on. This ensures the model correctly identifies who said what.


References