Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,15 +22,16 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 22 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 23 |
class BasicAgent:
|
| 24 |
def __init__(self):
|
| 25 |
-
print("Initializing
|
| 26 |
self.agent = create_langchain_agent()
|
| 27 |
|
| 28 |
def __call__(self, question: str) -> str:
|
| 29 |
try:
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Agent error: {e}"
|
| 36 |
|
|
|
|
| 22 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 23 |
class BasicAgent:
|
| 24 |
def __init__(self):
|
| 25 |
+
print("Initializing LangGraph Agent...")
|
| 26 |
self.agent = create_langchain_agent()
|
| 27 |
|
| 28 |
def __call__(self, question: str) -> str:
|
| 29 |
try:
|
| 30 |
+
# LangGraph uses a modern message-based format
|
| 31 |
+
result = self.agent.invoke({"messages": [("user", question)]})
|
| 32 |
+
|
| 33 |
+
# The final answer is the content of the very last message in the chain
|
| 34 |
+
return result["messages"][-1].content
|
| 35 |
except Exception as e:
|
| 36 |
return f"Agent error: {e}"
|
| 37 |
|