Spaces:
Running on Zero
Running on Zero
Download agent/nodes.py from AliHaider1/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/AliHaider1/Final_Assignment_Template/resolve/main/agent/nodes.py
- Command line
-
hf download hf://spaces/AliHaider1/Final_Assignment_Template/agent/nodes.py
-
curl -L -o nodes.py https://huggingface.co/spaces/AliHaider1/Final_Assignment_Template/resolve/main/agent/nodes.py
1.61 kB
| import os | |
| from dotenv import load_dotenv | |
| from langchain_core.messages import SystemMessage | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| from langchain_groq import ChatGroq | |
| from .state import AgentState | |
| from .prompts import SYSTEM_PROMPT | |
| from .tools import ALL_TOOLS | |
| load_dotenv() | |
| gemini_key_1 = ChatGoogleGenerativeAI( | |
| model="gemini-3.6-flash", | |
| google_api_key=os.getenv("GOOGLE_API_KEY_1"), | |
| timeout=60, | |
| max_retries=1, | |
| ).bind_tools(ALL_TOOLS) | |
| gemini_key_2 = ChatGoogleGenerativeAI( | |
| model="gemini-3.6-flash", | |
| google_api_key=os.getenv("GOOGLE_API_KEY_2"), | |
| timeout=60, | |
| max_retries=1, | |
| ).bind_tools(ALL_TOOLS) | |
| gemini_key_3 = ChatGoogleGenerativeAI( | |
| model="gemini-3.6-flash", | |
| google_api_key=os.getenv("GOOGLE_API_KEY_3"), | |
| timeout=60, | |
| max_retries=1, | |
| ).bind_tools(ALL_TOOLS) | |
| backup_groq_120b = ChatGroq( | |
| model="openai/gpt-oss-120b", | |
| temperature=0, | |
| timeout=30, | |
| max_retries=1, | |
| ).bind_tools(ALL_TOOLS) | |
| backup_groq_qwen = ChatGroq( | |
| model="qwen/qwen3.8-27b", | |
| temperature=0, | |
| timeout=30, | |
| max_retries=1, | |
| ).bind_tools(ALL_TOOLS) | |
| llm_with_tools = gemini_key_1.with_fallbacks([ | |
| gemini_key_2, | |
| backup_groq_120b, | |
| backup_groq_qwen, | |
| ]) | |
| def assistant_node(state: AgentState) -> dict: | |
| print(f"--- Calling LLM (history length: {len(state['messages'])}) ---") | |
| messages = [SystemMessage(content=SYSTEM_PROMPT)] + state["messages"] | |
| response = llm_with_tools.invoke(messages) | |
| print(f"Tool calls: {response.tool_calls}") | |
| return {"messages": [response]} |