Skip to content

Commit 1089929

Browse files
authored
fix(docs): Use @tool decorator for retriever in agentic RAG tutorial (#1774)
## Overview Fixed the agentic RAG tutorial to use the `@tool` decorator instead of `create_retriever_tool`. The previous approach caused a `TypeError` when used with LangGraph's `ToolNode` because `create_retriever_tool` returns a `functools.partial` object, which is incompatible with `typing.get_type_hints()`. ## Type of change **Type:** Fix typo/bug/link/formatting ## Related issues/PRs - GitHub issue: N/A - Feature PR: N/A ## Checklist - [x] I have read the [contributing guidelines](README.md) - [ ] I have tested my changes locally using `docs dev` - [x] All code examples have been tested and work correctly - [x] I have used **root relative** paths for internal links - [ ] I have updated navigation in `src/docs.json` if needed ## Additional notes The issue manifests as: `TypeError: functools.partial(...) is not a module, class, method, or function` during graph compilation/execution. The `@tool` decorator creates a proper `StructuredTool` that `ToolNode` can correctly inspect.
1 parent 110d036 commit 1089929

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/oss/langgraph/agentic-rag.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,17 @@ Now that we have our split documents, we can index them into a vector store that
150150
)
151151
retriever = vectorstore.as_retriever()
152152
```
153-
2. Create a retriever tool using LangChain's prebuilt `create_retriever_tool`:
153+
2. Create a retriever tool using the `@tool` decorator:
154154
```python
155-
from langchain_classic.tools.retriever import create_retriever_tool
155+
from langchain.tools import tool
156156

157-
retriever_tool = create_retriever_tool(
158-
retriever,
159-
"retrieve_blog_posts",
160-
"Search and return information about Lilian Weng blog posts.",
161-
)
157+
@tool
158+
def retrieve_blog_posts(query: str) -> str:
159+
"""Search and return information about Lilian Weng blog posts."""
160+
docs = retriever.invoke(query)
161+
return "\n\n".join([doc.page_content for doc in docs])
162+
163+
retriever_tool = retrieve_blog_posts
162164
```
163165
3. Test the tool:
164166
```python

0 commit comments

Comments
 (0)