작성
·
73
0
안녕하세요 선생님
위 이미지처럼 추후 서브그래프로 들어갈 CSV 관련 코드 작성 및 실행 워크플로우를 구성했는데, 테스트를 통해서 동작은 확인했습니다
그런데 마지막 execute_node가 python_repl로 실행만 하는 노드라서 실패했을 때 워크플로우가 중간에 다시 돌아갈 때 원인이 전달되지 않아서 수정이 잘 될지가 걱정됩니다.
에러까지 넘겨야 할지, 아니면 code_gen node에서 agentexecutor api로 tool_call로 python_repl을 연결한 다음 validation 노드를 타는 게 더 나을지 고민 중인데, 이렇게 하면 코드 실행 실패할 때마다 그래프 시각화가 여러 번 나올 것 같아서 어떤 접근법이 좋을지 조언 부탁드립니다
감사합니다
답변 1
0
안녕하세요. 판다스 스튜디오입니다.
제가 정확하게 코드를 확인하지 못한 상태라서, 아이디어 차원에서 답변 드립니다.
기존 워크플로우 구조를 유지하면서 execute_node에서 실패했을 때 에러 정보를 상태에 저장하여 code_gen_node로 돌아가게 하는 방식으로 처리하면 어떨까 싶습니다.
code_gen node에서는 이 에러정보를 컨텍스트로 활용해서 코드를 개선하는데 사용할 수 있을 것 같습니다.
1. 강의에서 설명한 방식 : 조건부 엣지를 활용한 라우팅
def execute_node(state):
code = state["code"]
try:
result = python_repl.run(code)
return {"result": result, "status": "success"}
except Exception as e:
# 에러 정보를 상태에 저장
return {"error": str(e), "status": "error"}
def router_after_execute(state):
if state.get("status") == "success":
return END
elif state.get("status") == "error":
return "code_gen_node"
2. Command 방식 (최근 업데이트)
from langgraph.types import Command
def execute_node(state):
code = state["code"]
try:
result = python_repl.run(code)
# 성공 시 END로 이동
return Command(
goto=END,
update={"result": result, "status": "success"}
)
except Exception as e:
# 에러 발생 시 code_gen_node로 이동
return Command(
goto="code_gen_node",
update={"error": str(e), "status": "error"}
)
if state.get("status") == "success":
return END
elif state.get("status") == "error":
return "code_gen_node"
선생님 답변 감사합니다
그런데 생각해보니 에러 상황을 정확히 전달하려면 관련 코드도 함께 공유해야 맥락이 더 잘 전달될 것 같은데, 그러면 컨텍스트 내용이 좀 길 것 같아서 일단은 프롬프트 엔지니어링으로 최대한 진행해보려고 합니다. 우선은 전체 그래프를 모두 연결해서 한 번 실행해보는 것이 궁금해서요