Reducers vs replaces in TypedDict

When two subagents touch the same field, the default in LangGraph is to overwrite. That works for the latest answer, but it loses citations and partial results when more than one specialist contributes. Reducers give you control over how updates combine for each field.

Replace vs append vs merge

Each state key has a merge policy. Replace overwrites, append concatenates lists, merge combines dicts.

agents/state.py
python
from operator import add
from typing import Annotated, TypedDict


class AgentState(TypedDict):
    question: str  # replace by default
    citations: Annotated[list, add]  # append across subagents
    final_answer: str  # replace by default

Annotated with add gives you a list reducer. Plain types stay replace-by-default. Pick per field based on what the conversation needs.

Quiz: Quiz

Loading practice…