Agent Architecture/System Design
Advanced10 min

State Design Patterns

Advanced state management: reducers, private vs public state, state channels, and handling state in long-running workflows.

Quick Reference

  • Reducers (Annotated[list, add_messages]) control how concurrent updates merge — essential for parallel node execution
  • Use private state fields (prefixed with _) for internal bookkeeping that the LLM should not see
  • State channels let nodes communicate typed data without polluting the main state schema
  • For long-running workflows, checkpoint state to the persistence layer after every node to enable resume-on-failure
  • Use state schema versioning when you need to update state shape without breaking in-flight workflows

Reducers — Merging Concurrent Updates

When multiple nodes update the same state field, you need a reducer to define how updates are merged. Without a reducer, the last write wins — which causes data loss in parallel execution:

Reducers prevent data loss in concurrent updates
ReducerBehaviorUse for
add_messagesAppends new messages, updates existing by IDConversation history (messages list)
add (operator.add)Concatenates listsAccumulating results from parallel nodes
None (default)Last write winsSingle-writer fields (intent, status)
Custom functionAny merge logic you defineCounters, aggregations, conflict resolution