Nodes and edges in our agent
OK, so let’s review. We’ve mentioned that an agentic RAG graph has three key components: the state that we already talked about, the nodes that append to or update the state, and the conditional edges that decide which node to visit next. We are now to the point where we can step through each of these in code blocks, seeing how the three components interact with each other.
Given this background, the first thing we will add to the code is the conditional edge, where the decisions are made. In this case, we are going to define an edge that determines if the retrieved documents are relevant to the question. This is the function that will decide whether to move on to the generation stage or to go back and try again:
- We will step through this code in multiple steps, but keep in mind that this is one large function, starting with the definition:
def score_documents(state) -> Literal[
    "generate", "...