-
Notifications
You must be signed in to change notification settings - Fork 0
LangGraph
Heemin0822 edited this page Jun 16, 2026
·
6 revisions
에이전트•도구•로직을 묶는 동적 pipeline 설계 도구
- State 정의 : DB
- Graph 정의 : 로직/흐름
- Node(Function) 설정(***) -> 그래프 초기화 -> 노드•엣지 추가 -> compile (그래프 완성)
- Graph-State 연결
노드 간 직접 인자 전달 없음. 모두 State에 쓰고 읽는다
from typing import TypedDict, Annotated
from operator import add
from langgraph.graph import StateGraph, START, END
# 1. State 정의 — DB 설계
class State(TypedDict):
messages: Annotated[list, add]
count: int
# 2. Node 설정 — 기능 설계
def greet(state: State): # input으로 State 무조건 넣어줘야함 !
return {"messages": ["안녕하세요!"], "count": 1} # return 도 무조건 dict 로 !
def farewell(state: State):
return {"messages": ["다음에 또 봐요."], "count": 1}
# 3. 그래프 초기화 — 빈 깡통 (State 와 연결)
builder = StateGraph(State)
# 4. 노드·엣지 추가 — 조립
builder.add_node("greet", greet)
builder.add_node("farewell", farewell)
builder.add_edge(START, "greet")
builder.add_edge("greet", "farewell")
builder.add_edge("farewell", END)
# 5. 컴파일 — 실행 가능 객체화
graph = builder.compile()