LangGraph 0.2 브랜치가 안정화되면서 상태 관리가 꽤 좋아졌다. 특히 체크포인팅과 interrupt.
체크포인트
from langgraph.checkpoint.postgres import PostgresSaver
saver = PostgresSaver.from_conn_string(DSN)
app = graph.compile(checkpointer=saver)
cfg = {"configurable": {"thread_id": "user-42"}}
state = app.invoke({"input": "..."}, config=cfg)
# 다음 호출에서 같은 thread_id면 중간 상태부터 이어감
이게 되면 대화 resume, 실패 복구, human-in-the-loop가 자연스럽게 풀린다. 이전에는 redis에 직접 state pickling했는데 이제 프레임워크 레벨.
interrupt 패턴
특정 노드 앞에서 실행을 일시 정지하고 사람 승인 대기 가능.
g.add_node("confirm_write", confirm_node)
g.add_edge("plan", "confirm_write")
app = g.compile(checkpointer=saver, interrupt_before=["confirm_write"])
# 실행 후 중단된 지점
# 사람이 검토 -> state.update({"approved": True}) -> app.invoke(None, config=cfg)
이것으로 내부 agent의 위험 동작(외부 API 호출, DB write)을 승인 체크포인트로 묶음. 사람 승인 후에만 execute 단계 진입.
Subgraph
서브 그래프가 정식으로 지원됨. "retrieval 체인", "reasoning 체인" 같은 블록을 재사용 가능하게 캡슐화. 큰 플로우는 잘 쪼개야 읽힌다.
단점
- 여전히 debug는 어렵다. LangSmith 없이는 노드 간 flow 추적이 힘듦.
- checkpoint DB 스키마가 버전 간 변경 있음. upgrade 시 migration 조심.
- TypedDict state는 IDE 자동완성 지원이 약해서 큰 state에선 Pydantic v2 모델로 대체하고 싶어지지만, 여전히 일부 엣지 케이스가 있음.
결론
에이전트는 "모델 + 그래프 + 상태"다. LangGraph는 "그래프 + 상태" 축에서 가장 실용적. 모델 선택과 분리되어 있어서, Claude/GPT/오픈소스 어떤 걸 꽂든 그대로 돌아간다. 이게 장기적 베팅 이유.
댓글 없음:
댓글 쓰기