1. Chat history is a record of the conversation between the user and the chat model.
  2. It is used to maintain context and state throughout the conversation.
  3. The chat history is sequence of messages, each of which is associated with a specific role, such as "user", "assistant", "system", or "tool".

Conversation patterns

image.png

  1. Conversation starts with a system message that sets the context for the conversation.
  2. This is followed by a User message containing the user’s input, and then an assistant message containing the model’s response.
  3. The assistant may respond directly to the user or if configured with tools request that a tool be invoked to perform a specific task.

A full conversation often involves a combination of two patterns of alternating messages:

  1. The user and the assistant representing a back-and-forth conversation.
  2. The assistant and tool messages representing an "agentic" workflow where the assistant is invoking tools to perform specific tasks.

Managing chat history

Since chat models have a maximum limit on input size, it's important to manage chat history and trim it as needed to avoid exceeding the context window.

While processing chat history, it's essential to preserve a correct conversation structure.

Key guidelines for managing chat history:

<aside> 💡

Understanding correct conversation structure is essential for being able to properly implement memory in chat models.

</aside>