Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -7,7 +7,7 @@ from langchain_core.tools import tool
|
|
| 7 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 8 |
from langchain_community.document_loaders import WikipediaLoader
|
| 9 |
|
| 10 |
-
# Load system prompt
|
| 11 |
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
| 12 |
SYSTEM_PROMPT = f.read()
|
| 13 |
|
|
@@ -26,7 +26,7 @@ def web_search(query: str) -> str:
|
|
| 26 |
|
| 27 |
tools = [wiki_search, web_search]
|
| 28 |
|
| 29 |
-
# Build LangGraph
|
| 30 |
def build_graph():
|
| 31 |
llm = ChatOpenAI(
|
| 32 |
model="gpt-4o",
|
|
@@ -53,15 +53,18 @@ def build_graph():
|
|
| 53 |
|
| 54 |
return graph.compile()
|
| 55 |
|
| 56 |
-
# Final class for
|
| 57 |
class BasicAgent:
|
| 58 |
def __init__(self):
|
| 59 |
-
print("
|
| 60 |
self.graph = build_graph()
|
| 61 |
|
| 62 |
def __call__(self, question: str) -> str:
|
| 63 |
try:
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
return f"Agent error: {str(e)}"
|
|
|
|
| 7 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 8 |
from langchain_community.document_loaders import WikipediaLoader
|
| 9 |
|
| 10 |
+
# Load system prompt
|
| 11 |
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
| 12 |
SYSTEM_PROMPT = f.read()
|
| 13 |
|
|
|
|
| 26 |
|
| 27 |
tools = [wiki_search, web_search]
|
| 28 |
|
| 29 |
+
# Build LangGraph with tools + OpenAI model
|
| 30 |
def build_graph():
|
| 31 |
llm = ChatOpenAI(
|
| 32 |
model="gpt-4o",
|
|
|
|
| 53 |
|
| 54 |
return graph.compile()
|
| 55 |
|
| 56 |
+
# Final class for integration with Gradio evaluation
|
| 57 |
class BasicAgent:
|
| 58 |
def __init__(self):
|
| 59 |
+
print("✅ LangGraph GAIA Agent initialized")
|
| 60 |
self.graph = build_graph()
|
| 61 |
|
| 62 |
def __call__(self, question: str) -> str:
|
| 63 |
try:
|
| 64 |
+
print(f"🧠 Question received: {question[:100]}")
|
| 65 |
+
messages = [HumanMessage(content=question)]
|
| 66 |
+
result = self.graph.invoke({"messages": messages})
|
| 67 |
+
final_msg = result["messages"][-1]
|
| 68 |
+
return final_msg.content.strip()
|
| 69 |
except Exception as e:
|
| 70 |
return f"Agent error: {str(e)}"
|