Nigou Julien commited on
Commit
07fb471
·
1 Parent(s): b22ac70

Build routed GAIA agent v1

Browse files
.gitignore CHANGED
@@ -6,3 +6,4 @@ __pycache__/
6
  .mypy_cache/
7
  .ruff_cache/
8
  *.egg-info/
 
 
6
  .mypy_cache/
7
  .ruff_cache/
8
  *.egg-info/
9
+ .gaia_cache/
README.md CHANGED
@@ -39,3 +39,26 @@ OPENAI_API_KEY=...
39
  ```
40
 
41
  If you run a LiteLLM proxy, set `LITELLM_API_BASE` and `LITELLM_API_KEY`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  ```
40
 
41
  If you run a LiteLLM proxy, set `LITELLM_API_BASE` and `LITELLM_API_KEY`.
42
+
43
+ ## Agent V1
44
+
45
+ The agent uses a routed LangGraph flow:
46
+
47
+ ```text
48
+ ingest_task -> classify_task -> specialized solver -> verify_answer -> normalize_final_answer
49
+ ```
50
+
51
+ Routes cover direct reasoning, computation/table questions, web search, YouTube
52
+ transcripts, spreadsheets, Python files, audio files, and image files.
53
+
54
+ For audio questions, configure a LiteLLM transcription-compatible provider. By
55
+ default the code uses `AUDIO_TRANSCRIPTION_MODEL=whisper-1` and reads
56
+ `OPENAI_API_KEY`, or you can set:
57
+
58
+ ```env
59
+ AUDIO_TRANSCRIPTION_MODEL=whisper-1
60
+ AUDIO_TRANSCRIPTION_API_KEY=...
61
+ AUDIO_TRANSCRIPTION_API_BASE=...
62
+ ```
63
+
64
+ For image questions, use a vision-capable `LITELLM_MODEL`.
app.py CHANGED
@@ -74,6 +74,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
74
  for item in questions_data:
75
  task_id = item.get("task_id")
76
  question_text = item.get("question")
 
 
77
  if not task_id or question_text is None:
78
  print(f"Skipping item with missing task_id or question: {item}")
79
  continue
@@ -83,12 +85,32 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
83
  session_id=session_id,
84
  user_id=username.strip(),
85
  task_id=task_id,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  )
87
- answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
88
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
89
  except Exception as e:
90
- print(f"Error running agent on task {task_id}: {e}")
91
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
 
 
 
 
 
 
 
92
 
93
  if not answers_payload:
94
  print("Agent did not produce any answers to submit.")
 
74
  for item in questions_data:
75
  task_id = item.get("task_id")
76
  question_text = item.get("question")
77
+ file_name = item.get("file_name") or ""
78
+ level = item.get("Level") or ""
79
  if not task_id or question_text is None:
80
  print(f"Skipping item with missing task_id or question: {item}")
81
  continue
 
85
  session_id=session_id,
86
  user_id=username.strip(),
87
  task_id=task_id,
88
+ file_name=file_name,
89
+ level=level,
90
+ )
91
+ answers_payload.append(
92
+ {"task_id": task_id, "submitted_answer": submitted_answer}
93
+ )
94
+ results_log.append(
95
+ {
96
+ "Task ID": task_id,
97
+ "Level": level,
98
+ "File": file_name,
99
+ "Question": question_text,
100
+ "Submitted Answer": submitted_answer,
101
+ }
102
  )
 
 
103
  except Exception as e:
104
+ print(f"Error running agent on task {task_id}: {e}")
105
+ results_log.append(
106
+ {
107
+ "Task ID": task_id,
108
+ "Level": level,
109
+ "File": file_name,
110
+ "Question": question_text,
111
+ "Submitted Answer": f"AGENT ERROR: {e}",
112
+ }
113
+ )
114
 
115
  if not answers_payload:
116
  print("Agent did not produce any answers to submit.")
gaia_agent/agent.py CHANGED
@@ -14,6 +14,9 @@ class GaiaAgent:
14
  session_id: str | None = None,
15
  user_id: str | None = None,
16
  task_id: str | None = None,
 
 
 
17
  ) -> str:
18
  print(f"Agent received question (first 80 chars): {question[:80]}...")
19
  with trace_agent_run(
@@ -23,7 +26,15 @@ class GaiaAgent:
23
  task_id=task_id,
24
  ) as trace:
25
  graph = build_graph(trace=trace, llm=self.llm)
26
- result = graph.invoke({"question": question})
 
 
 
 
 
 
 
 
27
  final_answer = result["final_answer"]
28
  print(f"Agent returning answer: {final_answer}")
29
  return final_answer
 
14
  session_id: str | None = None,
15
  user_id: str | None = None,
16
  task_id: str | None = None,
17
+ file_name: str | None = None,
18
+ file_path: str | None = None,
19
+ level: str | None = None,
20
  ) -> str:
21
  print(f"Agent received question (first 80 chars): {question[:80]}...")
22
  with trace_agent_run(
 
26
  task_id=task_id,
27
  ) as trace:
28
  graph = build_graph(trace=trace, llm=self.llm)
29
+ initial_state = {
30
+ "question": question,
31
+ "task_id": task_id or "",
32
+ "file_name": file_name or "",
33
+ "level": level or "",
34
+ }
35
+ if file_path:
36
+ initial_state["file_path"] = file_path
37
+ result = graph.invoke(initial_state)
38
  final_answer = result["final_answer"]
39
  print(f"Agent returning answer: {final_answer}")
40
  return final_answer
gaia_agent/answer.py CHANGED
@@ -1,3 +1,30 @@
 
 
 
1
  def normalize_answer(answer: str) -> str:
2
  """Apply minimal GAIA answer cleanup without changing meaning."""
3
- return answer.strip().removesuffix(".")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+
4
  def normalize_answer(answer: str) -> str:
5
  """Apply minimal GAIA answer cleanup without changing meaning."""
6
+ cleaned = str(answer).strip()
7
+
8
+ final_answer_match = re.search(
9
+ r"FINAL\s+ANSWER\s*:\s*(.+)\s*$",
10
+ cleaned,
11
+ flags=re.IGNORECASE | re.DOTALL,
12
+ )
13
+ if final_answer_match:
14
+ cleaned = final_answer_match.group(1).strip()
15
+
16
+ cleaned = cleaned.strip("` \n\t")
17
+ cleaned = cleaned.strip()
18
+ if (
19
+ len(cleaned) >= 2
20
+ and cleaned[0] == cleaned[-1]
21
+ and cleaned[0] in {"'", '"'}
22
+ ):
23
+ cleaned = cleaned[1:-1].strip()
24
+
25
+ cleaned = cleaned.removesuffix(".").strip()
26
+
27
+ if re.fullmatch(r"\$?-?\d[\d,]*(?:\.\d+)?", cleaned):
28
+ cleaned = cleaned.removeprefix("$").replace(",", "")
29
+
30
+ return cleaned
gaia_agent/graph.py CHANGED
@@ -1,38 +1,454 @@
 
 
 
 
 
 
 
