Questions
31 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?
31 / 32

You need to replay a past conversation from a database and continue it — how do you reconstruct the message state correctly in LangGraph?

Reconstruct the message state by loading the stored messages as a list of BaseMessage objects (using convert_to_messages if stored as dicts) and then resuming the graph with the same thread_id in the config, which will restore the full checkpoint state including messages.

LangGraph's checkpointing system is designed for exactly this purpose. If you have previously stored the conversation using a persistent checkpointer (e.g., PostgresSaver), you can simply resume with the same thread_id. The graph will load the last checkpoint, including all messages. If you need to reconstruct from raw message data (e.g., from a database that doesn't use LangGraph checkpoints), you can create a list of BaseMessage objects using convert_to_messages from stored dictionaries, then start a new graph invocation with that initial state. For the latter approach, you must ensure the message IDs are preserved or generated consistently to avoid duplication.

Reconstructing State from Database Records

For production, always use LangGraph's built-in checkpointer with a persistent store. It automatically handles serialization, versioning, and ID preservation, and is more efficient than manual reconstruction.

Difficulty: 7/10
Topics: state reconstruction, message persistence, LangGraph workflow

Scenario Questions

0-2 years experience
  1. 1

    Suppose you have stored each turn of a chat in a SQL table with columns id, role, content, and a parent_id linking to the previous message. How would you load those rows and feed them into a LangGraph agent so it can continue the conversation?

  2. 2

    If you retrieve a conversation history that includes system messages and user messages, what steps do you take to rebuild the LangGraph state before calling the next node?

  3. 3

    What would happen if you omitted the message timestamps when reconstructing the state?

2-5 years experience
  1. 1

    You notice that after replaying a conversation from the DB, the LangGraph agent repeats the last user message instead of continuing. Walk me through how you'd debug the state reconstruction logic.

  2. 2

    When persisting conversation turns, you decide between storing raw LangChain Message objects vs a serialized JSON. What trade‑offs affect the ability to correctly restore the LangGraph state?

  3. 3

    If the conversation includes branching (multiple possible next nodes), how would you capture and later reconstruct that branching information to resume the correct path?

5-8 years experience
  1. 1

    Design a scalable service that can replay and continue millions of concurrent conversations stored in a NoSQL store. How would you structure the state reconstruction to minimize latency and ensure consistency across distributed workers?

  2. 2

    Explain how you would handle versioning of LangGraph schemas (e.g., added new node types) while still being able to replay older conversations without breaking.

  3. 3

    What edge cases (e.g., missing messages, out‑of‑order timestamps) could cause state corruption, and how would you detect and recover from them in production?

8+ years experience
  1. 1

    Your company is migrating from a custom chat persistence layer to LangGraph’s built‑in state store. What architectural changes would you propose to ensure backward compatibility and minimal downtime, and how would you phase the migration?

  2. 2

    Across multiple product teams, some use LangGraph with different node implementations. How would you establish a shared contract for persisting and replaying conversation state to avoid integration friction?

  3. 3

    Consider long‑term maintenance: how would you design observability and testing strategies to guarantee that replayed conversations always produce the same deterministic outcomes after code changes?

Follow-up Questions

  • Can you sketch the code you’d use to rebuild the LangGraph state from DB rows?
  • What metrics or logs would you put in place to detect reconstruction failures?
  • How would you test that replayed conversations produce the same results after a code change?