Update langgraph_agent.py
Browse files- langgraph_agent.py +13 -13
langgraph_agent.py
CHANGED
@@ -16,7 +16,8 @@ from langchain_core.messages import SystemMessage, HumanMessage
|
|
16 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
17 |
from langchain_core.tools import tool
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
@tool
|
22 |
def multiply(a: int, b: int) -> int:
|
@@ -55,18 +56,17 @@ def wiki_search(query: str) -> dict:
|
|
55 |
print(f"Error in wiki_search tool: {e}")
|
56 |
return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
)
|
62 |
@tool
|
63 |
-
def google_web_search(query: str) ->
|
64 |
try:
|
65 |
-
|
66 |
-
return
|
67 |
except Exception as e:
|
68 |
print(f"Error in google_web_search tool: {e}")
|
69 |
-
return
|
70 |
|
71 |
@tool
|
72 |
def arvix_search(query: str) -> dict:
|
@@ -191,10 +191,10 @@ def build_graph(provider: str = "gemini"):
|
|
191 |
llm_with_tools = llm.bind_tools(tools)
|
192 |
|
193 |
def assistant(state: MessagesState):
|
194 |
-
messages_to_send = [sys_msg] + state["messages"]
|
195 |
-
llm_response = llm_with_tools.invoke(messages_to_send)
|
196 |
-
print(f"LLM Raw Response: {llm_response}")
|
197 |
-
return {"messages": [llm_response]}
|
198 |
|
199 |
builder = StateGraph(MessagesState)
|
200 |
builder.add_node("assistant", assistant)
|
|
|
16 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
17 |
from langchain_core.tools import tool
|
18 |
|
19 |
+
# Correct import for GoogleSearchAPIWrapper
|
20 |
+
from langchain_google_community import GoogleSearchAPIWrapper
|
21 |
|
22 |
@tool
|
23 |
def multiply(a: int, b: int) -> int:
|
|
|
56 |
print(f"Error in wiki_search tool: {e}")
|
57 |
return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}
|
58 |
|
59 |
+
# Instantiate GoogleSearchAPIWrapper
|
60 |
+
search = GoogleSearchAPIWrapper()
|
61 |
+
|
|
|
62 |
@tool
|
63 |
+
def google_web_search(query: str) -> str:
|
64 |
try:
|
65 |
+
# Use the run method of the GoogleSearchAPIWrapper instance
|
66 |
+
return search.run(query)
|
67 |
except Exception as e:
|
68 |
print(f"Error in google_web_search tool: {e}")
|
69 |
+
return f"Error occurred while searching the web for '{query}'. Details: {str(e)}"
|
70 |
|
71 |
@tool
|
72 |
def arvix_search(query: str) -> dict:
|
|
|
191 |
llm_with_tools = llm.bind_tools(tools)
|
192 |
|
193 |
def assistant(state: MessagesState):
|
194 |
+
messages_to_send = [sys_msg] + state["messages"]
|
195 |
+
llm_response = llm_with_tools.invoke(messages_to_send)
|
196 |
+
print(f"LLM Raw Response: {llm_response}")
|
197 |
+
return {"messages": [llm_response]}
|
198 |
|
199 |
builder = StateGraph(MessagesState)
|
200 |
builder.add_node("assistant", assistant)
|