Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Search for weather does not work #7875

Closed
2 tasks done
avilabiel opened this issue Mar 22, 2025 · 5 comments
Closed
2 tasks done

DOC: Search for weather does not work #7875

avilabiel opened this issue Mar 22, 2025 · 5 comments
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder

Comments

@avilabiel
Copy link

Checklist

  • I added a very descriptive title to this issue.
  • I included a link to the documentation page I am referring to (if applicable).

Issue with current documentation:

I followed the given documentation for Javascript, and I didn't get the weather answer using the given code.

Code:

import * as dotenv from 'dotenv'
dotenv.config()

import { TavilySearchResults } from '@langchain/community/tools/tavily_search'
import { ChatOpenAI } from '@langchain/openai'
import { MemorySaver } from '@langchain/langgraph'
import { HumanMessage } from '@langchain/core/messages'
import { createReactAgent } from '@langchain/langgraph/prebuilt'

const main = async () => {
  // Define the tools for the agent to use
  const agentTools = [new TavilySearchResults({ maxResults: 3 })]
  const agentModel = new ChatOpenAI({ temperature: 0 })

  // Initialize memory to persist state between graph runs
  const agentCheckpointer = new MemorySaver()
  const agent = createReactAgent({
    llm: agentModel,
    tools: agentTools,
    checkpointSaver: agentCheckpointer,
  })

  // Now it's time to use!
  const agentFinalState = await agent.invoke(
    { messages: [new HumanMessage('what is the current weather in sf')] },
    { configurable: { thread_id: '42' } }
  )

  console.log(
    agentFinalState.messages[agentFinalState.messages.length - 1].content
  )

  const agentNextState = await agent.invoke(
    { messages: [new HumanMessage('what about ny')] },
    { configurable: { thread_id: '42' } }
  )

  console.log(
    agentNextState.messages[agentNextState.messages.length - 1].content
  )
}

main()

Result:

npx ts-node src/agent/agent.ts
                                                                                                                                                                             
I'm currently unable to retrieve the current weather in San Francisco. It seems there is an issue with the weather data source. Is there anything else I can assist you with?

I'm currently unable to retrieve the current weather in New York. It seems there is an issue with the weather data source. Is there anything else I can assist you with?

Documentation: https://langchain-ai.github.io/langgraphjs/tutorials/quickstart/#customizing-agent-behavior

Idea or request for content:

This is the first page of LangChain documentation, and it's frustrating that this snippet doesn't work.

Copy link

dosubot bot commented Mar 22, 2025

Hey there, @avilabiel! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this issue together!

To address the issue with the TavilySearchResults tool not retrieving weather data, here are a few steps you can take to troubleshoot and potentially resolve the problem:

  1. API Key Verification: Ensure that the Tavily API key is correctly set as an environment variable named TAVILY_API_KEY. You can verify this by checking your environment variables or by logging the value in your code to ensure it's being read correctly.

  2. Error Messages: Check for any error messages in the console output. The LangChain documentation mentions specific error messages that can help diagnose issues, such as missing API keys or request failures [1].

  3. Network Issues: Ensure that there are no network issues preventing access to the Tavily API. You can test this by making a direct API call using a tool like curl or Postman to see if the API is reachable and responding as expected.

  4. Rate Limits: Although the documentation does not specify rate limits, it's worth checking if there are any restrictions or rate limits imposed by the Tavily API that might be affecting your requests.

  5. Code Review: Double-check the code snippet for any typos or misconfigurations. Ensure that all necessary imports and initializations are correctly set up.

  6. Documentation Review: Revisit the documentation to ensure all setup steps are followed correctly, especially regarding API key setup and tool initialization [2].

If these steps do not resolve the issue, consider logging additional details from the API response to gain more insight into what might be going wrong.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot dosubot bot added the auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder label Mar 22, 2025
@avilabiel
Copy link
Author

@dosubot I checked everything that you suggested, and still, it doesn't work

Copy link

dosubot bot commented Mar 22, 2025

If you've verified the API key, checked for error messages, and ensured there are no network issues, there might be a deeper issue with the TavilySearchResults tool or its integration. Here are a few additional steps to consider:

  1. Error Handling in Code: Ensure that your code is set up to catch and log any exceptions thrown by the TavilySearchResults tool. This can provide more detailed information about what might be going wrong. The tool can throw specific errors for missing API keys, request failures, and results parsing issues [1].

  2. API Response Format: Verify that the Tavily API is returning the expected response format. The tool expects a JSON object with an array of results. If the response format has changed, it could cause parsing errors [1].

  3. Recent Changes: Check if there have been any recent updates or changes to the LangChain library or the Tavily API that might affect functionality. Sometimes, updates can introduce breaking changes that require adjustments in your code.

  4. Debugging: Add logging to capture the full API response and any intermediate steps in your code. This can help identify where the process is failing.

  5. Alternative Testing: Try using a different tool or method to fetch weather data to see if the issue is specific to the TavilySearchResults tool.

If none of these steps resolve the issue, it might be helpful to review the specific implementation details or consider reaching out to the maintainers for further assistance.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@michaelgriff
Copy link

Hi @avilabiel - took a look into this.

Just tried to reproduce the issue on my side with my own Tavily and OpenAI keys, and the response I was getting was what was expected.

Would you mind sharing the email or details on the method of authentication you used when signing up for your Tavily API key? I will look into the specific queries further and see if I can find anything that stands out.

@jacoblee93
Copy link
Collaborator

Thanks @michaelgriff!

@avilabiel can you try just hard-coding the weather tools to return a fixed response? It's possible Tavily was having some temporary difficulties.

https://js.langchain.com/docs/how_to/custom_tools/#tool-function

Going to close for now but please ping if it's recurring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder
Projects
None yet
Development

No branches or pull requests

3 participants