How do you implement AI agent orchestration with LangGraph?
LangGraph (by LangChain) provides a framework for building stateful, multi-actor AI agent workflows as graphs. Core concepts: nodes represent agent steps (LLM calls, tool executions, conditional logic), edges define transitions between nodes, state represents the accumulated data flowing through the graph, and conditional edges enable dynamic routing based on state. Architecture: define a TypedDict for state (conversation messages, intermediate results, flags), create node functions that process state and return updates, connect nodes with edges and conditional edges, and compile the graph into an executable application. Key features: state persistence (checkpoint state at every node for recovery and replay), human-in-the-loop (interrupt execution at specified nodes for human input, then resume), streaming (stream node outputs to the user as they execute), and subgraphs (compose complex agents from smaller, reusable graph components). Implementation patterns: (1) ReAct agent: tool-calling node with conditional edge that loops back if more tools are needed. (2) Plan-and-execute: planner node creates a task list, executor node processes tasks sequentially, replanner node adjusts based on results. (3) Multi-agent supervisor: supervisor node routes to specialist nodes based on task classification, specialist nodes have their own tool sets. (4) Reflection: generator node produces output, critic node evaluates and provides feedback, conditional edge loops until quality threshold met. State management: use annotation-based state definition for automatic merging, implement reducers for list-type state (append messages vs replace), and use channels for cross-node communication. Deployment: LangGraph Cloud provides hosted deployment with built-in persistence, streaming, and monitoring. Self-hosted deployment uses LangGraph Server. Testing: test individual nodes in isolation, test graph execution end-to-end, and verify state transitions and conditional routing logic.