1
  from langgraph.graph import END, StateGraph
2
 
3
  from gaia_agent.answer import normalize_answer
 
4
  from gaia_agent.llms import create_chat_model
5
  from gaia_agent.observability import traced_step
6
- from gaia_agent.prompts import DUMMY_LLM_TEST_PROMPT
 
 
 
 
7
  from gaia_agent.state import GaiaState
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  def build_graph(trace=None, llm=None):
11
  graph = StateGraph(GaiaState)
12
  chat_model = llm or create_chat_model()
13
 
14
- def draft_answer(state: GaiaState) -> GaiaState:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def run() -> dict[str, str]:
16
- response = chat_model.invoke(
17
- [
18
- ("system", DUMMY_LLM_TEST_PROMPT),
19
- ("user", state["question"]),
20
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  )
22
- return {"draft_answer": str(response.content)}
 
 
23
 
24
- return traced_step(trace, "draft_answer", run)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- def normalize_final_answer(state: GaiaState) -> GaiaState:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def run() -> dict[str, str]:
28
- return {"final_answer": normalize_answer(state["draft_answer"])}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  return traced_step(trace, "normalize_final_answer", run)
31
 
32
- graph.add_node("draft_answer", draft_answer)
 
 
 
 
 
 
 
 
 
 
33
  graph.add_node("normalize_final_answer", normalize_final_answer)
34
- graph.set_entry_point("draft_answer")
35
- graph.add_edge("draft_answer", "normalize_final_answer")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  graph.add_edge("normalize_final_answer", END)
37
 
38
  return graph.compile()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from langchain_core.messages import HumanMessage, SystemMessage
8
  from langgraph.graph import END, StateGraph
9
 
10
  from gaia_agent.answer import normalize_answer
11
+ from gaia_agent.config import settings
12
  from gaia_agent.llms import create_chat_model
13
  from gaia_agent.observability import traced_step
14
+ from gaia_agent.prompts import (
15
+ GAIA_AGENT_SYSTEM_PROMPT,
16
+ GAIA_QUERY_PROMPT,
17
+ GAIA_VERIFY_PROMPT,
18
+ )
19
  from gaia_agent.state import GaiaState
20
+ from gaia_agent.tools.files import (
21
+ download_task_file,
22
+ read_text_file,
23
+ summarize_spreadsheet,
24
+ )
25
+ from gaia_agent.tools.media import image_data_url, transcribe_audio_file
26
+ from gaia_agent.tools.python_repl import run_python_file
27
+ from gaia_agent.tools.web import (
28
+ extract_urls,
29
+ fetch_url,
30
+ get_youtube_transcript,
31
+ web_search,
32
+ )
33
+
34
+
35
+ MAX_EVIDENCE_CHARS = 36_000
36
+ MAX_WEB_PAGES = 4
37
 
38
 
39
  def build_graph(trace=None, llm=None):
40
  graph = StateGraph(GaiaState)
41
  chat_model = llm or create_chat_model()
42
 
43
+ def ingest_task(state: GaiaState) -> dict[str, Any]:
44
+ def run() -> dict[str, Any]:
45
+ evidence = list(state.get("evidence", []))
46
+ output: dict[str, Any] = {
47
+ "evidence": evidence,
48
+ "tool_outputs": list(state.get("tool_outputs", [])),
49
+ }
50
+ if state.get("file_path") or not state.get("file_name"):
51
+ return output
52
+
53
+ try:
54
+ path = download_task_file(
55
+ settings.gaia_api_url,
56
+ state["task_id"],
57
+ state.get("file_name"),
58
+ )
59
+ output["file_path"] = str(path)
60
+ evidence.append(f"Downloaded attached file to {path}.")
61
+ except Exception as exc:
62
+ evidence.append(f"Could not download attached file: {exc}")
63
+ output["error"] = str(exc)
64
+ return output
65
+
66
+ return traced_step(trace, "ingest_task", run)
67
+
68
+ def classify_task(state: GaiaState) -> dict[str, str]:
69
  def run() -> dict[str, str]:
70
+ question = state["question"].lower()
71
+ file_name = state.get("file_name", "").lower()
72
+
73
+ if file_name.endswith((".xlsx", ".xls", ".csv")):
74
+ task_type = "spreadsheet"
75
+ elif file_name.endswith(".py"):
76
+ task_type = "python_file"
77
+ elif file_name.endswith((".mp3", ".wav", ".m4a", ".ogg", ".flac")):
78
+ task_type = "audio"
79
+ elif file_name.endswith((".png", ".jpg", ".jpeg", ".webp")):
80
+ task_type = "image"
81
+ elif "youtube.com" in question or "youtu.be" in question:
82
+ task_type = "youtube"
83
+ elif _looks_like_computation(question):
84
+ task_type = "compute"
85
+ elif _looks_like_direct(question):
86
+ task_type = "direct"
87
+ else:
88
+ task_type = "web"
89
+ return {"task_type": task_type}
90
+
91
+ return traced_step(trace, "classify_task", run)
92
+
93
+ def solve_direct(state: GaiaState) -> dict[str, Any]:
94
+ def run() -> dict[str, Any]:
95
+ answer = _invoke_text(
96
+ chat_model,
97
+ GAIA_AGENT_SYSTEM_PROMPT,
98
+ f"Question:\n{state['question']}",
99
+ )
100
+ return {"draft_answer": answer}
101
+
102
+ return traced_step(trace, "solve_direct", run)
103
+
104
+ def solve_compute(state: GaiaState) -> dict[str, Any]:
105
+ def run() -> dict[str, Any]:
106
+ answer = _invoke_text(
107
+ chat_model,
108
+ GAIA_AGENT_SYSTEM_PROMPT,
109
+ (
110
+ "Solve this question carefully. If it includes a table or "
111
+ "formal rule, compute the requested value exactly.\n\n"
112
+ f"Question:\n{state['question']}"
113
+ ),
114
+ )
115
+ return {"draft_answer": answer}
116
+
117
+ return traced_step(trace, "solve_compute", run)
118
+
119
+ def solve_spreadsheet(state: GaiaState) -> dict[str, Any]:
120
+ def run() -> dict[str, Any]:
121
+ evidence = list(state.get("evidence", []))
122
+ path = state.get("file_path")
123
+ if not path:
124
+ evidence.append("Attached spreadsheet is unavailable.")
125
+ answer = _invoke_text(
126
+ chat_model,
127
+ GAIA_AGENT_SYSTEM_PROMPT,
128
+ _question_with_evidence(state["question"], evidence),
129
+ )
130
+ return {"evidence": evidence, "draft_answer": answer}
131
+
132
+ summary = summarize_spreadsheet(path)
133
+ evidence.append(f"Spreadsheet summary:\n{summary}")
134
+ answer = _invoke_text(
135
+ chat_model,
136
+ GAIA_AGENT_SYSTEM_PROMPT,
137
+ _question_with_evidence(state["question"], evidence),
138
+ )
139
+ return {"evidence": evidence, "draft_answer": answer}
140
+
141
+ return traced_step(trace, "solve_spreadsheet", run)
142
+
143
+ def solve_python_file(state: GaiaState) -> dict[str, Any]:
144
+ def run() -> dict[str, Any]:
145
+ evidence = list(state.get("evidence", []))
146
+ path = state.get("file_path")
147
+ if not path:
148
+ evidence.append("Attached Python file is unavailable.")
149
+ answer = _invoke_text(
150
+ chat_model,
151
+ GAIA_AGENT_SYSTEM_PROMPT,
152
+ _question_with_evidence(state["question"], evidence),
153
+ )
154
+ return {"evidence": evidence, "draft_answer": answer}
155
+
156
+ source = read_text_file(path, max_chars=30_000)
157
+ result = run_python_file(path)
158
+ evidence.append(f"Attached Python source:\n{source}")
159
+ evidence.append(
160
+ "Python execution result:\n"
161
+ f"exit_code={result['exit_code']}\n"
162
+ f"stdout:\n{result['stdout']}\n"
163
+ f"stderr:\n{result['stderr']}"
164
+ )
165
+
166
+ stdout = str(result.get("stdout", "")).strip()
167
+ if stdout and not str(result.get("stderr", "")).strip():
168
+ draft = stdout.splitlines()[-1]
169
+ verified = draft
170
+ else:
171
+ draft = _invoke_text(
172
+ chat_model,
173
+ GAIA_AGENT_SYSTEM_PROMPT,
174
+ _question_with_evidence(state["question"], evidence),
175
+ )
176
+ verified = ""
177
+ output = {"evidence": evidence, "draft_answer": draft}
178
+ if verified:
179
+ output["verified_answer"] = verified
180
+ return output
181
+
182
+ return traced_step(trace, "solve_python_file", run)
183
+
184
+ def solve_audio(state: GaiaState) -> dict[str, Any]:
185
+ def run() -> dict[str, Any]:
186
+ evidence = list(state.get("evidence", []))
187
+ path = state.get("file_path")
188
+ if not path:
189
+ evidence.append("Attached audio file is unavailable.")
190
+ else:
191
+ try:
192
+ transcript = transcribe_audio_file(path)
193
+ evidence.append(f"Audio transcript:\n{transcript}")
194
+ except Exception as exc:
195
+ evidence.append(f"Audio transcription failed: {exc}")
196
+
197
+ answer = _invoke_text(
198
+ chat_model,
199
+ GAIA_AGENT_SYSTEM_PROMPT,
200
+ _question_with_evidence(state["question"], evidence),
201
  )
202
+ return {"evidence": evidence, "draft_answer": answer}
203
+
204
+ return traced_step(trace, "solve_audio", run)
205
 
206
+ def solve_image(state: GaiaState) -> dict[str, Any]:
207
+ def run() -> dict[str, Any]:
208
+ evidence = list(state.get("evidence", []))
209
+ path = state.get("file_path")
210
+ if path:
211
+ try:
212
+ answer = _invoke_image(chat_model, state["question"], path)
213
+ evidence.append(f"Image analyzed from {path}.")
214
+ except Exception as exc:
215
+ evidence.append(f"Image analysis failed: {exc}")
216
+ answer = _invoke_text(
217
+ chat_model,
218
+ GAIA_AGENT_SYSTEM_PROMPT,
219
+ _question_with_evidence(state["question"], evidence),
220
+ )
221
+ else:
222
+ evidence.append("Attached image file is unavailable.")
223
+ answer = _invoke_text(
224
+ chat_model,
225
+ GAIA_AGENT_SYSTEM_PROMPT,
226
+ _question_with_evidence(state["question"], evidence),
227
+ )
228
+ return {"evidence": evidence, "draft_answer": answer}
229
+
230
+ return traced_step(trace, "solve_image", run)
231
+
232
+ def solve_youtube(state: GaiaState) -> dict[str, Any]:
233
+ def run() -> dict[str, Any]:
234
+ evidence = list(state.get("evidence", []))
235
+ urls = extract_urls(state["question"])
236
+ for url in urls:
237
+ if "youtube.com" not in url and "youtu.be" not in url:
238
+ continue
239
+ try:
240
+ transcript = get_youtube_transcript(url)
241
+ evidence.append(f"YouTube transcript for {url}:\n{transcript}")
242
+ except Exception as exc:
243
+ evidence.append(f"YouTube transcript failed for {url}: {exc}")
244
+
245
+ answer = _invoke_text(
246
+ chat_model,
247
+ GAIA_AGENT_SYSTEM_PROMPT,
248
+ _question_with_evidence(state["question"], evidence),
249
+ )
250
+ return {"evidence": evidence, "draft_answer": answer}
251
 
252
+ return traced_step(trace, "solve_youtube", run)
253
+
254
+ def solve_web(state: GaiaState) -> dict[str, Any]:
255
+ def run() -> dict[str, Any]:
256
+ evidence = list(state.get("evidence", []))
257
+ queries = _build_search_queries(chat_model, state["question"])
258
+ seen_urls: set[str] = set()
259
+
260
+ for query in queries:
261
+ try:
262
+ results = web_search(query, max_results=5)
263
+ except Exception as exc:
264
+ evidence.append(f"Search failed for {query!r}: {exc}")
265
+ continue
266
+
267
+ if results:
268
+ evidence.append(
269
+ "Search results for "
270
+ f"{query!r}:\n"
271
+ + "\n".join(f"- {item.title}: {item.url}" for item in results)
272
+ )
273
+
274
+ for result in results:
275
+ if len(seen_urls) >= MAX_WEB_PAGES:
276
+ break
277
+ if result.url in seen_urls:
278
+ continue
279
+ seen_urls.add(result.url)
280
+ try:
281
+ page_text = fetch_url(result.url, max_chars=12_000)
282
+ except Exception as exc:
283
+ evidence.append(f"Fetch failed for {result.url}: {exc}")
284
+ continue
285
+ evidence.append(f"Page: {result.title}\nURL: {result.url}\n{page_text}")
286
+
287
+ answer = _invoke_text(
288
+ chat_model,
289
+ GAIA_AGENT_SYSTEM_PROMPT,
290
+ _question_with_evidence(state["question"], evidence),
291
+ )
292
+ return {"evidence": evidence, "draft_answer": answer}
293
+
294
+ return traced_step(trace, "solve_web", run)
295
+
296
+ def verify_answer(state: GaiaState) -> dict[str, str]:
297
  def run() -> dict[str, str]:
298
+ if state.get("verified_answer"):
299
+ return {"verified_answer": state["verified_answer"]}
300
+
301
+ evidence = _trim_evidence(state.get("evidence", []))
302
+ verified = _invoke_text(
303
+ chat_model,
304
+ GAIA_VERIFY_PROMPT,
305
+ (
306
+ f"Question:\n{state['question']}\n\n"
307
+ f"Evidence:\n{evidence}\n\n"
308
+ f"Draft answer:\n{state.get('draft_answer', '')}"
309
+ ),
310
+ )
311
+ return {"verified_answer": verified}
312
+
313
+ return traced_step(trace, "verify_answer", run)
314
+
315
+ def normalize_final_answer(state: GaiaState) -> dict[str, str]:
316
+ def run() -> dict[str, str]:
317
+ answer = state.get("verified_answer") or state.get("draft_answer", "")
318
+ return {"final_answer": normalize_answer(answer)}
319
 
320
  return traced_step(trace, "normalize_final_answer", run)
321
 
322
+ graph.add_node("ingest_task", ingest_task)
323
+ graph.add_node("classify_task", classify_task)
324
+ graph.add_node("solve_direct", solve_direct)
325
+ graph.add_node("solve_compute", solve_compute)
326
+ graph.add_node("solve_spreadsheet", solve_spreadsheet)
327
+ graph.add_node("solve_python_file", solve_python_file)
328
+ graph.add_node("solve_audio", solve_audio)
329
+ graph.add_node("solve_image", solve_image)
330
+ graph.add_node("solve_youtube", solve_youtube)
331
+ graph.add_node("solve_web", solve_web)
332
+ graph.add_node("verify_answer", verify_answer)
333
  graph.add_node("normalize_final_answer", normalize_final_answer)
334
+
335
+ graph.set_entry_point("ingest_task")
336
+ graph.add_edge("ingest_task", "classify_task")
337
+ graph.add_conditional_edges(
338
+ "classify_task",
339
+ lambda state: state.get("task_type", "web"),
340
+ {
341
+ "direct": "solve_direct",
342
+ "compute": "solve_compute",
343
+ "spreadsheet": "solve_spreadsheet",
344
+ "python_file": "solve_python_file",
345
+ "audio": "solve_audio",
346
+ "image": "solve_image",
347
+ "youtube": "solve_youtube",
348
+ "web": "solve_web",
349
+ },
350
+ )
351
+ for node in (
352
+ "solve_direct",
353
+ "solve_compute",
354
+ "solve_spreadsheet",
355
+ "solve_python_file",
356
+ "solve_audio",
357
+ "solve_image",
358
+ "solve_youtube",
359
+ "solve_web",
360
+ ):
361
+ graph.add_edge(node, "verify_answer")
362
+ graph.add_edge("verify_answer", "normalize_final_answer")
363
  graph.add_edge("normalize_final_answer", END)
364
 
365
  return graph.compile()
366
+
367
+
368
+ def _invoke_text(chat_model, system_prompt: str, user_prompt: str) -> str:
369
+ response = chat_model.invoke(
370
+ [
371
+ ("system", system_prompt),
372
+ ("user", user_prompt),
373
+ ]
374
+ )
375
+ return str(response.content)
376
+
377
+
378
+ def _invoke_image(chat_model, question: str, path: str | Path) -> str:
379
+ response = chat_model.invoke(
380
+ [
381
+ SystemMessage(content=GAIA_AGENT_SYSTEM_PROMPT),
382
+ HumanMessage(
383
+ content=[
384
+ {"type": "text", "text": question},
385
+ {
386
+ "type": "image_url",
387
+ "image_url": {"url": image_data_url(path)},
388
+ },
389
+ ]
390
+ ),
391
+ ]
392
+ )
393
+ return str(response.content)
394
+
395
+
396
+ def _build_search_queries(chat_model, question: str) -> list[str]:
397
+ raw_queries = _invoke_text(
398
+ chat_model,
399
+ GAIA_QUERY_PROMPT,
400
+ f"Question:\n{question}",
401
+ )
402
+ queries = [
403
+ re.sub(r"^\s*[-*\d.)]+\s*", "", line).strip()
404
+ for line in raw_queries.splitlines()
405
+ if line.strip()
406
+ ]
407
+ queries = [query.strip("\"'") for query in queries if len(query.strip("\"'")) > 3]
408
+ if question not in queries:
409
+ queries.append(question)
410
+ return queries[:3]
411
+
412
+
413
+ def _question_with_evidence(question: str, evidence: list[str]) -> str:
414
+ return f"Question:\n{question}\n\nEvidence:\n{_trim_evidence(evidence)}"
415
+
416
+
417
+ def _trim_evidence(evidence: list[str]) -> str:
418
+ text = "\n\n---\n\n".join(evidence)
419
+ if len(text) <= MAX_EVIDENCE_CHARS:
420
+ return text
421
+ return f"{text[:MAX_EVIDENCE_CHARS]}\n\n[trimmed after {MAX_EVIDENCE_CHARS} chars]"
422
+
423
+
424
+ def _looks_like_computation(question: str) -> bool:
425
+ markers = (
426
+ "given this table",
427
+ "provide the subset",
428
+ "counter-examples",
429
+ "not commutative",
430
+ "calculate",
431
+ "numeric output",
432
+ )
433
+ return any(marker in question for marker in markers)
434
+
435
+
436
+ def _looks_like_direct(question: str) -> bool:
437
+ if question.count(" ") <= 8:
438
+ return True
439
+ if _looks_reversed(question):
440
+ return True
441
+ direct_markers = (
442
+ "grocery list",
443
+ "categorizing things",
444
+ "write the opposite",
445
+ )
446
+ return any(marker in question for marker in direct_markers)
447
+
448
+
449
+ def _looks_reversed(question: str) -> bool:
450
+ words = re.findall(r"[a-z]{4,}", question)
451
+ if len(words) < 3:
452
+ return False
453
+ reversed_common = {"rewsna", "drow", "etirw", "ecnetnes", "dnatsrednu"}
454
+ return len(reversed_common.intersection(words)) >= 2
gaia_agent/prompts.py CHANGED
@@ -5,6 +5,35 @@ list of numbers and/or strings.
5
  """.strip()
6
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  DUMMY_LLM_TEST_PROMPT = """
9
  You are testing the LLM connection for a GAIA agent.
10
  Answer the user question directly in a few words.
 
5
  """.strip()
6
 
7
 
8
+ GAIA_AGENT_SYSTEM_PROMPT = """
9
+ You are a GAIA benchmark assistant.
10
+ Answer real-world questions by using the provided evidence and tool output.
11
+
12
+ Rules:
13
+ - Give only the final answer, with no explanation.
14
+ - Keep the answer as short as possible.
15
+ - If the answer is numeric, do not include units unless the question explicitly asks for them.
16
+ - If the answer is a list, use a comma-separated list.
17
+ - Do not invent facts that are not supported by evidence.
18
+ """.strip()
19
+
20
+
21
+ GAIA_QUERY_PROMPT = """
22
+ Create up to three concise web search queries that would help answer the GAIA
23
+ question. Return only the queries, one per line, without numbering.
24
+ """.strip()
25
+
26
+
27
+ GAIA_VERIFY_PROMPT = """
28
+ You are checking a GAIA answer before submission.
29
+ Use the question, evidence, and draft answer to produce the final answer.
30
+ If the draft answer was computed directly by a tool, preserve it unless the
31
+ evidence clearly contradicts it.
32
+
33
+ Return only the final answer. Do not include reasoning or a prefix.
34
+ """.strip()
35
+
36
+
37
  DUMMY_LLM_TEST_PROMPT = """
38
  You are testing the LLM connection for a GAIA agent.
39
  Answer the user question directly in a few words.
gaia_agent/state.py CHANGED
@@ -1,7 +1,16 @@
1
- from typing import TypedDict
2
 
3
 
4
  class GaiaState(TypedDict, total=False):
 
5
  question: str
 
 
 
 
 
 
6
  draft_answer: str
 
7
  final_answer: str
 
 
1
+ from typing import Any, TypedDict
2
 
3
 
4
  class GaiaState(TypedDict, total=False):
5
+ task_id: str
6
  question: str
7
+ file_name: str
8
+ file_path: str
9
+ level: str
10
+ task_type: str
11
+ evidence: list[str]
12
+ tool_outputs: list[dict[str, Any]]
13
  draft_answer: str
14
+ verified_answer: str
15
  final_answer: str
16
+ error: str
gaia_agent/tools/files.py CHANGED
@@ -1 +1,91 @@
1
- """File-reading tools will live here."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import mimetypes
4
+ from pathlib import Path
5
+ from urllib.parse import urlparse
6
+
7
+ import pandas as pd
8
+ import requests
9
+
10
+
11
+ DEFAULT_CACHE_DIR = Path(".gaia_cache") / "files"
12
+
13
+
14
+ def download_task_file(
15
+ api_url: str,
16
+ task_id: str,
17
+ file_name: str | None = None,
18
+ *,
19
+ cache_dir: Path = DEFAULT_CACHE_DIR,
20
+ timeout: int = 60,
21
+ ) -> Path:
22
+ """Download the file associated with a GAIA task ID into a local cache."""
23
+ cache_dir.mkdir(parents=True, exist_ok=True)
24
+ target_name = file_name or task_id
25
+ target_path = cache_dir / Path(target_name).name
26
+ if target_path.exists() and target_path.stat().st_size > 0:
27
+ return target_path
28
+
29
+ response = requests.get(
30
+ f"{api_url.rstrip('/')}/files/{task_id}",
31
+ timeout=timeout,
32
+ )
33
+ response.raise_for_status()
34
+
35
+ content_type = response.headers.get("content-type", "")
36
+ if "application/json" in content_type:
37
+ detail = response.json().get("detail", "unknown file download error")
38
+ raise FileNotFoundError(detail)
39
+
40
+ if not file_name:
41
+ suffix = _suffix_from_content_type(content_type)
42
+ target_path = cache_dir / f"{task_id}{suffix}"
43
+
44
+ target_path.write_bytes(response.content)
45
+ return target_path
46
+
47
+
48
+ def read_text_file(path: str | Path, *, max_chars: int = 20_000) -> str:
49
+ text = Path(path).read_text(encoding="utf-8", errors="replace")
50
+ if len(text) <= max_chars:
51
+ return text
52
+ return f"{text[:max_chars]}\n\n[truncated after {max_chars} characters]"
53
+
54
+
55
+ def summarize_spreadsheet(path: str | Path, *, max_rows: int = 12) -> str:
56
+ """Return a compact textual summary of all sheets in a spreadsheet."""
57
+ file_path = Path(path)
58
+ if file_path.suffix.lower() == ".csv":
59
+ workbook = {file_path.stem: pd.read_csv(file_path)}
60
+ else:
61
+ workbook = pd.read_excel(file_path, sheet_name=None)
62
+ sections: list[str] = []
63
+ for sheet_name, dataframe in workbook.items():
64
+ sections.append(f"Sheet: {sheet_name}")
65
+ sections.append(f"Shape: {dataframe.shape[0]} rows x {dataframe.shape[1]} columns")
66
+ sections.append(f"Columns: {', '.join(map(str, dataframe.columns))}")
67
+
68
+ numeric_sums = dataframe.select_dtypes(include="number").sum(numeric_only=True)
69
+ if not numeric_sums.empty:
70
+ sums = ", ".join(
71
+ f"{column}={value}" for column, value in numeric_sums.items()
72
+ )
73
+ sections.append(f"Numeric column sums: {sums}")
74
+
75
+ preview = dataframe.head(max_rows).to_csv(index=False)
76
+ sections.append(f"Preview CSV:\n{preview.strip()}")
77
+ return "\n\n".join(sections)
78
+
79
+
80
+ def _suffix_from_content_type(content_type: str) -> str:
81
+ media_type = content_type.split(";", 1)[0].strip()
82
+ guessed = mimetypes.guess_extension(media_type)
83
+ if guessed:
84
+ return guessed
85
+
86
+ parsed = urlparse(media_type)
87
+ if parsed.path:
88
+ suffix = Path(parsed.path).suffix
89
+ if suffix:
90
+ return suffix
91
+ return ".bin"
gaia_agent/tools/media.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import base64
4
+ import mimetypes
5
+ import os
6
+ from pathlib import Path
7
+
8
+
9
+ def transcribe_audio_file(path: str | Path) -> str:
10
+ """Transcribe an audio file with LiteLLM's transcription API."""
11
+ model = os.getenv("AUDIO_TRANSCRIPTION_MODEL", "whisper-1")
12
+ api_key = os.getenv("AUDIO_TRANSCRIPTION_API_KEY") or os.getenv("OPENAI_API_KEY")
13
+ api_base = os.getenv("AUDIO_TRANSCRIPTION_API_BASE")
14
+
15
+ try:
16
+ import litellm
17
+ except ImportError as exc:
18
+ raise RuntimeError("litellm is required for audio transcription.") from exc
19
+
20
+ with Path(path).open("rb") as audio:
21
+ result = litellm.transcription(
22
+ model=model,
23
+ file=audio,
24
+ api_key=api_key,
25
+ api_base=api_base,
26
+ response_format="json",
27
+ )
28
+
29
+ if isinstance(result, str):
30
+ return result
31
+ if isinstance(result, dict):
32
+ return str(result.get("text", result))
33
+ return str(getattr(result, "text", result))
34
+
35
+
36
+ def image_data_url(path: str | Path) -> str:
37
+ image_path = Path(path)
38
+ media_type = mimetypes.guess_type(image_path.name)[0] or "image/png"
39
+ payload = base64.b64encode(image_path.read_bytes()).decode("ascii")
40
+ return f"data:{media_type};base64,{payload}"
gaia_agent/tools/python_repl.py CHANGED
@@ -1 +1,47 @@
1
- """Python execution tools will live here."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+ import sys
5
+ import tempfile
6
+ from pathlib import Path
7
+
8
+
9
+ def run_python_file(path: str | Path, *, timeout: int = 20) -> dict[str, str | int]:
10
+ file_path = Path(path)
11
+ return _run_python([str(file_path)], cwd=file_path.parent, timeout=timeout)
12
+
13
+
14
+ def run_python_code(code: str, *, timeout: int = 20) -> dict[str, str | int]:
15
+ with tempfile.TemporaryDirectory(prefix="gaia-python-") as tmpdir:
16
+ file_path = Path(tmpdir) / "snippet.py"
17
+ file_path.write_text(code, encoding="utf-8")
18
+ return _run_python([str(file_path)], cwd=Path(tmpdir), timeout=timeout)
19
+
20
+
21
+ def _run_python(
22
+ args: list[str],
23
+ *,
24
+ cwd: Path,
25
+ timeout: int,
26
+ ) -> dict[str, str | int]:
27
+ try:
28
+ completed = subprocess.run(
29
+ [sys.executable, *args],
30
+ cwd=cwd,
31
+ capture_output=True,
32
+ text=True,
33
+ timeout=timeout,
34
+ check=False,
35
+ )
36
+ except subprocess.TimeoutExpired as exc:
37
+ return {
38
+ "exit_code": 124,
39
+ "stdout": exc.stdout or "",
40
+ "stderr": f"Python execution timed out after {timeout}s.",
41
+ }
42
+
43
+ return {
44
+ "exit_code": completed.returncode,
45
+ "stdout": completed.stdout,
46
+ "stderr": completed.stderr,
47
+ }
gaia_agent/tools/search.py CHANGED
@@ -1 +1,4 @@
1
- """Search tools will live here."""
 
 
 
 
1
+ from gaia_agent.tools.web import SearchResult, web_search
2
+
3
+
4
+ __all__ = ["SearchResult", "web_search"]
gaia_agent/tools/web.py CHANGED
@@ -1 +1,224 @@
1
- """Web browsing tools will live here."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from dataclasses import dataclass
5
+ from html.parser import HTMLParser
6
+ from typing import Iterable
7
+ from urllib.parse import parse_qs, unquote, urlparse
8
+
9
+ import requests
10
+
11
+
12
+ USER_AGENT = (
13
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
14
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124 Safari/537.36"
15
+ )
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class SearchResult:
20
+ title: str
21
+ url: str
22
+ snippet: str = ""
23
+
24
+
25
+ def extract_urls(text: str) -> list[str]:
26
+ return re.findall(r"https?://[^\s)>\]]+", text)
27
+
28
+
29
+ def fetch_url(url: str, *, timeout: int = 20, max_chars: int = 30_000) -> str:
30
+ response = requests.get(
31
+ url,
32
+ headers={"User-Agent": USER_AGENT},
33
+ timeout=timeout,
34
+ )
35
+ response.raise_for_status()
36
+ content_type = response.headers.get("content-type", "")
37
+ raw_text = response.text
38
+ if "html" in content_type:
39
+ raw_text = html_to_text(raw_text)
40
+
41
+ raw_text = normalize_whitespace(raw_text)
42
+ if len(raw_text) <= max_chars:
43
+ return raw_text
44
+ return f"{raw_text[:max_chars]}\n\n[truncated after {max_chars} characters]"
45
+
46
+
47
+ def web_search(query: str, *, max_results: int = 5, timeout: int = 20) -> list[SearchResult]:
48
+ results = _duckduckgo_search(query, max_results=max_results, timeout=timeout)
49
+ if results:
50
+ return results[:max_results]
51
+ return _wikipedia_search(query, max_results=max_results, timeout=timeout)
52
+
53
+
54
+ def get_youtube_transcript(url_or_id: str) -> str:
55
+ video_id = extract_youtube_id(url_or_id)
56
+ if not video_id:
57
+ raise ValueError(f"Could not extract a YouTube video id from {url_or_id!r}.")
58
+
59
+ try:
60
+ from youtube_transcript_api import YouTubeTranscriptApi
61
+ except ImportError as exc:
62
+ raise RuntimeError(
63
+ "youtube-transcript-api is not installed, so YouTube transcripts "
64
+ "cannot be fetched."
65
+ ) from exc
66
+
67
+ try:
68
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
69
+ except AttributeError:
70
+ transcript = YouTubeTranscriptApi().fetch(video_id).to_raw_data()
71
+
72
+ return "\n".join(
73
+ f"[{entry.get('start', 0):.1f}] {entry.get('text', '')}"
74
+ for entry in transcript
75
+ )
76
+
77
+
78
+ def extract_youtube_id(url_or_id: str) -> str | None:
79
+ if re.fullmatch(r"[\w-]{11}", url_or_id):
80
+ return url_or_id
81
+
82
+ parsed = urlparse(url_or_id)
83
+ if parsed.hostname in {"youtu.be", "www.youtu.be"}:
84
+ return parsed.path.lstrip("/")[:11]
85
+ if parsed.hostname and "youtube.com" in parsed.hostname:
86
+ query_id = parse_qs(parsed.query).get("v", [None])[0]
87
+ if query_id:
88
+ return query_id[:11]
89
+ match = re.search(r"/(?:shorts|embed)/([\w-]{11})", parsed.path)
90
+ if match:
91
+ return match.group(1)
92
+ return None
93
+
94
+
95
+ def html_to_text(html: str) -> str:
96
+ parser = _TextExtractor()
97
+ parser.feed(html)
98
+ return parser.text()
99
+
100
+
101
+ def normalize_whitespace(text: str) -> str:
102
+ return re.sub(r"\s+", " ", text).strip()
103
+
104
+
105
+ def _duckduckgo_search(
106
+ query: str,
107
+ *,
108
+ max_results: int,
109
+ timeout: int,
110
+ ) -> list[SearchResult]:
111
+ response = requests.get(
112
+ "https://duckduckgo.com/html/",
113
+ params={"q": query},
114
+ headers={"User-Agent": USER_AGENT},
115
+ timeout=timeout,
116
+ )
117
+ response.raise_for_status()
118
+ parser = _DuckDuckGoParser()
119
+ parser.feed(response.text)
120
+ return parser.results[:max_results]
121
+
122
+
123
+ def _wikipedia_search(
124
+ query: str,
125
+ *,
126
+ max_results: int,
127
+ timeout: int,
128
+ ) -> list[SearchResult]:
129
+ response = requests.get(
130
+ "https://en.wikipedia.org/w/api.php",
131
+ params={
132
+ "action": "query",
133
+ "list": "search",
134
+ "srsearch": query,
135
+ "format": "json",
136
+ "srlimit": max_results,
137
+ },
138
+ headers={"User-Agent": USER_AGENT},
139
+ timeout=timeout,
140
+ )
141
+ response.raise_for_status()
142
+ payload = response.json()
143
+ results = []
144
+ for item in payload.get("query", {}).get("search", []):
145
+ title = item.get("title", "")
146
+ url_title = title.replace(" ", "_")
147
+ results.append(
148
+ SearchResult(
149
+ title=title,
150
+ url=f"https://en.wikipedia.org/wiki/{url_title}",
151
+ snippet=html_to_text(item.get("snippet", "")),
152
+ )
153
+ )
154
+ return results
155
+
156
+
157
+ class _TextExtractor(HTMLParser):
158
+ def __init__(self) -> None:
159
+ super().__init__()
160
+ self._chunks: list[str] = []
161
+ self._skip_depth = 0
162
+
163
+ def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
164
+ if tag in {"script", "style", "noscript", "svg"}:
165
+ self._skip_depth += 1
166
+ if tag in {"p", "br", "li", "tr", "h1", "h2", "h3", "h4"}:
167
+ self._chunks.append("\n")
168
+
169
+ def handle_endtag(self, tag: str) -> None:
170
+ if tag in {"script", "style", "noscript", "svg"} and self._skip_depth:
171
+ self._skip_depth -= 1
172
+ if tag in {"p", "li", "tr"}:
173
+ self._chunks.append("\n")
174
+
175
+ def handle_data(self, data: str) -> None:
176
+ if not self._skip_depth:
177
+ self._chunks.append(data)
178
+
179
+ def text(self) -> str:
180
+ return "\n".join(
181
+ chunk.strip() for chunk in self._chunks if chunk and chunk.strip()
182
+ )
183
+
184
+
185
+ class _DuckDuckGoParser(HTMLParser):
186
+ def __init__(self) -> None:
187
+ super().__init__()
188
+ self.results: list[SearchResult] = []
189
+ self._active_href: str | None = None
190
+ self._active_chunks: list[str] = []
191
+
192
+ def handle_starttag(self, tag: str, attrs: Iterable[tuple[str, str | None]]) -> None:
193
+ if tag != "a":
194
+ return
195
+ attr_map = {key: value or "" for key, value in attrs}
196
+ css_class = attr_map.get("class", "")
197
+ href = attr_map.get("href", "")
198
+ if "result__a" in css_class and href:
199
+ self._active_href = _unwrap_duckduckgo_url(href)
200
+ self._active_chunks = []
201
+
202
+ def handle_data(self, data: str) -> None:
203
+ if self._active_href:
204
+ self._active_chunks.append(data)
205
+
206
+ def handle_endtag(self, tag: str) -> None:
207
+ if tag != "a" or not self._active_href:
208
+ return
209
+ title = normalize_whitespace(" ".join(self._active_chunks))
210
+ if title and self._active_href.startswith("http"):
211
+ self.results.append(SearchResult(title=title, url=self._active_href))
212
+ self._active_href = None
213
+ self._active_chunks = []
214
+
215
+
216
+ def _unwrap_duckduckgo_url(url: str) -> str:
217
+ if url.startswith("//"):
218
+ url = f"https:{url}"
219
+ parsed = urlparse(url)
220
+ if "duckduckgo.com" in parsed.netloc:
221
+ uddg = parse_qs(parsed.query).get("uddg", [None])[0]
222
+ if uddg:
223
+ return unquote(uddg)
224
+ return url
pyproject.toml CHANGED
@@ -8,11 +8,13 @@ dependencies = [
8
  "gradio[oauth]==5.25.2",
9
  "requests>=2.32.0",
10
  "pandas>=2.2.0",
 
11
  "python-dotenv>=1.0.1",
12
  "langchain>=0.3.0",
13
  "langgraph>=0.2.60",
14
  "langfuse>=2.57.0",
15
  "langchain-litellm>=0.6.4",
 
16
  ]
17
 
18
  [build-system]
 
8
  "gradio[oauth]==5.25.2",
9
  "requests>=2.32.0",
10
  "pandas>=2.2.0",
11
+ "openpyxl>=3.1.0",
12
  "python-dotenv>=1.0.1",
13
  "langchain>=0.3.0",
14
  "langgraph>=0.2.60",
15
  "langfuse>=2.57.0",
16
  "langchain-litellm>=0.6.4",
17
+ "youtube-transcript-api>=0.6.2",
18
  ]
