Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Stop calling functions: my first LangGraph graph, where state does the calling

Описание и применение

Переписали цепочку JobCopilot в граф LangGraph, где состояние передаётся узлами, а функции не вызывают друг друга, что устранило проблемы с вложенными вызовами и управлением состоянием.

Задача

Nested function calls in a JobCopilot pipeline caused unclear ownership, retry logic, and state management issues.

Результат

The graph-based approach eliminated nested function calls, clarified retry logic, and ensured robust state management, allowing the pipeline to handle errors and scoring correctly.

Рабочий процесс

  • Define a single Pydantic model (AgentState) to hold all run data.
  • Implement nodes that receive state, perform a task, and return a dict patch of changed fields.
  • Use LangGraph’s StateGraph to declare nodes and edges, ensuring no node calls another.
  • Configure last-writer-wins for fields and use Annotated with custom reducers for list accumulation.
  • Run the graph, letting LangGraph merge patches and pass updated state to the next node.
  • Fix a wiring bug that caused every job to return "error" after correcting the graph.
  • Validate state integrity with Pydantic to catch type errors during merges.

Доказательства

functions stop calling each other; state flows through a graph, and nodes return patches of that state.

Источник

Fields without a custom reducer are last-writer-wins — I proved it to myself before trusting it:

Источник

Same lesson as part 1: shape is a contract, and contracts live in pydantic, not in comments.

Источник

  • Дата записи: 2026-10-27T09:26:20.465Z