naman1102's picture
simplify
2871b51
raw
history blame
2.21 kB
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
import signal
# ─────────────────────────── External tools ──────────────────────────────
from tools import (
wikipedia_search_tool,
arxiv_search_tool,
audio_transcriber_tool,
excel_tool,
analyze_code_tool,
image_tool
)
# ─────────────────────────── Configuration ───────────────────────────────
MAX_TOOL_CALLS = 5
# ─────────────────────────── Helper utilities ────────────────────────────
# ─────────────────────────── Agent state ⬇ ───────────────────────────────
# ───────────────────────────── Nodes ⬇ ───────────────────────────────────
# ------------- tool adapters -------------
# ─────────────────────────── Graph wiring ───────────────────────────────
def build_graph():
"""Build and return a create_react_agent."""
llm = ChatOpenAI(model_name="gpt-4o-mini", temperature=0.3)
llm_tools = [
wikipedia_search_tool,
arxiv_search_tool,
audio_transcriber_tool,
excel_tool,
analyze_code_tool,
image_tool
]
# Create the react agent - it will use the system prompt from the messages
agent = create_react_agent(model=llm, tools=llm_tools)
return agent