19
 
20
  [build-system]
requirements.txt CHANGED
@@ -1,8 +1,11 @@
1
  gradio[oauth]==5.25.2
2
  requests>=2.32.0
3
  pandas>=2.2.0
 
4
  python-dotenv>=1.0.1
5
  langchain>=0.3.0
6
  langchain-openai>=0.3.0
7
  langgraph>=0.2.60
8
  langfuse>=2.57.0
 
 
 
1
  gradio[oauth]==5.25.2
2
  requests>=2.32.0
3
  pandas>=2.2.0
4
+ openpyxl>=3.1.0
5
  python-dotenv>=1.0.1
6
  langchain>=0.3.0
7
  langchain-openai>=0.3.0
8
  langgraph>=0.2.60
9
  langfuse>=2.57.0
10
+ langchain-litellm>=0.6.4
11
+ youtube-transcript-api>=0.6.2
uv.lock CHANGED
@@ -506,6 +506,15 @@ wheels = [
506
  { url = "https://files.pythonhosted.org/packages/20/2a/1b016902351a523aa2bd446b50a5bc1175d7a7d1cf90fe2ef904f9b84ebc/cryptography-46.0.7-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:258514877e15963bd43b558917bc9f54cf7cf866c38aa576ebf47a77ddbc43a4", size = 3412829, upload-time = "2026-04-08T01:57:48.874Z" },
507
  ]
