FrancescaScipioni commited on
Commit
2982e63
·
verified ·
1 Parent(s): 021c8f6

updated the graph call

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -13,21 +13,18 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
14
  # --- Basic Agent Definition ---
15
  class BasicAgent:
16
- """LangGraph Agent Wrapper"""
17
-
18
  def __init__(self):
19
  print("BasicAgent initialized.")
20
- self.graph = graph # Using graph already compiled in agent.py
21
-
22
  def __call__(self, question: str) -> str:
 
 
23
  messages = [HumanMessage(content=question)]
24
- result = self.graph.invoke({"messages": messages})
25
- final_response = result['messages'][-1].content
26
-
27
- # Assumes answer starts with "FINAL ANSWER: "
28
- if final_response.startswith("FINAL ANSWER: "):
29
- return final_response[len("FINAL ANSWER: "):].strip()
30
- return final_response.strip()
31
 
32
  def run_and_submit_all( profile: gr.OAuthProfile | None):
33
  """
 
13
 
14
  # --- Basic Agent Definition ---
15
  class BasicAgent:
16
+ """A langgraph agent."""
 
17
  def __init__(self):
18
  print("BasicAgent initialized.")
19
+ self.graph = build_graph()
20
+
21
  def __call__(self, question: str) -> str:
22
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+ # Wrap the question in a HumanMessage from langchain_core
24
  messages = [HumanMessage(content=question)]
25
+ messages = self.graph.invoke({"messages": messages})
26
+ answer = messages['messages'][-1].content
27
+ return answer[14:]
 
 
 
 
28
 
29
  def run_and_submit_all( profile: gr.OAuthProfile | None):
30
  """