File size: 1,643 Bytes
a1c1d9a
7319d31
 
 
a1c1d9a
 
7319d31
 
 
 
 
 
 
 
a1c1d9a
7319d31
a1c1d9a
7319d31
 
 
 
 
a1c1d9a
 
7319d31
 
 
a1c1d9a
 
7319d31
 
 
 
a1c1d9a
7319d31
 
 
 
 
 
 
 
 
 
 
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
# nodes/core.py (Updated to include Excel tool)
from states.state import AgentState
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from tools.langchain_tools import EXTENDED_TOOLS  # ✅ Changed from individual imports

load_dotenv()

openrouter_api_key = os.getenv("OPENROUTER_API_KEY")

if not openrouter_api_key:
    raise ValueError("OPENROUTER_API_KEY not found in environment variables")

# Initialize OpenRouter ChatOpenAI
chat = ChatOpenAI(
    model="google/gemini-2.5-pro-preview",  # Tool-compatible model
    temperature=0,
    max_retries=2,
    base_url="https://openrouter.ai/api/v1",
    api_key=openrouter_api_key,
    default_headers={
        "HTTP-Referer": "https://your-app.com",
        "X-Title": "LangGraph Agent",
    }
)

# Use EXTENDED_TOOLS which includes Excel support
tools = EXTENDED_TOOLS

chat_with_tools = chat.bind_tools(tools)

def assistant(state: AgentState):
    """Assistant node with Excel support"""
    sys_msg = (
        "You are a helpful assistant with access to tools. Understand user requests accurately. "
        "Use your tools when needed to answer effectively. Strictly follow all user instructions and constraints. "
        "Pay attention: your output needs to contain only the final answer without any reasoning since it will be "
        "strictly evaluated against a dataset which contains only the specific response. "
        "Your final output needs to be just the string or integer containing the answer, not an array or technical stuff."
    )
    
    return {
        "messages": [chat_with_tools.invoke([sys_msg] + state["messages"])]
    }