docs: LangGraph 워크플로우 session 처리 및 조건부 엣지 추가

- ColdmailState에서 session 제거 (직렬화 불가)
- 각 노드에서 async with aiohttp.ClientSession() 개별 생성
- route_after_filter 함수 추가
- add_conditional_edges로 filter → END or process 분기
- process 노드에서 for 루프로 여러 이메일 처리
- try-except로 IR 실패 시 continue 명시
- 96줄 유지

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
happybell80 2025-10-14 22:34:09 +09:00
parent b0ddfc0dc4
commit 4e8a85c23f

View File

@ -72,19 +72,20 @@
- requirements.txt: langgraph 추가
- app/workflows/__init__.py: 빈 파일 생성
- app/workflows/coldmail_workflow.py 생성:
- from typing import TypedDict; from langgraph.graph import StateGraph, END
- class ColdmailState(TypedDict): emails: list, coldmail_candidates: list, processed_results: list, session: object
- async def fetch_emails_node(state): coldmail_briefing.py:93-121 로직 이동
- async def filter_coldmail_node(state): coldmail_briefing.py:123-141 로직 이동
- async def process_email_node(state): coldmail_briefing.py:145-287 for 루프 내용 이동
- async def send_summary_node(state): coldmail_briefing.py:289-300 로직 이동
- from typing import TypedDict; from langgraph.graph import StateGraph, END; import aiohttp
- class ColdmailState(TypedDict): emails: list, coldmail_candidates: list, processed_results: list
- async def fetch_emails_node(state): async with aiohttp.ClientSession() as session 내부에서 coldmail_briefing.py:103-121 로직 실행, return {"emails": emails}
- async def filter_coldmail_node(state): for email in state["emails"] 반복, coldmail_briefing.py:125-139 필터 로직, return {"coldmail_candidates": candidates}
- async def process_email_node(state): async with aiohttp.ClientSession() as session 내부에서 for email in state["coldmail_candidates"] 반복, coldmail_briefing.py:145-287 처리, try-except로 IR 실패 시 continue, return {"processed_results": results}
- async def send_summary_node(state): async with aiohttp.ClientSession() as session, coldmail_briefing.py:289-300 요약 전송
- def route_after_filter(state): return "process" if state["coldmail_candidates"] else END
- graph = StateGraph(ColdmailState)
- graph.add_node("fetch", fetch_emails_node), add_node("filter", filter_coldmail_node), add_node("process", process_email_node), add_node("send", send_summary_node)
- graph.add_edge("fetch", "filter"), add_edge("filter", "process"), add_edge("process", "send"), add_edge("send", END)
- graph.add_edge("fetch", "filter"), add_conditional_edges("filter", route_after_filter, {"process": "process", END: END}), add_edge("process", "send"), add_edge("send", END)
- workflow = graph.compile()
- coldmail_briefing.py:78-302: _run_coldmail_briefing() 전체 교체
- coldmail_briefing.py:78-302: _run_coldmail_briefing() 교체
- from app.workflows.coldmail_workflow import workflow
- initial_state = {"emails": [], "coldmail_candidates": [], "processed_results": [], "session": session}
- initial_state = {"emails": [], "coldmail_candidates": [], "processed_results": []}
- result = await workflow.ainvoke(initial_state)
---