thought

Chat Template

Chat Template converts structured API messages into a linear stream of tokens with special tags (e.g., <|imstart|>, <|imend|>). This leads to two consequences: (1) roles cannot be substituted — if a tool result is passed as a user message, the model will “change the subject” and erase the reasoning chain; (2) KV Cache is sensitive to the prefix specifically at the token level. Strategies for handling reasoning history vary: from complete removal (DeepSeek R1) to mandatory return (DeepSeek V4, Claude).

Related: Пять компонентов контекста, KV Cache