Essi commited on
Commit
cf16b92
·
1 Parent(s): 00699b6

refactor: add debug agent for running GAIA tasks locally with improved argument handling

Browse files
Files changed (2) hide show
  1. debug_agent.py +57 -0
  2. debug_one_task.py +0 -45
debug_agent.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import textwrap
3
+ from typing import Any
4
+
5
+ import requests
6
+
7
+ from app import DEFAULT_API_URL, GAIAAgent
8
+
9
+
10
+ def fetch_question_row(task_id: str, api: str = DEFAULT_API_URL) -> dict[str, Any]:
11
+ """Return the question dict associated with *task_id* (raises if not found)."""
12
+ resp = requests.get(f"{api}/questions", timeout=15)
13
+ resp.raise_for_status()
14
+ for row in resp.json():
15
+ if row["task_id"] == task_id:
16
+ return row
17
+ raise ValueError(f"task_id '{task_id}' not present in /questions.")
18
+
19
+
20
+ def run_one(task_id: str | None, question: str | None) -> None:
21
+ agent = GAIAAgent()
22
+
23
+ if task_id:
24
+ row = fetch_question_row(task_id)
25
+ question = row["question"]
26
+ print(f"\n{row}\n") # show full row incl. metadata
27
+
28
+ # --- show pretty question
29
+ print("=" * 90)
30
+ print(f"QUESTION ({task_id or 'adhoc'})")
31
+ print(textwrap.fill(question or "", width=90))
32
+ print("=" * 90)
33
+
34
+ assert question is not None, "Internal error: question was None"
35
+ answer = agent(question, task_id=task_id)
36
+ print(f"\nFINAL ANSWER --> {answer}")
37
+
38
+
39
+ def parse_args() -> argparse.Namespace:
40
+ parser = argparse.ArgumentParser(description="Run one GAIAAgent query locally.")
41
+ parser.add_argument("--task_id", help="GAIA task_id to fetch & run")
42
+ parser.add_argument("question", nargs="?", help="Ad-hoc question text (positional)")
43
+
44
+ ns = parser.parse_args()
45
+
46
+ # mutual-exclusion checks
47
+ if ns.task_id and ns.question:
48
+ parser.error("Provide either --task_id OR a question, not both.")
49
+ if ns.task_id is None and ns.question is None:
50
+ parser.error("You must supply a GAIA --task_id or a question.")
51
+
52
+ return ns
53
+
54
+
55
+ if __name__ == "__main__":
56
+ args = parse_args()
57
+ run_one(task_id=args.task_id, question=args.question)
debug_one_task.py DELETED
@@ -1,45 +0,0 @@
1
- """
2
- Run ONE GAIA task locally through the full GAIAAgent pipeline.
3
- Shows debug prints and, if an attachment exists, saves it to disk.
4
-
5
- Usage:
6
- python debug_one_task.py <task_id>
7
- """
8
-
9
- import sys
10
- import textwrap
11
-
12
- import requests
13
-
14
- from app import DEFAULT_API_URL, GAIAAgent
15
-
16
-
17
- def fetch_question_row(task_id: str, api: str = DEFAULT_API_URL) -> dict[str, str]:
18
- """Return the question dict for the given task_id (raises if not found)."""
19
- resp = requests.get(f"{api}/questions", timeout=15)
20
- resp.raise_for_status()
21
- for row in resp.json():
22
- if row["task_id"] == task_id:
23
- print(f"\n\n{row}\n\n")
24
- return row
25
- raise ValueError(f"Task ID '{task_id}' not present in /questions endpoint.")
26
-
27
-
28
- def main(task_id: str) -> None:
29
- agent = GAIAAgent()
30
-
31
- row = fetch_question_row(task_id)
32
-
33
- print("=" * 90)
34
- print(f"QUESTION ({task_id})")
35
- print(textwrap.fill(row["question"], width=90))
36
- print("=" * 90)
37
-
38
- answer = agent(row["question"], task_id=task_id)
39
- print("\nFINAL ANSWER →", answer)
40
-
41
-
42
- if __name__ == "__main__":
43
- if len(sys.argv) != 2:
44
- sys.exit("Usage: python debug_one_task.py <task_id>")
45
- main(sys.argv[1].strip())