반응형

⭐ 역할
🧩 역할
- 데이터를 변환하거나 수정할 필요가 없는 경우
- 파이프라인의 특정 단계를 건너뛰어야 하는 경우
- 디버깅 또는 테스트 목적으로 데이터 흐름을 모니터링해야 하는 경우
🤖 예제로 흐름 파악하기
- tax_deduction_question가 invoke를 통해, tax_deduction_chain의 question: RunnablePassthrough로 들어감
- 마찬가지로 tax_base_equation_question이 tax_base_retrieval_chain의 question: RunnablePassthrough로 들어감
- tax_base_equation_chain의 tax_base_equation_information에는 tax_base_retrieval_chain이 들어옴
tax_base_retrieval_chain = (
{'context': retriever, 'question': RunnablePassthrough()}
| rag_prompt
| llm
| StrOutputParser()
)
tax_base_equation_prompt = ChatPromptTemplate.from_messages([
('system', '사용자의 질문에서 과세표준을 계산하는 방법을 수식으로 나타내주세요. 부연설명 없이 수식만 리턴해주세요'),
('human', '{tax_base_equation_information}')
])
tax_base_equation_chain = (
{'tax_base_equation_information': RunnablePassthrough()}
| tax_base_equation_prompt
| llm
| StrOutputParser()
)
tax_base_chain = {'tax_base_equation_information' : tax_base_retrieval_chain} | tax_base_equation_chain
def get_tax_base_equation(state: AgentState) -> AgentState:
tax_base_equation_question = '주택에 대한 종합부동산세 계산시 과세표준을 계산하는 방법을 수식으로 표현해서 알려주세요'
tax_base_equation = tax_base_chain.invoke(tax_base_equation_question)
return {'tax_base_equation': tax_base_equation}
tax_deduction_chain = (
{'context': retriever, 'question': RunnablePassthrough()}
| rag_prompt
| llm
| StrOutputParser()
)
def get_tax_deduction(state: AgentState) -> AgentState:
# 공제금액을 묻는 질문을 정의합니다.
tax_deduction_question = '주택에 대한 종합부동산세 계산시 공제금액을 알려주세요'
# tax_deduction_chain을 사용하여 질문을 실행하고 결과를 얻습니다.
tax_deduction = tax_deduction_chain.invoke(tax_deduction_question)
# state에서 'tax_deduction' 키에 대한 값을 반환합니다.
return {'tax_deduction': tax_deduction}
출처
01. RunnablePassthrough
.custom { background-color: #008d8d; color: white; padding: 0.25em 0.5…
wikidocs.net
반응형
'AI > LangGraph' 카테고리의 다른 글
| tool (0) | 2026.02.24 |
|---|---|
| 지금까지 우리가 만든건 Agent가 아니다?? (0) | 2026.02.23 |
| SubGraph와 Router (0) | 2026.02.22 |
| Corrective RAG (0) | 2026.02.22 |
| Self RAG (0) | 2026.02.22 |