본문 바로가기

LangChain&LangGraph

디버깅 - #3 replay

https://programmerk.tistory.com/93

 

디버깅 - #2 interrupt

interrupt :LangGraph의 진행을 특정 단계에서 중지 기능 구성도chatbot 역할 : 사전 llm.bind_tools 로 제공된 tools 을 사용할지 결정하는 역할tools : 웹 검색 도구 제공,chatbot에서 tool_calls 호출시 사용되는 too

programmerk.tistory.com

 

인터럽트 before 로그

https://smith.langchain.com/public/25c69e3d-26ce-4862-834c-b77ab3496fa5/r

 

LangSmith

 

smith.langchain.com

 

 

인터럽트 구간부터 이어서 하기 예제

events = graph.stream(None, config, stream_mode="values")
# 이벤트 반복 처리
for event in events:
    # 메시지가 이벤트에 포함된 경우
    print(event)
    print("\n\n")

 

input 자리에 None 을 입력하고,  이전에 interrupt 포함된 config 를 넣어주면 이어서 실행 가능하다

 

인터럽트 이어서 실행 로그

 

https://smith.langchain.com/public/187b215c-e17d-4791-ac68-303e6d8e8f4d/r

 

LangSmith

 

smith.langchain.com

 

 

 

전체 사이클중 특정 시점 부터 재실행하기

예제

to_replay = None

# 상태 기록 가져오기
for state in graph.get_state_history(config):
    # 메시지 수 및 다음 상태 출력
    print("메시지 수: ", len(state.values["messages"]), "다음 노드: ", state.next)
    print("-" * 80)
    # 특정 상태 선택 기준: 채팅 메시지 수
    if len(state.values["messages"]) == 3:
        to_replay = state

# 다음 항목의 다음 요소 출력
print(to_replay.next)

# 다음 항목의 설정 정보 출력
print(to_replay.config)
 
for event in graph.stream(None, to_replay.config, stream_mode="values"):
    # 메시지가 이벤트에 포함된 경우
    if "messages" in event:
        # 마지막 메시지 출력
        print(event["messages"][-1])

 

start-> chatbot->tools->chatbot->end  5단계중 tools 단계부터 재실행 수행하기위한 코드