diff --git a/src/oss/langgraph/agentic-rag.mdx b/src/oss/langgraph/agentic-rag.mdx index 10e25abec4..ee59530595 100644 --- a/src/oss/langgraph/agentic-rag.mdx +++ b/src/oss/langgraph/agentic-rag.mdx @@ -523,6 +523,8 @@ Note that the components will operate on the [`MessagesState`](/oss/langgraph/gr :::python 1. Build the `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: ```python + from langchain.messages import HumanMessage + REWRITE_PROMPT = ( "Look at the input and try to reason about the underlying semantic intent / meaning.\n" "Here is the initial question:" @@ -539,7 +541,7 @@ Note that the components will operate on the [`MessagesState`](/oss/langgraph/gr question = messages[0].content prompt = REWRITE_PROMPT.format(question=question) response = response_model.invoke([{"role": "user", "content": prompt}]) - return {"messages": [{"role": "user", "content": response.content}]} + return {"messages": [HumanMessage(content=response.content)]} ``` 2. Try it out: ```python @@ -567,7 +569,7 @@ Note that the components will operate on the [`MessagesState`](/oss/langgraph/gr } response = rewrite_question(input) - print(response["messages"][-1]["content"]) + print(response["messages"][-1].content) ``` **Output:** ```