MessagePlaceholder is a special prompt component that acts as a slot for injecting a dynamic list of messages (a conversation history) into a prompt template at runtime, allowing for flexible handling of variable-length histories [citation:1][citation:5][citation:9].
MessagePlaceholder is a powerful tool in ChatPromptTemplate that solves the problem of handling variable-length conversation histories. Unlike static messages (like a fixed SystemMessage), the placeholder's content is not defined when you write the template. Instead, you provide the conversation history as a list of BaseMessage objects when you invoke the prompt. The MessagePlaceholder seamlessly inserts this entire list of messages into the prompt at that exact point. This is critical for building agents and chatbots, as the conversation history grows over time and must be included in each new model call for context [citation:1][citation:5][citation:9].