Spaces:
Build error
Build error
Update langgraph_agent.py
Browse files15 unmodified lines16171819192021222332 unmodified lines56575858596061596061626363646566656667686969707172118 unmodified lines19119219319419519619719419519619719819920015 unmodified linesfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.tools import tool
from langchain_google_community.tools.Google Search import GoogleSearchResults# Correct import for GoogleSearchAPIWrapperfrom langchain_google_community import GoogleSearchAPIWrapper
@tooldef multiply(a: int, b: int) -> int:32 unmodified lines print(f"Error in wiki_search tool: {e}") return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}
Google Search_tool = GoogleSearchResults( api_key=os.getenv("GOOGLE_API_KEY"), engine_id=os.getenv("GOOGLE_CSE_ID"))# Instantiate GoogleSearchAPIWrappersearch = GoogleSearchAPIWrapper()
@tooldef google_web_search(query: str) -> dict:def google_web_search(query: str) -> str: try: docs = Google Search_tool.invoke(query) return {"google_web_results": docs} # Use the run method of the GoogleSearchAPIWrapper instance return search.run(query) except Exception as e: print(f"Error in google_web_search tool: {e}") return {"google_web_results": f"Error occurred while searching the web for '{query}'. Details: {str(e)}"} return f"Error occurred while searching the web for '{query}'. Details: {str(e)}"
@tooldef arvix_search(query: str) -> dict:118 unmodified lines llm_with_tools = llm.bind_tools(tools)
def assistant(state: MessagesState): messages_to_send = [sys_msg] + state["messages"] # This line was moved right llm_response = llm_with_tools.invoke(messages_to_send) # This line was moved right print(f"LLM Raw Response: {llm_response}") # This line was moved right return {"messages": [llm_response]} # This line was moved right messages_to_send = [sys_msg] + state["messages"] llm_response = llm_with_tools.invoke(messages_to_send) print(f"LLM Raw Response: {llm_response}") return {"messages": [llm_response]}
builder = StateGraph(MessagesState) builder.add_node("assistant", assistant)langgraph_agent.py+13-13