작성
·
58
답변 2
0
0
안녕하세요. 판다스 스튜디오입니다.
일반적으로 조건부 분기 후 도구에 맞는 적절한 필터링이 필요합니다. 단순 프로토타입에서는 생략할 수 있지만, 실제 사용 시에는 도구에 맞게 가공하는 과정이 권장됩니다.
def filter_for_search_tool(state):
original_question = state.get("question", "")
# 필터링 로직 (예: 검색에 적합한 키워드 추출)
filtered_question = "검색어: " + extract_keywords(original_question)
return {"question": filtered_question}
다음 예시와 같이 메인 그래프에 서브그래프를 노드로 추가하고, 조건부 엣지로 연결합니다.
# 서브그래프 생성
search_graph = create_search_tool_graph()
db_graph = create_database_tool_graph()
# 메인 그래프에 서브그래프 연결
main_graph = StateGraph(State)
main_graph.add_node("supervisor", supervisor)
main_graph.add_node("search_tool", search_graph)
main_graph.add_node("database_tool", db_graph)
# 라우팅 함수 (supervisor 결정에 따라 분기)
def route(state):
return state["next_step"]
# 조건부 엣지 설정
main_graph.add_edge(START, "supervisor")
main_graph.add_conditional_edges(
"supervisor", route,
{
"search_tool": "search_tool",
"database_tool": "database_tool",
"end": END
}
)
# 서브그래프에서 supervisor로 돌아오는 경로
main_graph.add_edge("search_tool", "supervisor")
main_graph.add_edge("database_tool", "supervisor")
감사합니다!