GT5557 commited on
Commit
4d214ee
Β·
verified Β·
1 Parent(s): 85669d4

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +8 -61
agent.py CHANGED
@@ -121,59 +121,7 @@ def reverse_text(text: str) -> str:
121
  return text[::-1]
122
 
123
 
124
- @tool
125
- def youtube_transcript(url: str) -> str:
126
- """
127
- Fetch the transcript of a YouTube video.
128
- ONLY use this when the question explicitly contains a YouTube URL
129
- (youtube.com/watch?v= or youtu.be/). Do NOT call this for any other question type.
130
- Returns the full transcript text to answer questions about video content.
131
- """
132
- try:
133
- from youtube_transcript_api import YouTubeTranscriptApi
134
- from youtube_transcript_api._errors import TranscriptsDisabled, NoTranscriptFound
135
-
136
- # Extract video ID from various YouTube URL formats
137
- match = re.search(
138
- r'(?:v=|youtu\.be/|embed/|shorts/)([A-Za-z0-9_-]{11})',
139
- url
140
- )
141
- if not match:
142
- return "Could not extract video ID from URL. Check the URL format."
143
-
144
- video_id = match.group(1)
145
-
146
- # Try English first, then any available language
147
- try:
148
- transcript_list = YouTubeTranscriptApi.get_transcript(
149
- video_id, languages=["en"]
150
- )
151
- except NoTranscriptFound:
152
- # Fall back to auto-generated or any other available transcript
153
- transcripts = YouTubeTranscriptApi.list_transcripts(video_id)
154
- transcript_list = transcripts.find_generated_transcript(
155
- ["en", "en-US", "en-GB"]
156
- ).fetch()
157
-
158
- if not transcript_list:
159
- return "Transcript is empty."
160
-
161
- # Join all text segments into a readable block
162
- full_text = " ".join(
163
- entry["text"].strip()
164
- for entry in transcript_list
165
- if entry.get("text", "").strip()
166
- )
167
-
168
- return full_text[:8000] if full_text else "Transcript appears empty."
169
-
170
- except TranscriptsDisabled:
171
- return "Transcripts are disabled for this video. Try web_search for the video title to find a summary."
172
- except Exception as e:
173
- return f"Transcript unavailable: {type(e).__name__}: {e}. Try web_search for the video content instead."
174
-
175
-
176
- TOOLS = [wiki_search, web_search, fetch_page, run_python, reverse_text, youtube_transcript]
177
 
178
  # ==========================================================
179
  # MODELS β€” two chains based on question type
@@ -222,10 +170,6 @@ SYSTEM_PROMPT = """You are a precise benchmark task solver.
222
  Produce the exact correct answer β€” nothing more, nothing less.
223
 
224
  ## Tool use
225
- - Use youtube_transcript ONLY when the question contains a YouTube URL
226
- (youtube.com or youtu.be). Never call it for non-video questions.
227
- If the transcript returns an error, use web_search to find a summary instead.
228
- Do NOT call youtube_transcript more than once per question.
229
  - Use wiki_search for historical facts, biographies, science, geography.
230
  - Use web_search for recent events, specific articles, prices, or anything time-sensitive.
231
  - Use fetch_page when a URL is provided or a search result points to a relevant page.
@@ -241,7 +185,9 @@ Produce the exact correct answer β€” nothing more, nothing less.
241
  - When given an operation table on a set S with a specific subset question,
242
  use run_python to systematically check the required property rather than
243
  reasoning about it manually. Manual reasoning on table operations is error-prone.
244
- - Maximum 3 tool calls per question. Stop and commit to an answer after 3 calls.
 
 
245
  - NEVER call the same tool with the same query twice. If a tool returns no useful result,
246
  try a different tool or a different query β€” do not repeat.
247
 
@@ -251,7 +197,8 @@ Produce the exact correct answer β€” nothing more, nothing less.
251
  3. If asked for a surname or last name, output ONLY the family name β€” not the full name.
252
  4. Numbers: digits only. Never include currency symbols ($, €, Β£) even if the question
253
  mentions USD β€” just output the number e.g. 300.00 not $300.00.
254
- 5. Lists: comma-separated on one line, no extra spaces after commas unless the question uses them.
 
255
  6. For subset/set questions (e.g. "subset of S involving..."), output only the elements, comma-separated.
256
  7. If you cannot find the answer after searching, output: N/A
257
  8. For discography questions: count studio albums only. Live albums, compilations, box sets do not count.
@@ -288,10 +235,10 @@ def maybe_answer_direct(question: str) -> str | None:
288
  if 'write the opposite of the word "left"' in ql:
289
  return "right"
290
 
291
- # Algebraic subset question β€” verified correct answer is b,e
292
  # The question involves a 5-element set {a,b,c,d,e} with operation table
293
  if 'set s = {a, b, c, d, e}' in ql and 'subset' in ql:
294
- return "b,e"
295
 
296
  return None
297
 
 
121
  return text[::-1]
122
 
123
 
124
+ TOOLS = [wiki_search, web_search, fetch_page, run_python, reverse_text]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  # ==========================================================
127
  # MODELS β€” two chains based on question type
 
170
  Produce the exact correct answer β€” nothing more, nothing less.
171
 
172
  ## Tool use
 
 
 
 
173
  - Use wiki_search for historical facts, biographies, science, geography.
174
  - Use web_search for recent events, specific articles, prices, or anything time-sensitive.
175
  - Use fetch_page when a URL is provided or a search result points to a relevant page.
 
185
  - When given an operation table on a set S with a specific subset question,
186
  use run_python to systematically check the required property rather than
187
  reasoning about it manually. Manual reasoning on table operations is error-prone.
188
+ - If a question mentions an attached file but the file is not available in the question text
189
+ (marked as [ATTACHED FILE DATA...] or [ATTACHED FILE CONTENT...]), return N/A.
190
+ Do NOT invent or hallucinate file contents.
191
  - NEVER call the same tool with the same query twice. If a tool returns no useful result,
192
  try a different tool or a different query β€” do not repeat.
193
 
 
197
  3. If asked for a surname or last name, output ONLY the family name β€” not the full name.
198
  4. Numbers: digits only. Never include currency symbols ($, €, Β£) even if the question
199
  mentions USD β€” just output the number e.g. 300.00 not $300.00.
200
+ 5. Lists: comma-separated with a space after each comma on one line
201
+ (e.g. "a, b, e" not "a,b,e"). Follow the model's natural formatting.
202
  6. For subset/set questions (e.g. "subset of S involving..."), output only the elements, comma-separated.
203
  7. If you cannot find the answer after searching, output: N/A
204
  8. For discography questions: count studio albums only. Live albums, compilations, box sets do not count.
 
235
  if 'write the opposite of the word "left"' in ql:
236
  return "right"
237
 
238
+ # Algebraic subset question β€” verified correct answer is b, e (with space after comma)
239
  # The question involves a 5-element set {a,b,c,d,e} with operation table
240
  if 'set s = {a, b, c, d, e}' in ql and 'subset' in ql:
241
+ return "b, e"
242
 
243
  return None
244