Skip to content

Conversation

sviswana
Copy link

What does this PR do?

Fixes # 894 (raised in #894)
Updating the imports & some linter issues in 3p-integrations/langchain/langgraph_rag_agent_local.ipynb --> tested E2E and can view the langchain traces for the last 2 cells:

https://smith.langchain.com/public/35e29916-70be-4146-8fc9-9787cb111ef5/r
https://smith.langchain.com/public/8ec9370f-29e2-46b4-842c-8ab949f8a3fa/r

@IgorKasianenko
Copy link
Contributor

Thanks for the PR!
I am facing an issue with the last cell. Trace https://smith.langchain.com/public/bc4b4491-32c4-4925-b870-864b51ba02ca/r

output

---ROUTE QUESTION---
Who are the Bears expected to draft first in the NFL draft?
{'datasource': 'web_search'}
web_search
---ROUTE QUESTION TO WEB SEARCH---
---WEB SEARCH---
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[29], [line 7](vscode-notebook-cell:?execution_count=29&line=7)
      [5](vscode-notebook-cell:?execution_count=29&line=5) from pprint import pprint
      [6](vscode-notebook-cell:?execution_count=29&line=6) inputs = {"question": "Who are the Bears expected to draft first in the NFL draft?"}
----> [7](vscode-notebook-cell:?execution_count=29&line=7) for output in app.stream(inputs):
      [8](vscode-notebook-cell:?execution_count=29&line=8)     for key, value in output.items():
      [9](vscode-notebook-cell:?execution_count=29&line=9)         pprint(f"Finished running: {key}:")

File /opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2436, in Pregel.stream(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, checkpoint_during, debug, subgraphs)
   [2434](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2434)         for task in loop.match_cached_writes():
   [2435](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2435)             loop.output_writes(task.id, task.writes, cached=True)
-> [2436](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2436)         for _ in runner.tick(
   [2437](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2437)             [t for t in loop.tasks.values() if not t.writes],
   [2438](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2438)             timeout=self.step_timeout,
   [2439](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2439)             get_waiter=get_waiter,
   [2440](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2440)             schedule_task=loop.accept_push,
   [2441](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2441)         ):
   [2442](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2442)             # emit output
   [2443](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2443)             yield from output()
   [2444](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/llama/lib/python3.12/site-packages/langgraph/pregel/__init__.py:2444) # emit output

Cell In[26], [line 108](vscode-notebook-cell:?execution_count=26&line=108)
    [106](vscode-notebook-cell:?execution_count=26&line=106) print("---WEB SEARCH---")
    [107](vscode-notebook-cell:?execution_count=26&line=107) question = state["question"]
...
    [110](vscode-notebook-cell:?execution_count=26&line=110) # Web search
    [111](vscode-notebook-cell:?execution_count=26&line=111) docs = web_search_tool.invoke({"query": question})

KeyError: 'documents'
During task with name 'websearch' and id '75b85dfd-1140-0aa4-3b67-d84958ac6906'

Could you please help me resolve the error?

I may recommend updating markdown with the new Trace after every cell with code.

@IgorKasianenko
Copy link
Contributor

Would you like to address deprecation warnings in 3rd and 8th cells?
3rd ### Index

USER_AGENT environment variable not set, consider setting it to identify your requests.
[/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/3536094261.py:26](https://file+.vscode-resource.vscode-cdn.net/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/3536094261.py:26): LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-huggingface package and should be used instead. To use it run `pip install -U :class:`~langchain-huggingface` and import as `from :class:`~langchain_huggingface import HuggingFaceEmbeddings``.
  embedding=HuggingFaceEmbeddings(),
[/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/3536094261.py:26](https://file+.vscode-resource.vscode-cdn.net/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/3536094261.py:26): LangChainDeprecationWarning: Default values for HuggingFaceEmbeddings.model_name were deprecated in LangChain 0.2.16 and will be removed in 0.4.0. Explicitly pass a model_name to the HuggingFaceEmbeddings constructor instead.
  embedding=HuggingFaceEmbeddings(),

8th ### Router

[/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/1326739691.py:8](https://file+.vscode-resource.vscode-cdn.net/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/1326739691.py:8): LangChainDeprecationWarning: The class `ChatOllama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import ChatOllama``.
  llm = ChatOllama(model=local_llm, format="json", temperature=0)
[/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/1326739691.py:25](https://file+.vscode-resource.vscode-cdn.net/var/folders/h3/f6zfhg152wb1y4164q6vhzv80000gn/T/ipykernel_82863/1326739691.py:25): LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 1.0. Use :meth:`~invoke` instead.
  docs = retriever.get_relevant_documents(question)
{'datasource': 'vectorstore'}

@IgorKasianenko
Copy link
Contributor

You may take a look on this PR #905 for more context

@sviswana
Copy link
Author

Thanks @IgorKasianenko - addressed the deprecation warnings in 3rd/8th cells & included the updated trace. Interestingly I can't reproduce the error in the last cell, it does seem to work for me...

@IgorKasianenko
Copy link
Contributor

IgorKasianenko commented May 29, 2025

After installing the conda env from scratch and creating new langchain API key I can confirm that I am facing the same error as #894 (comment)
Will be happy to find the solution to it

Todays error log

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[13], [line 6](vscode-notebook-cell:?execution_count=13&line=6)
      [4](vscode-notebook-cell:?execution_count=13&line=4) from pprint import pprint
      [5](vscode-notebook-cell:?execution_count=13&line=5) inputs = {"question": "Who are the Bears expected to draft first in the NFL draft?"}
----> [6](vscode-notebook-cell:?execution_count=13&line=6) for output in app.stream(inputs):
      [7](vscode-notebook-cell:?execution_count=13&line=7)     print(output)
      [8](vscode-notebook-cell:?execution_count=13&line=8)     # for key, value in output.items():
      [9](vscode-notebook-cell:?execution_count=13&line=9)     #     pprint(f"Finished running: {key}:")

File /opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2436, in Pregel.stream(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, checkpoint_during, debug, subgraphs)
   [2434](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2434)         for task in loop.match_cached_writes():
   [2435](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2435)             loop.output_writes(task.id, task.writes, cached=True)
-> [2436](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2436)         for _ in runner.tick(
   [2437](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2437)             [t for t in loop.tasks.values() if not t.writes],
   [2438](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2438)             timeout=self.step_timeout,
   [2439](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2439)             get_waiter=get_waiter,
   [2440](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2440)             schedule_task=loop.accept_push,
   [2441](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2441)         ):
   [2442](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2442)             # emit output
   [2443](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2443)             yield from output()
   [2444](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/__init__.py:2444) # emit output

File /opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/runner.py:161, in PregelRunner.tick(self, tasks, reraise, timeout, retry_policy, get_waiter, schedule_task)
    [159](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/pr953/lib/python3.10/site-packages/langgraph/pregel/runner.py:159) t = tasks[0]
...
--> [108](vscode-notebook-cell:?execution_count=10&line=108) documents = state["documents"]
    [110](vscode-notebook-cell:?execution_count=10&line=110) # Web search
    [111](vscode-notebook-cell:?execution_count=10&line=111) docs = web_search_tool.invoke({"query": question})

KeyError: 'documents'

Debugging it as stand alone function works as expected:

inputs = {"question": "Who are the Bears expected to draft first in the NFL draft?"}
question = inputs['question']
web_search_tool.invoke({"query": question})
> [{'title': '10 players the Bears could pick in Round 1 of the 2025 NFL Draft',
  'url': '...

@IgorKasianenko
Copy link
Contributor

@sviswana I checked it with all small models and they result in the same issue:

ollama list
NAME                         ID              SIZE      MODIFIED          
llama3.1:latest              46e0c10c039e    4.9 GB    About an hour ago    
llama3:latest                365c0bd3c000    4.7 GB    2 days ago           
llama3.2:latest              a80c4f17acd5    2.0 GB    6 months ago   

@sviswana
Copy link
Author

yea it's super strange - b/c I'm using the small llama3.2:1b model myself

Copy link
Contributor

@IgorKasianenko IgorKasianenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

"from langchain_community.document_loaders import WebBaseLoader\n",
"from langchain_community.vectorstores import Chroma\n",
"from langchain_community.embeddings import HuggingFaceEmbeddings\n",
"from langchain_huggingface import HuggingFaceEmbeddings\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created brand new conda env to test it end to end and I am getting

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[4], line 14
      6 from langchain_huggingface import HuggingFaceEmbeddings
      8 urls = [
      9     "https://lilianweng.github.io/posts/2023-06-23-agent/",
     10     "https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/",
     11     "https://lilianweng.github.io/posts/2023-10-25-adv-attack-llm/",
     12 ]
---> 14 docs = [WebBaseLoader(url).load() for url in urls]
     15 docs_list = [item for sublist in docs for item in sublist]
     17 text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
     18     chunk_size=250, chunk_overlap=0
     19 )

Cell In[4], line 14, in <listcomp>(.0)
      6 from langchain_huggingface import HuggingFaceEmbeddings
      8 urls = [
      9     "https://lilianweng.github.io/posts/2023-06-23-agent/",
     10     "https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/",
     11     "https://lilianweng.github.io/posts/2023-10-25-adv-attack-llm/",
     12 ]
---> 14 docs = [WebBaseLoader(url).load() for url in urls]
     15 docs_list = [item for sublist in docs for item in sublist]
     17 text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
...
--> 347     from bs4 import BeautifulSoup
    349     if parser is None:
    350         if url.endswith(".xml"):

ModuleNotFoundError: No module named 'bs4'

@IgorKasianenko IgorKasianenko merged commit 3c74c5b into main Jun 3, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants