ReAct Research Agent with Lang

AI & HCI
n8n 캔버스에서 화살표로 그렸던 루프를, 코드 한 줄의 그래프 선언으로 옮겼다.
Posted on June 30, 2026, 8:46 a.m. by SANGJIN
random_image

Reimplemented the same ReAct (Reasoning + Acting) research agent from the n8n version, this time as an explicit graph in LangGraph. Where n8n expressed the loop as a line drawn back to an earlier node on a canvas, add_conditional_edges expresses the same logic in code.

Step Role
plan_node Gemini generates the first search keyword
search_node Tavily searches, accumulates results into State
judge_node Decides if results are sufficient, generates next keyword
add_conditional_edges Routes to summarize_node or back to search_node
summarize_node → save_node Writes the final markdown report to disk

Key decisions:

State (a TypedDict) replaces n8n's automatic JSON hand-off between nodes — every node reads State and returns an updated copy, making data flow explicit in code rather than implied by canvas wiring

The same "stop after 3 attempts" rule needed a different comparison than the n8n version (iteration >= 3 vs n8n's $runIndex >= 2), since LangGraph increments iteration inside judge_node itself — same outcome, different counting point

save_node writes files directly, since LangGraph runs as a local Python process rather than inside a Docker container with restricted file permissions

Tech: LangGraph, FastAPI, Gemini API (langchain-google-genai, free tier), Tavily Search API, Python


n8n 버전과 동일한 ReAct(Reasoning + Acting) 리서치 Agent를 LangGraph로 다시 구현했다. n8n이 캔버스에서 노드 뒤로 선을 그어 루프를 표현했다면, LangGraph는 add_conditional_edges로 같은 로직을 코드로 선언한다.

단계 역할
plan_node Gemini가 첫 검색 키워드 생성
search_node Tavily로 검색, State에 결과 누적
judge_node 충분한지 판단, 부족하면 다음 키워드 생성
add_conditional_edges summarize_node 또는 search_node로 분기
summarize_node → save_node 최종 마크다운 보고서 저장

구현별 핵심:

State(TypedDict)가 n8n의 자동 JSON 전달을 대체한다. 모든 노드가 State를 읽고 갱신된 복사본을 반환해, 데이터 흐름이 캔버스의 암묵적 연결이 아니라 코드로 명시됨

"3회 시도 후 종료" 규칙이 n8n과 비교 조건이 다르다 (iteration >= 3 vs n8n의 $runIndex >= 2). LangGraph는 judge_node 내부에서 iteration을 증가시키기 때문 — 결과는 같지만 카운팅 시점이 다름

save_node가 파일을 직접 저장한다. LangGraph는 권한이 제한된 Docker 컨테이너가 아니라 로컬 Python 프로세스로 실행되기 때문

사용 기술: LangGraph, FastAPI, Gemini API (langchain-google-genai, 무료 티어), Tavily Search API, Python

Links Github: https://github.com/SangjinKO/agentic_loop_search_langraph Velog: https://velog.io/@kosang234/n8n%EC%97%90%EC%84%9C-%ED%99%94%EC%82%B4%ED%91%9C%EB%A1%9C-%EA%B7%B8%EB%A0%B8%EB%8D%98-%EB%A3%A8%ED%94%84%EB%A5%BC-LangGraph%EC%97%90%EC%84%9C%EB%8A%94-%EC%BD%94%EB%93%9C%EB%A1%9C-%EC%84%A0%EC%96%B8%ED%96%88%EB%8B%A4-ReAct-Agent-%EC%9E%AC%EA%B5%AC%ED%98%84%EA%B8%B0

AI

Leave a Comment: