Multi-Agent(HITL) with n8n

AI & HCI
주제와 조건을 입력하면 AI가 조사하고, 쓰고, 세 관점으로 검토한다 — 품질이 미달이면 Slack으로 사람에게 판단을 넘긴다.
Posted on July 6, 2026, 8:24 a.m. by SANGJIN
random_image

Built a multi-agent pipeline that automatically generates a lecture plan from a 6-field webhook input (topic, audience, duration, delivery method, tools, constraints). n8n orchestrates the full workflow across 20 nodes; a Flask server handles all Gemini and Tavily calls.

The pipeline runs in 3 rounds: sequential planning + research → sequential writing → parallel review (content / time allocation / difficulty evaluated simultaneously). If the combined score falls below threshold, a HITL gate pauses execution, sends a Slack notification with score and feedback, and waits for a human POST decision — rework or save as-is.

Key design decisions:

HITL over automated rework loop: lecture plans are creative outputs where numeric scores don't capture everything. A human gate was chosen over automated retry so the final call stays with a person.

Researcher runs sequentially, not in parallel: n8n branching sends the same data to all branches simultaneously — connecting N researcher nodes causes N² calls, not N parallel calls. Split Out + single HTTP Request node (Execute Once OFF) was the correct pattern. Fixed-N parallel (3 reviewers via node branches + Merge) works cleanly.

Gemini fallback chain: gemini-3.1-flash-lite → gemini-2.5-flash-lite → gemini-2.5-flash with exponential backoff on 429/503 errors.

Research query strategy: subtopic + educational keywords ("강의", "교육 커리큘럼", "부트캠프") with wikipedia.org and namu.wiki excluded — returns actual curriculum pages instead of definitions.

JSON.stringify() rule: draft, feedback, and reviews always require JSON.stringify() in n8n JSON Body. Plain {{ }} wrapping breaks on newlines. Slack messages with multi-field concatenation need Specify Body → Using Fields mode.

Tech: n8n, Flask, Python, Gemini API (free tier, fallback chain), Tavily Search API, Slack Incoming Webhook


Webhook으로 6개 필드(주제/대상자/일수/방식/도구/제약조건)를 받아 강의계획서를 자동 생성하는 멀티에이전트 파이프라인을 만들었다. n8n이 20개 노드로 전체 흐름을 제어하고, Flask 서버가 Gemini와 Tavily 호출을 담당한다.

파이프라인은 3라운드로 구성된다. 서브토픽 분해 + 서브토픽별 웹 검색(순차) → 초안 작성(순차) → 내용/시간배분/난이도 병렬 검토(3개 동시). 종합 점수가 기준 미달이면 HITL 게이트가 작동해 Slack으로 점수와 피드백을 전송하고, 사람이 curl 명령으로 "재작업" 또는 "현재 버전 저장"을 결정할 때까지 대기한다.

핵심 설계 결정:

HITL 선택: 강의계획서는 수치 점수만으로 품질을 판단하기 어렵다. 자동 재작업 루프 대신 사람이 최종 판단하는 구조를 선택했다.

researcher 순차 처리: n8n 분기는 같은 데이터를 여러 경로로 동시에 보내는 것이다. researcher 노드 N개를 병렬 연결하면 N² 호출이 발생한다. Split Out + 단일 HTTP Request 노드(Execute Once OFF)가 올바른 패턴이다. 고정 N개 병렬(reviewer 3개 분기 + Merge)은 정상 동작한다.

Gemini 폴백 체인: gemini-3.1-flash-lite → gemini-2.5-flash-lite → gemini-2.5-flash, 429/503 에러 시 지수 백오프 후 다음 모델로 전환.

검색 쿼리 전략: 서브토픽 + 교육 키워드("강의", "교육 커리큘럼", "부트캠프") 조합, 위키피디아/나무위키 제외 → 용어 정의 대신 실제 커리큘럼 페이지 수집.

JSON.stringify() 원칙: draft, feedback, reviews는 n8n JSON Body에서 항상 JSON.stringify() 처리 필수. 줄바꿈 포함 필드를 {{ }} 그대로 쓰면 Bad control character 오류 발생.

사용 기술: n8n, Flask, Python, Gemini API (무료 티어, 폴백 체인), Tavily Search API, Slack Incoming Webhook

Links Github: https://github.com/SangjinKO/n8n_HITL_lecture_planner Velog: https://velog.io/@kosang234/n8n%EC%9C%BC%EB%A1%9C-%EA%B0%95%EC%9D%98%EA%B3%84%ED%9A%8D%EC%84%9C%EB%A5%BC-%EC%9E%90%EB%8F%99-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-Multi-Agent-AI-Workflow%EB%A5%BC-%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

Agent

Leave a Comment: