wrigleyDan commited on
Commit
b904ff2
·
verified ·
1 Parent(s): 3be6804

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +6 -25
agent.py CHANGED
@@ -12,6 +12,7 @@ from langchain_core.tools import tool
12
  from langgraph.graph import START, StateGraph, MessagesState
13
  from langgraph.prebuilt import tools_condition
14
  from langgraph.prebuilt import ToolNode
 
15
 
16
  import requests
17
 
@@ -55,33 +56,13 @@ def search_wiki(query: str, max_results: int = 3) -> str:
55
  return json.dumps(response, indent=2)
56
 
57
 
58
- @tool
59
- def search_web(query: str, max_results: int = 3) -> str:
60
- """
61
- Searches the web for the given query and returns a maximum of 'max_results'
62
- relevant hits.
63
-
64
- Args:
65
- query (str): The search query for the web search.
66
- max_results (int): The maximum number of search results to retrieve (default is 3).
67
-
68
- Returns:
69
- str: A JSON string containing a list, where each entry
70
- represents a search result article with its snippet, title, link and other metadata.
71
- Returns an empty list if no results are found or an error occurs.
72
- """
73
- try:
74
- wrapper = DuckDuckGoSearchAPIWrapper(max_results=max_results)
75
- search = DuckDuckGoSearchResults(api_wrapper=wrapper)
76
- #search = DuckDuckGoSearchResults()
77
- results = search.invoke(query)
78
- return results
79
- except Exception as e:
80
- print(f"An error occurred during web search: {e}")
81
- return json.dumps([]) # Return an empty JSON list on error
82
 
83
  tools = [
84
- search_web,
85
  search_wiki
86
  ]
87
 
 
12
  from langgraph.graph import START, StateGraph, MessagesState
13
  from langgraph.prebuilt import tools_condition
14
  from langgraph.prebuilt import ToolNode
15
+ from langchain_tavily import TavilySearch
16
 
17
  import requests
18
 
 
56
  return json.dumps(response, indent=2)
57
 
58
 
59
+ tavily_search_tool = TavilySearch(
60
+ max_results=5,
61
+ topic="general",
62
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  tools = [
65
+ tavily_search_tool,
66
  search_wiki
67
  ]
68