File size: 1,233 Bytes
a5164b3
 
86166ac
2dabf6a
 
 
 
766af75
 
 
86166ac
2dabf6a
 
 
86166ac
 
 
ca81ac5
 
 
 
a5164b3
ca81ac5
 
a5164b3
 
 
 
ca81ac5
 
 
 
 
 
 
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
34
35
import os

from langchain_openai import ChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage, ToolMessage
from langgraph.graph import MessagesState
from langgraph.graph import StateGraph, START, END

from langchain_community.tools import BraveSearch  # web search
from langchain.tools import Calculator  # for basic math
from langchain.tools.python.tool import PythonAstREPLTool  # for logic/math problems

from .custom tools import (datetime_tools, transcribe_audio_tool)
from .prompt import system_prompt

# gpt-4.1-nano (cheaper for debugging) with temperature 0 for less randomness
# for benchmarking use gpt-4.1-mini or 04-mini

llm = ChatOpenAI(
    model="gpt-4.1-nano",
    temperature=0
)

calculator_tool = Calculator()
python_tool = PythonAstREPLTool()
search_tool = BraveSearch.from_api_key(
                    api_key=os.getenv("BRAVE_SEARCH_API"),
                    search_kwargs={"count": 4},  # returns the 4 best results and their URL
                    description="Web search using Brave"
)

community_tools = [calculator_tool, python_tool, search_tool]
custom_tools = [datetime_tools, transcribe_audio_tool].

tools = community_tools + custom_tools
llm_with_tools = llm.bind_tools(tools)