""" Module for configuring and creating tools for the LangGraph agent. """ from typing import Dict, Any, List, Tuple from langchain_community.tools.tavily_search import TavilySearchResults from langchain_community.tools.arxiv.tool import ArxivQueryRun from langchain_community.tools import DuckDuckGoSearchRun from langchain_openai import ChatOpenAI def create_tools(config: Dict[str, Any]) -> Tuple[List, ChatOpenAI]: """ Create LangChain tools and model for use in the agent. Args: config: Configuration dictionary Returns: Tuple containing: - List of tools - ChatOpenAI model """ # Initialize tools with error handling try: tavily_tool = TavilySearchResults( max_results=config["tavily_max_results"], api_key=config["tavily_api_key"] ) except Exception as e: print(f"Error initializing Tavily: {e}") tavily_tool = None # Initialize ArXiv tool arxiv_tool = ArxivQueryRun() # Initialize DuckDuckGo search tool duckduckgo_tool = DuckDuckGoSearchRun() # Create the tool belt tool_belt = [] if tavily_tool: tool_belt.append(tavily_tool) if arxiv_tool: tool_belt.append(arxiv_tool) if duckduckgo_tool: tool_belt.append(duckduckgo_tool) # Initialize the OpenAI model model = ChatOpenAI( model=config["model_name"], temperature=config["temperature"], api_key=config["openai_api_key"], callbacks=None # Disable default callbacks that might cause tracing issues ) # Bind tools to the model model_with_tools = model.bind_tools(tool_belt) return tool_belt, model_with_tools