508
 
 
 
 
 
 
 
 
 
 
509
  [[package]]
510
  name = "distro"
511
  version = "1.9.0"
@@ -515,6 +524,15 @@ wheels = [
515
  { url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277, upload-time = "2023-12-24T09:54:30.421Z" },
516
  ]
517
 
 
 
 
 
 
 
 
 
 
518
  [[package]]
519
  name = "fastapi"
520
  version = "0.136.1"
@@ -725,9 +743,11 @@ dependencies = [
725
  { name = "langchain-litellm" },
726
  { name = "langfuse" },
727
  { name = "langgraph" },
 
728
  { name = "pandas" },
729
  { name = "python-dotenv" },
730
  { name = "requests" },
 
731
  ]
732
 
733
  [package.dev-dependencies]
@@ -742,9 +762,11 @@ requires-dist = [
742
  { name = "langchain-litellm", specifier = ">=0.6.4" },
743
  { name = "langfuse", specifier = ">=2.57.0" },
744
  { name = "langgraph", specifier = ">=0.2.60" },
 
745
  { name = "pandas", specifier = ">=2.2.0" },
746
  { name = "python-dotenv", specifier = ">=1.0.1" },
747
  { name = "requests", specifier = ">=2.32.0" },
 
748
  ]
749
 
750
  [package.metadata.requires-dev]
