Spaces:
Sleeping
Sleeping
Backup
Browse files
app.py
CHANGED
|
@@ -34,52 +34,22 @@ class BasicAgent:
|
|
| 34 |
# ==============================================================================
|
| 35 |
def test_single_question(question: str):
|
| 36 |
"""
|
| 37 |
-
Runs the agent on a single question
|
| 38 |
"""
|
| 39 |
if not question.strip():
|
| 40 |
return "Please enter a question to test."
|
| 41 |
|
| 42 |
print("--- Running Single Test ---")
|
| 43 |
try:
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# We can configure the graph to stream all intermediate steps
|
| 49 |
-
# This gives us a play-by-play of the agent's actions.
|
| 50 |
-
full_thought_process = ""
|
| 51 |
-
events = graph.stream(
|
| 52 |
-
{"messages": messages},
|
| 53 |
-
# Increase the recursion limit for debugging complex tasks
|
| 54 |
-
# but the real goal is to fix the loop, not just extend it.
|
| 55 |
-
{"recursion_limit": 50}
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
for event in events:
|
| 59 |
-
# We are interested in the 'assistant' node's output and the 'tools' node's output
|
| 60 |
-
if "assistant" in event:
|
| 61 |
-
message = event["assistant"]["messages"][-1]
|
| 62 |
-
full_thought_process += f"--- Assistant ---\n"
|
| 63 |
-
full_thought_process += f"Content: {message.content}\n"
|
| 64 |
-
if message.tool_calls:
|
| 65 |
-
full_thought_process += f"Tool Calls: {message.tool_calls}\n"
|
| 66 |
-
full_thought_process += "---\n\n"
|
| 67 |
-
|
| 68 |
-
if "tools" in event:
|
| 69 |
-
tool_outputs = event["tools"]["messages"]
|
| 70 |
-
full_thought_process += f"--- Tools Output ---\n"
|
| 71 |
-
for tool_output in tool_outputs:
|
| 72 |
-
full_thought_process += f"Tool Output: {tool_output.content}\n"
|
| 73 |
-
full_thought_process += "---\n\n"
|
| 74 |
-
|
| 75 |
print("--- Single Test Complete ---")
|
| 76 |
-
return
|
| 77 |
-
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Error during single test: {e}")
|
| 80 |
-
|
| 81 |
-
import traceback
|
| 82 |
-
return f"AGENT ERROR:\n{type(e).__name__}\n{str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
| 83 |
|
| 84 |
# ==============================================================================
|
| 85 |
|
|
@@ -145,9 +115,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 145 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 146 |
continue
|
| 147 |
try:
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 150 |
-
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer":
|
| 151 |
except Exception as e:
|
| 152 |
print(f"Error running agent on task {task_id}: {e}")
|
| 153 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
|
|
|
| 34 |
# ==============================================================================
|
| 35 |
def test_single_question(question: str):
|
| 36 |
"""
|
| 37 |
+
Runs the agent on a single question for debugging purposes.
|
| 38 |
"""
|
| 39 |
if not question.strip():
|
| 40 |
return "Please enter a question to test."
|
| 41 |
|
| 42 |
print("--- Running Single Test ---")
|
| 43 |
try:
|
| 44 |
+
# Instantiate the agent. This ensures it's fresh for the test.
|
| 45 |
+
agent = BasicAgent()
|
| 46 |
+
# Call the agent and get the raw output
|
| 47 |
+
response = agent(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
print("--- Single Test Complete ---")
|
| 49 |
+
return response
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
print(f"Error during single test: {e}")
|
| 52 |
+
return f"AGENT ERROR: {e}"
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# ==============================================================================
|
| 55 |
|
|
|
|
| 115 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 116 |
continue
|
| 117 |
try:
|
| 118 |
+
# We call the agent which now returns the full response
|
| 119 |
+
full_answer = agent(question_text)
|
| 120 |
+
|
| 121 |
+
# For submission, we slice the "FINAL ANSWER: " prefix
|
| 122 |
+
if "FINAL ANSWER: " in full_answer:
|
| 123 |
+
submitted_answer = full_answer.split("FINAL ANSWER: ")[1]
|
| 124 |
+
else:
|
| 125 |
+
submitted_answer = full_answer
|
| 126 |
+
|
| 127 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 128 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": full_answer}) # Log the full answer
|
| 129 |
except Exception as e:
|
| 130 |
print(f"Error running agent on task {task_id}: {e}")
|
| 131 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|