File size: 2,096 Bytes
d3b49b4
 
 
 
 
 
 
 
14fa0cc
d3b49b4
 
 
 
14fa0cc
d3b49b4
14fa0cc
d3b49b4
 
 
 
a790815
d3b49b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a790815
 
14fa0cc
 
 
 
 
 
 
a790815
14fa0cc
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import annotations
import os
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph, START, END
from langchain.schema import HumanMessage, SystemMessage, AIMessage
from state import AgentState
from typing import Any, Dict, List, Optional
import json
from langgraph.prebuilt import create_react_agent

# ─────────────────────────── External tools ──────────────────────────────
from tools import (
    wikipedia_search_tool,
    arxiv_search_tool,
    audio_transcriber_tool,
    excel_tool,
    analyze_code_tool
)

# ─────────────────────────── Configuration ───────────────────────────────

MAX_TOOL_CALLS = 5

# ─────────────────────────── Helper utilities ────────────────────────────

# ─────────────────────────── Agent state ⬇ ───────────────────────────────

# ───────────────────────────── Nodes  ⬇ ───────────────────────────────────

# ------------- tool adapters -------------


# ─────────────────────────── Graph wiring ───────────────────────────────

def build_graph():
    graph = StateGraph(AgentState)

    llm = ChatOpenAI(model_name="gpt-4.1-mini", temperature=0.3)

    llm_tools = [
        wikipedia_search_tool,
        arxiv_search_tool,
        audio_transcriber_tool,
        excel_tool,
        analyze_code_tool,
    ]
    # llm = llm.bind_tools(llm_tools)
    agent = create_react_agent(llm, llm_tools)

    return agent