ReAct Research Agent with n8n
AI & HCI주제 하나만 던지면, AI가 스스로 검색하고 판단하고 — 부족하면 다시 검색한다.
Built a ReAct (Reasoning + Acting) agent that autonomously repeats search and judgment until it has enough information to answer a research topic. Unlike a single-pass pipeline, this agent decides for itself whether to search again or stop, using Gemini for judgment and Tavily for web search.
The core architecture: n8n controls the loop, Flask handles every call to Gemini and Tavily behind it.
| Step | Role |
|---|---|
| Plan | Gemini generates the first search keyword |
| Search | Tavily searches the web, results accumulate across loops |
| Judge | Gemini decides if results are sufficient, or generates the next keyword |
| Summarize → Save | Once sufficient, writes a markdown report to disk |
Key decisions:
n8n's Loop Over Items node cannot exit early on a condition — it processes
every item in a batch before stopping. Replaced it with a direct
If:false → Search loopback, letting Judge's verdict control each iteration
Result accumulation moved to the Flask server: /search merges new results
with previous_results on every call, keeping the n8n workflow simple
Tech: n8n, Flask, Gemini API (free tier), Tavily Search API, Docker, Python
주제 하나를 입력하면 스스로 검색하고, 결과가 충분한지 판단하고, 부족하면 다른 키워드로 다시 검색하는 ReAct(Reasoning + Acting) Agent를 만들었다. 한 번 판단하고 끝나는 파이프라인과 달리, 이 Agent는 Gemini의 판단과 Tavily 검색을 반복하며 스스로 다음 행동을 결정한다.
핵심 아키텍처: n8n이 루프를 제어하고, 그 뒤에서 Flask가 Gemini와 Tavily 호출을 전담한다.
| 단계 | 역할 |
|---|---|
| Plan | Gemini가 첫 검색 키워드 생성 |
| Search | Tavily로 웹 검색, 루프를 돌수록 결과 누적 |
| Judge | 결과가 충분한지 판단, 부족하면 다음 키워드 생성 |
| Summarize → Save | 충분해지면 마크다운 보고서로 저장 |
구현별 핵심:
n8n의 Loop Over Items 노드는 조건으로 중간에 멈출 수 없고 배치 전체를 처리해야 종료된다. If:false → Search 직접 연결로 바꿔서, Judge의 판단이 매 반복을 제어하게 함
결과 누적은 Flask 서버 책임으로 분리. /search가 매 호출마다 이전 결과와 새 결과를 합산해, n8n 워크플로우 자체는 단순하게 유지
사용 기술: n8n, Flask, Gemini API (무료 티어), Tavily Search API, Docker, Python
Links Github: https://github.com/SangjinKO/n8n_agentic_loop_research Velog: https://velog.io/@kosang234/GitHub%EC%97%90-push%ED%95%98%EB%A9%B4-%ED%85%8C%EC%8A%A4%ED%8A%B8%EA%B0%80-%EB%8F%8C%EA%B3%A0-%ED%86%B5%EA%B3%BC%ED%95%98%EB%A9%B4-%EB%B0%B0%ED%8F%AC%EB%90%9C%EB%8B%A4-Jenkins-Pytest-Docker%EB%A1%9C-QA-%EC%9E%90%EB%8F%99%ED%99%94-%ED%8C%8C%EC%9D%B4%ED%94%84%EB%9D%BC%EC%9D%B8%EC%9D%84-%EC%A7%81%EC%A0%91-%EB%A7%8C%EB%93%A4%EB%A9%B4%EC%84%9C-%EA%B9%A8%EB%8B%AC%EC%9D%80-%EA%B2%83%EB%93%A4
Leave a Comment: