Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,13 +11,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
|
|
14 |
def __init__(self):
|
|
|
15 |
# graph factory lives here
|
16 |
-
self.
|
17 |
|
18 |
def __call__(self, question: str) -> str:
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
return answer.replace("FINAL ANSWER:","",1).strip()
|
22 |
|
23 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
+
"""A StateGraph-powered agent."""
|
15 |
def __init__(self):
|
16 |
+
print("BasicAgent initializing StateGraph agent...")
|
17 |
# graph factory lives here
|
18 |
+
self.agent = build_graph()
|
19 |
|
20 |
def __call__(self, question: str) -> str:
|
21 |
+
print(f"Agent received question: {question[:50]}...")
|
22 |
+
# seed initial state(empty message list
|
23 |
+
init_state = {"message": []}
|
24 |
+
# run the graph, injecting the questions
|
25 |
+
# bulid_graph() was compiled to accept (state, question=...)
|
26 |
+
result_state = self.agent.invoke(init_state, question)
|
27 |
+
# extract the final message
|
28 |
+
final_msg = result_state["messages"][-1]
|
29 |
+
answer = getattr(final_msg, "content", str(final_msg))
|
30 |
+
# strip off any "FINAL ANSWER:" prefix if present
|
31 |
return answer.replace("FINAL ANSWER:","",1).strip()
|
32 |
|
33 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|