mralamdari commited on
Commit
4a85b14
·
verified ·
1 Parent(s): d30652e

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +43 -18
agent.py CHANGED
@@ -440,31 +440,56 @@ class EsiAgent:
440
 
441
  self.graph = builder.compile()
442
 
443
- def run(self, question: str) -> str:
 
 
444
  """
445
- Runs the agent end‑to‑end on a single question string and returns
446
- just the answer text (stripped of any prefix).
 
447
  """
448
- # Wrap in the same state shape your graph expects
449
  payload = {
450
  "task_id": None,
451
  "question": question,
452
- "files": [], # no attachments
453
- "level": 1 # default to Level 1
454
  }
455
- # 2) Wrap in your state object
456
- initial_state = GaiaAgentState(raw_payload=payload)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
 
458
- # initial_state = {"messages": [HumanMessage(content=question)]}
459
- # Invoke the graph
460
- final_state = self.graph.invoke(initial_state)
461
- # Extract the last message
462
- msgs = final_state["messages"]
463
- last = msgs[-1].content
464
- # If you prefix with "FINAL ANSWER: " remove that
465
- if last.startswith("FINAL ANSWER:"):
466
- return last[len("FINAL ANSWER:"):].strip()
467
- return last.strip()
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__":