Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/oss/langgraph/agentic-rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand All @@ -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
Expand Down Expand Up @@ -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:**
```
Expand Down