Questions
2 of 32
1What is a Message in LangChain and how does it differ from a plain string prompt?
2What are the core message types in LangChain — HumanMessage, AIMessage, SystemMessage, ToolMessage, FunctionMessage — and when do you use each?
3What is the difference between SystemMessage and HumanMessage — how does the LLM treat them differently under the hood?
4What is a BaseMessage and why does LangChain model all messages as objects instead of raw strings?
5What is the content field in a message and why can it be either a string or an array of content blocks?
6What is a multimodal message and how do you pass images or file data inside a message content block?
7How do you construct a conversation history as a BaseMessage[] array and pass it correctly to a Chat Model?
8What is MessagePlaceholder in a ChatPromptTemplate and how does it let you inject dynamic message history into a prompt?
9How does AIMessage carry tool call requests and how does ToolMessage carry the result back — walk through the full round trip?
10What is the difference between AIMessage.tool_calls and AIMessage.additional_kwargs.function_call — why do both exist?
11How do you trim messages to stay within the LLM's context window without losing important conversation context?
12How do you filter messages by type (e.g. only keep HumanMessages) using LangChain's built-in message utilities?
13What is mergeMessageRuns() and when would you use it to preprocess a message list?
14How do you convert LangChain messages to OpenAI's raw API format and back — when would you need to do this?
15How does LangGraph's MessagesAnnotation work and why is it the recommended state shape for agent graphs?
16How does the messages reducer in LangGraph handle message updates — why can you append, replace, or delete messages by ID?
17How do you implement message deduplication in a LangGraph state to avoid the same message being added twice?
18How do you implement a sliding window memory — keeping only the last N messages — without losing the system prompt?
19How do you implement conversation summarization — replacing old messages with a summary message to save tokens?
20How do you persist and restore a full message history across sessions using a checkpoint saver in LangGraph?
21What is the difference between storing messages in MemorySaver vs an external store like Redis or PostgreSQL via a custom BaseCheckpointSaver?
22How do you stream individual message chunks using AIMessageChunk and how do you aggregate them into a complete AIMessage?
23What is RemoveMessage in LangGraph and how do you use it to surgically delete specific messages from agent state?
24How do you attach custom metadata to a message (e.g. timestamps, user IDs, trace IDs) without breaking LLM compatibility?
25How do you handle token counting per message — accounting for role overhead, tool schemas, and system prompt tokens — to accurately predict context usage?
26How do you design a multi-tenant message store where conversation histories are isolated per user and per session?
27How do you use LangSmith to inspect the exact message array sent to the LLM at every step of an agent run?
28What are the security implications of injecting user-supplied content directly into a SystemMessage — how do you prevent prompt injection attacks?
29Your agent is hitting the context window limit after 20 turns — what is your strategy to manage message history without losing critical context?
30A user's message contains both text and an image — how do you construct the correct multimodal HumanMessage content block for a vision model?
31You need to replay a past conversation from a database and continue it — how do you reconstruct the message state correctly in LangGraph?
32Your LLM is returning inconsistent tool call formatting across providers (OpenAI vs Anthropic vs Gemini) — how do LangChain messages abstract this away?
02 / 32

What are the core message types in LangChain — HumanMessage, AIMessage, SystemMessage, ToolMessage, FunctionMessage — and when do you use each?

LangChain's core message types correspond to different actors and phases in a conversation: HumanMessage for user input, AIMessage for model responses, SystemMessage for setting assistant behavior, ToolMessage for returning tool execution results, and FunctionMessage (deprecated) for legacy function responses [citation:1][citation:6].

LangChain uses a class hierarchy derived from BaseMessage, where each type represents a distinct role or phase in the conversation flow, ensuring the LLM can correctly interpret the source and purpose of each message [citation:1][citation:6].

HumanMessage
  1. 1

    Represents input from the end user to the AI model.

  2. 2

    Typically contains the user's question, command, or statement.

  3. 3

    The content field holds the user's text or other data. [citation:1][citation:6]

AIMessage
  1. 1

    Represents the response generated by the AI model.

  2. 2

    Used for both simple text responses and those containing tool calls.

  3. 3

    Contains key fields like tool_calls, usage_metadata, and invalid_tool_calls. [citation:1][citation:6]

SystemMessage
  1. 1

    Provides high-level instructions to the AI model, defining its persona, rules, and capabilities.

  2. 2

    This message is typically not visible to the end user and is sent by the developer at the start of a conversation. [citation:1][citation:6]

ToolMessage
  1. 1

    Used to return the result of a tool execution back to the AI model.

  2. 2

    Must include a tool_call_id that matches the id of the original AIMessage's tool call request.

  3. 3

    Also can carry a status and an artifact for large output data. [citation:1][citation:6]

The FunctionMessage exists for legacy compatibility with older function-calling patterns and is largely superseded by ToolMessage in modern LangChain versions. The following code example demonstrates a complete round trip of these core message types in an agentic workflow [citation:1].

Example: Tool Calling Round Trip