@@ -1613,6 +1635,18 @@ wheels = [
1613
  { url = "https://files.pythonhosted.org/packages/f2/40/f090499f10514515081d09cb9da09f25b821eb20497e9423afe4f07b4ecf/openai-2.34.0-py3-none-any.whl", hash = "sha256:c996a71b1a210f3569844572ad4c609307e978515fb76877cf449b72596e549e", size = 1316535, upload-time = "2026-05-04T17:34:06.773Z" },
1614
  ]
1615
 
 
 
 
 
 
 
 
 
 
 
 
 
1616
  [[package]]
1617
  name = "opentelemetry-api"
1618
  version = "1.41.1"
@@ -3218,6 +3252,19 @@ wheels = [
3218
  { url = "https://files.pythonhosted.org/packages/69/68/c8739671f5699c7dc470580a4f821ef37c32c4cb0b047ce223a7f115757f/yarl-1.23.0-py3-none-any.whl", hash = "sha256:a2df6afe50dea8ae15fa34c9f824a3ee958d785fd5d089063d960bae1daa0a3f", size = 48288, upload-time = "2026-03-01T22:07:51.388Z" },
3219
  ]
3220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3221
  [[package]]
3222
  name = "zipp"
3223
  version = "3.23.1"
 
506
  { url = "https://files.pythonhosted.org/packages/20/2a/1b016902351a523aa2bd446b50a5bc1175d7a7d1cf90fe2ef904f9b84ebc/cryptography-46.0.7-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:258514877e15963bd43b558917bc9f54cf7cf866c38aa576ebf47a77ddbc43a4", size = 3412829, upload-time = "2026-04-08T01:57:48.874Z" },
