Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -440,31 +440,56 @@ class EsiAgent:
|
|
| 440 |
|
| 441 |
self.graph = builder.compile()
|
| 442 |
|
| 443 |
-
|
|
|
|
|
|
|
| 444 |
"""
|
| 445 |
-
|
| 446 |
-
|
|
|
|
| 447 |
"""
|
| 448 |
-
#
|
| 449 |
payload = {
|
| 450 |
"task_id": None,
|
| 451 |
"question": question,
|
| 452 |
-
"files": [],
|
| 453 |
-
"level":
|
| 454 |
}
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
|
| 469 |
# Optional: allow running agent.py directly for quick tests
|
| 470 |
if __name__ == "__main__":
|
|
|
|
| 440 |
|
| 441 |
self.graph = builder.compile()
|
| 442 |
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
def run(self, question: str, files=None, level: int = 1) -> str:
|
| 446 |
"""
|
| 447 |
+
question: the user’s question string
|
| 448 |
+
files: optional list of file paths/URLs (default empty list)
|
| 449 |
+
level: GAIA difficulty (1,2,3)
|
| 450 |
"""
|
| 451 |
+
# 1) Build the raw_payload
|
| 452 |
payload = {
|
| 453 |
"task_id": None,
|
| 454 |
"question": question,
|
| 455 |
+
"files": files or [],
|
| 456 |
+
"level": level
|
| 457 |
}
|
| 458 |
+
|
| 459 |
+
# 2) Wrap in your custom state class
|
| 460 |
+
state = GaiaAgentState(raw_payload=payload)
|
| 461 |
+
|
| 462 |
+
# 3) Invoke the graph end-to-end
|
| 463 |
+
final_state = self.graph.invoke(state)
|
| 464 |
+
|
| 465 |
+
# 4) Pull out the final answer
|
| 466 |
+
return final_state.final_answer
|
| 467 |
+
|
| 468 |
+
# def run(self, question: str) -> str:
|
| 469 |
+
# """
|
| 470 |
+
# Runs the agent end‑to‑end on a single question string and returns
|
| 471 |
+
# just the answer text (stripped of any prefix).
|
| 472 |
+
# """
|
| 473 |
+
# # Wrap in the same state shape your graph expects
|
| 474 |
+
# payload = {
|
| 475 |
+
# "task_id": None,
|
| 476 |
+
# "question": question,
|
| 477 |
+
# "files": [], # no attachments
|
| 478 |
+
# "level": 1 # default to Level 1
|
| 479 |
+
# }
|
| 480 |
+
# # 2) Wrap in your state object
|
| 481 |
+
# initial_state = GaiaAgentState(raw_payload=payload)
|
| 482 |
|
| 483 |
+
# # initial_state = {"messages": [HumanMessage(content=question)]}
|
| 484 |
+
# # Invoke the graph
|
| 485 |
+
# final_state = self.graph.invoke(initial_state)
|
| 486 |
+
# # Extract the last message
|
| 487 |
+
# msgs = final_state["messages"]
|
| 488 |
+
# last = msgs[-1].content
|
| 489 |
+
# # If you prefix with "FINAL ANSWER: " remove that
|
| 490 |
+
# if last.startswith("FINAL ANSWER:"):
|
| 491 |
+
# return last[len("FINAL ANSWER:"):].strip()
|
| 492 |
+
# return last.strip()
|
| 493 |
|
| 494 |
# Optional: allow running agent.py directly for quick tests
|
| 495 |
if __name__ == "__main__":
|