kamorou commited on
Commit
ff483ba
·
verified ·
1 Parent(s): 29e9c5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -11,6 +11,43 @@ import pandas as pd
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
  def __init__(self):
 
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
14
+ class BasicAgent:
15
+ """
16
+ This is the agent class that the GAIA test harness will use.
17
+ """
18
+ def __init__(self):
19
+ # The compiled LangGraph app is our agent executor
20
+ self.agent_executor = app
21
+
22
+ def run(self, question: str) -> str:
23
+ """
24
+ This method is called by the test script with each question.
25
+ It runs the LangGraph agent and returns the final answer.
26
+ """
27
+ print(f"Agent received question (first 80 chars): {question[:80]}...")
28
+ try:
29
+ # Format the input for our graph
30
+ inputs = {"messages": [HumanMessage(content=question)]}
31
+
32
+ # Stream the response to get the final answer
33
+ final_response = ""
34
+ for s in self.agent_executor.stream(inputs, {"recursion_limit": 15}):
35
+ if "agent" in s:
36
+ # The final answer is the content of the last message from the agent node
37
+ if s["agent"]["messages"][-1].content:
38
+ final_response = s["agent"]["messages"][-1].content
39
+
40
+ # A fallback in case the agent finishes without a clear message
41
+ if not final_response:
42
+ final_response = "Agent finished but did not produce a final answer."
43
+
44
+ print(f"Agent returning final answer (first 80 chars): {final_response[:80]}...")
45
+ return final_response
46
+
47
+ except Exception as e:
48
+ print(f"An error occurred in agent execution: {e}")
49
+ return f"Error: {e}"
50
+
51
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
52
  class BasicAgent:
53
  def __init__(self):