507
  ]
508
 
509
+ [[package]]
510
+ name = "defusedxml"
511
+ version = "0.7.1"
512
+ source = { registry = "https://pypi.org/simple" }
513
+ sdist = { url = "https://files.pythonhosted.org/packages/0f/d5/c66da9b79e5bdb124974bfe172b4daf3c984ebd9c2a06e2b8a4dc7331c72/defusedxml-0.7.1.tar.gz", hash = "sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69", size = 75520, upload-time = "2021-03-08T10:59:26.269Z" }
514
+ wheels = [
515
+ { url = "https://files.pythonhosted.org/packages/07/6c/aa3f2f849e01cb6a001cd8554a88d4c77c5c1a31c95bdf1cf9301e6d9ef4/defusedxml-0.7.1-py2.py3-none-any.whl", hash = "sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61", size = 25604, upload-time = "2021-03-08T10:59:24.45Z" },
516
+ ]
517
+
518
  [[package]]
519
  name = "distro"
520
  version = "1.9.0"
 
524
  { url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277, upload-time = "2023-12-24T09:54:30.421Z" },
525
  ]
526
 
527
+ [[package]]
528
+ name = "et-xmlfile"
529
+ version = "2.0.0"
530
+ source = { registry = "https://pypi.org/simple" }
531
+ sdist = { url = "https://files.pythonhosted.org/packages/d3/38/af70d7ab1ae9d4da450eeec1fa3918940a5fafb9055e934af8d6eb0c2313/et_xmlfile-2.0.0.tar.gz", hash = "sha256:dab3f4764309081ce75662649be815c4c9081e88f0837825f90fd28317d4da54", size = 17234, upload-time = "2024-10-25T17:25:40.039Z" }
532
+ wheels = [
533
+ { url = "https://files.pythonhosted.org/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl", hash = "sha256:7a91720bc756843502c3b7504c77b8fe44217c85c537d85037f0f536151b2caa", size = 18059, upload-time = "2024-10-25T17:25:39.051Z" },
534
+ ]
535
+
536
  [[package]]
