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

How do you implement message deduplication in a LangGraph state to avoid the same message being added twice?

Difficulty: 6/10
state management, deduplication, LangGraph

Message deduplication is automatically handled by LangGraph's add_messages reducer because each message carries a unique ID. If the same message (with the same ID) is added again, it will replace the existing one rather than duplicate. For manual deduplication, you can use a custom reducer that checks for content equality before appending.

The default add_messages reducer already prevents duplication based on message IDs. When you create messages, LangChain assigns a random id if not provided. If you re-send the same message object (with the same ID), the reducer will replace it, not duplicate it. However, if you create two separate message objects with identical content but different IDs, they will both be added. To avoid this, you can either reuse the same message object or implement a custom reducer that checks content equality and skips duplicates.

Ensuring Deduplication with IDs

Scenario Questions

0-2 years experience

  1. 1Suppose you have a LangGraph that stores messages in its state list. How would you modify the node that adds a new message to ensure the same message text isn’t added twice?
  2. 2If you run a simple test where the same user input is sent twice, what would you check in the state to confirm your deduplication logic worked?
  3. 3What data structure would you use inside the state to quickly check whether a message has already been seen?

2-5 years experience

  1. 1You’re adding a deduplication step to a LangGraph that processes user queries, but after deployment you notice some messages still appear twice when the user sends rapid consecutive inputs. Walk me through how you’d debug the issue.
  2. 2Explain the trade‑offs between using a set of message IDs versus hashing the full message content for deduplication in a LangGraph that may handle large payloads.
  3. 3If the deduplication logic accidentally filters out a legitimate new message because its content matches an older one, how would you adjust the design to avoid false positives?

5-8 years experience

  1. 1Design a deduplication mechanism for a LangGraph that must handle millions of messages per day across multiple worker processes. What consistency model would you choose and why?
  2. 2How would you instrument and monitor the deduplication component in production to detect performance bottlenecks or accidental message loss?
  3. 3Consider a scenario where the state is persisted to a distributed store (e.g., Redis). How would you ensure deduplication remains correct when the store experiences partitions or restarts?

8+ years experience

  1. 1At a platform level, how would you evolve the LangGraph architecture to make deduplication a reusable service across many different agents while keeping backward compatibility?
  2. 2Discuss the long‑term maintenance implications of embedding deduplication logic directly in each graph versus abstracting it into a shared middleware layer. Which approach scales better across teams?
  3. 3If the organization decides to migrate from LangGraph to a new orchestration framework, what migration strategy would you propose to preserve deduplication guarantees without downtime?

Follow-up Questions

  • What would you do if the deduplication check becomes a performance hotspot?
  • How would you handle deduplication when messages can be edited after being sent?
  • Can you think of any failure modes where a duplicate could slip through despite your design?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.