File size: 1,058 Bytes
33890b1
006ec78
 
33890b1
 
006ec78
4bc43c8
006ec78
33890b1
006ec78
33890b1
 
 
 
 
 
 
 
 
 
006ec78
 
90dcfc0
 
 
33890b1
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# src/langgraphagenticai/search_tool.py
from langchain_community.tools.tavily_search import TavilySearchResults
from langgraph.prebuilt import ToolNode
import os
import streamlit as st

def get_tools(max_results=3):
    """
    Returns a list of tools with configurable max_results.
    """
    try:
        tavily_api_key = os.getenv("TAVILY_API_KEY", st.session_state.get("TAVILY_API_KEY", ""))
        if not tavily_api_key:
            st.error("Error: Tavily API key not provided")
            return []
        tools = [TavilySearchResults(max_results=max_results, api_key=tavily_api_key)]
        return tools
    except Exception as e:
        st.error(f"Error initializing search tools: {e}")
        return []

def create_tool_nodes(tools):
    """
    Creates tool nodes based on the provided tools.
    """
    try:
        if not tools:
            st.error("Error: No tools provided")
            return None
        return ToolNode(tools=tools)
    except Exception as e:
        st.error(f"Error creating tool nodes: {e}")
        return None