537
  name = "fastapi"
538
  version = "0.136.1"
 
743
  { name = "langchain-litellm" },
744
  { name = "langfuse" },
745
  { name = "langgraph" },
746
+ { name = "openpyxl" },
747
  { name = "pandas" },
748
  { name = "python-dotenv" },
749
  { name = "requests" },
750
+ { name = "youtube-transcript-api" },
751
  ]
752
 
753
  [package.dev-dependencies]
 
762
  { name = "langchain-litellm", specifier = ">=0.6.4" },
763
  { name = "langfuse", specifier = ">=2.57.0" },
764
  { name = "langgraph", specifier = ">=0.2.60" },
765
+ { name = "openpyxl", specifier = ">=3.1.0" },
766
  { name = "pandas", specifier = ">=2.2.0" },
767
  { name = "python-dotenv", specifier = ">=1.0.1" },
768
  { name = "requests", specifier = ">=2.32.0" },
769
+ { name = "youtube-transcript-api", specifier = ">=0.6.2" },
770
  ]
771
 
772
  [package.metadata.requires-dev]
 
1635
  { url = "https://files.pythonhosted.org/packages/f2/40/f090499f10514515081d09cb9da09f25b821eb20497e9423afe4f07b4ecf/openai-2.34.0-py3-none-any.whl", hash = "sha256:c996a71b1a210f3569844572ad4c609307e978515fb76877cf449b72596e549e", size = 1316535, upload-time = "2026-05-04T17:34:06.773Z" },
