orbulat commited on
Commit
5afbf57
·
verified ·
1 Parent(s): cbaa3e2

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +9 -6
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 from system_prompt.txt
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 agent
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 submission agent
57
  class BasicAgent:
58
  def __init__(self):
59
- print("Initializing LangGraph GAIA Agent...")
60
  self.graph = build_graph()
61
 
62
  def __call__(self, question: str) -> str:
63
  try:
64
-
65
- return "default answer"
 
 
 
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)}"