WebBaseLoader
utility:create_retriever_tool
:MessagesState
— graph state that contains a messages
key with a list of chat messages.
generate_query_or_respond
node. It will call an LLM to generate a response based on the current graph state (list of messages). Given the input messages, it will decide to retrieve using the retriever tool, or respond directly to the user. Note that we’re giving the chat model access to the retriever_tool
we created earlier via .bind_tools
:grade_documents
— to determine whether the retrieved documents are relevant to the question. We will use a model with a structured output schema GradeDocuments
for document grading. The grade_documents
function will return the name of the node to go to based on the grading decision (generate_answer
or rewrite_question
):rewrite_question
node. The retriever tool can return potentially irrelevant documents, which indicates a need to improve the original user question. To do so, we will call the rewrite_question
node:generate_answer
node: if we pass the grader checks, we can generate the final answer based on the original question and the retrieved context:generate_query_or_respond
and determine if we need to call retriever_tool
tools_condition
:
generate_query_or_respond
returned tool_calls
, call retriever_tool
to retrieve contextgrade_documents
) and route to next step:
rewrite_question
and then call generate_query_or_respond
againgenerate_answer
and generate final response using the ToolMessage
with the retrieved document context