1636
  ]
1637
 
1638
+ [[package]]
1639
+ name = "openpyxl"
1640
+ version = "3.1.5"
1641
+ source = { registry = "https://pypi.org/simple" }
1642
+ dependencies = [
1643
+ { name = "et-xmlfile" },
1644
+ ]
1645
+ sdist = { url = "https://files.pythonhosted.org/packages/3d/f9/88d94a75de065ea32619465d2f77b29a0469500e99012523b91cc4141cd1/openpyxl-3.1.5.tar.gz", hash = "sha256:cf0e3cf56142039133628b5acffe8ef0c12bc902d2aadd3e0fe5878dc08d1050", size = 186464, upload-time = "2024-06-28T14:03:44.161Z" }
1646
+ wheels = [
1647
+ { url = "https://files.pythonhosted.org/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl", hash = "sha256:5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2", size = 250910, upload-time = "2024-06-28T14:03:41.161Z" },
1648
+ ]
1649
+
1650
  [[package]]
1651
  name = "opentelemetry-api"
1652
  version = "1.41.1"
 
3252
  { url = "https://files.pythonhosted.org/packages/69/68/c8739671f5699c7dc470580a4f821ef37c32c4cb0b047ce223a7f115757f/yarl-1.23.0-py3-none-any.whl", hash = "sha256:a2df6afe50dea8ae15fa34c9f824a3ee958d785fd5d089063d960bae1daa0a3f", size = 48288, upload-time = "2026-03-01T22:07:51.388Z" },
3253
  ]
3254
 
3255
+ [[package]]
3256
+ name = "youtube-transcript-api"
3257
+ version = "1.2.4"
3258
+ source = { registry = "https://pypi.org/simple" }
3259
+ dependencies = [
3260
+ { name = "defusedxml" },
3261
+ { name = "requests" },
3262
+ ]
3263
+ sdist = { url = "https://files.pythonhosted.org/packages/60/43/4104185a2eaa839daa693b30e15c37e7e58795e8e09ec414f22b3db54bec/youtube_transcript_api-1.2.4.tar.gz", hash = "sha256:b72d0e96a335df599d67cee51d49e143cff4f45b84bcafc202ff51291603ddcd", size = 469839, upload-time = "2026-01-29T09:09:17.088Z" }
3264
+ wheels = [
3265
+ { url = "https://files.pythonhosted.org/packages/be/95/129ea37efd6cd6ed00f62baae6543345c677810b8a3bf0026756e1d3cf3c/youtube_transcript_api-1.2.4-py3-none-any.whl", hash = "sha256:03878759356da5caf5edac77431780b91448fb3d8c21d4496015bdc8a7bc43ff", size = 485227, upload-time = "2026-01-29T09:09:15.427Z" },
3266
+ ]
3267
+
3268
  [[package]]
3269
  name = "zipp"
3270
  version = "3.23.1"