AI EngineeringInterview preparation
Intermediate·Concept·2 min read

State and reducers

Practice this question

Overview

  • State is the structured data shared by graph steps, such as current intent, evidence IDs, and task phase.
  • A reducer specifies how a new update combines with an existing state field.
  • Some fields replace earlier values; others safely combine multiple updates.

Why this matters

Nodes need explicit inputs and predictable updates, especially when parallel branches write results.

An everyday example

A shared case file contains one current status but can contain many evidence entries.

A technical example

Replace phase; merge evidence by source ID; add bounded event records rather than replacing the entire event list accidentally.

How it works

  1. Node returns partial update
  2. Graph applies each field's update rule
  3. Resulting state becomes input to subsequent nodes
  4. Persist at configured boundaries.

Architecture and flow

Current state + node updates → reducers → next state.

The insurance assistant example

Two independent document-checking branches contribute findings without overwriting one another.

When to use it

Explicit state for any graph; reducers when multiple updates need combination.

When to avoid it

Do not store full PDFs, credentials, database clients, or unrestricted histories in checkpoints.

Interview answer

“State is the graph's execution contract; reducers define how updates are applied, including safe merging for parallel results.”

Benefits, trade-offs, and production considerations

  • Prefer deterministic, associative merging for concurrent results and deduplicate by stable IDs.
  • Appending arrays blindly can grow state and duplicate replayed records.
  • Runtime authentication should be freshly verified and kept distinct from model-editable fields.
Adapted from 13_AI.MD · “State and reducers”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.