aelin commited on
Commit
e6b3fdf
·
1 Parent(s): 0056801

Adds exception handling to agent answer retrieval

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -56,19 +56,22 @@ class BasicAgent:
56
  as you want. The file name is: {file_name}.\n
57
  """
58
 
59
-
60
  # Retrieve the answer from the cache if it exists
61
- cached = get_cached_answer(task_id)
62
- if cached and cached.get("isCorrect") and cached.get("answer"):
63
- print(f"Returning cached correct answer for task_id {task_id}: {cached['answer']}")
64
-
65
- return str(cached["answer"])
66
 
67
- answer = await self.agent.run(prompt)
68
 
69
- print(f"Agent returning answer: {answer}")
70
-
71
- return str(answer)
 
 
 
72
 
73
  def instantiate_agent():
74
  try:
 
56
  as you want. The file name is: {file_name}.\n
57
  """
58
 
59
+ try:
60
  # Retrieve the answer from the cache if it exists
61
+ cached = get_cached_answer(task_id)
62
+ if cached and cached.get("isCorrect") and cached.get("answer"):
63
+ print(f"Returning cached correct answer for task_id {task_id}: {cached['answer']}")
64
+
65
+ return str(cached["answer"])
66
 
67
+ answer = await self.agent.run(prompt)
68
 
69
+ print(f"Agent returning answer: {answer}")
70
+
71
+ return str(answer)
72
+ except Exception as e:
73
+ print(f"Error running agent on question {question['task_id']}: {e}")
74
+ return "AGENT ERROR: " + str(e)
75
 
76
  def instantiate_agent():
77
  try: