Hanbaike commited on
Commit
f4da841
·
verified ·
1 Parent(s): effd9ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -8
app.py CHANGED
@@ -252,8 +252,56 @@ def assistant(state: AgentState):
252
  """
253
  system_msg = SystemMessage(
254
  content=(
255
- "Reply with the final answer only. Do not include any preamble, "
256
- "explanations, or the text 'FINAL ANSWER'."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  )
258
  )
259
 
@@ -297,22 +345,29 @@ class BasicAgent:
297
  def __init__(self):
298
  self.graph = graph
299
 
300
- def __call__(self, question: str) -> str:
301
 
302
  try:
303
-
 
 
 
 
304
  result = self.graph.invoke(
305
  {
306
  "messages": [
307
- HumanMessage(content=question)
308
  ]
309
  },
310
  config={
311
  "recursion_limit": 30
312
  }
313
  )
314
-
315
- return result["messages"][-1].content
 
 
 
316
 
317
  except Exception as e:
318
  return f"Agent error: {e}"
@@ -378,7 +433,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
378
  print(f"Skipping item with missing task_id or question: {item}")
379
  continue
380
  try:
381
- submitted_answer = agent(question_text)
382
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
383
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
384
  except Exception as e:
 
252
  """
253
  system_msg = SystemMessage(
254
  content=(
255
+ "You are an expert research and reasoning agent.\n\n"
256
+ "You have access to tools for:\n"
257
+ "- web search\n"
258
+ "- webpage retrieval\n"
259
+ "- PDF reading\n"
260
+ "- Python execution\n"
261
+ "- task file retrieval\n\n"
262
+ "Always use tools when information is missing, uncertain, "
263
+ "requires computation, or depends on external documents.\n\n"
264
+ "When solving a task:\n\n"
265
+ "1. Read the question carefully.\n"
266
+ "2. Use tools whenever necessary.\n"
267
+ "3. Verify facts before answering.\n"
268
+ "4. Perform calculations with Python rather than mental math.\n"
269
+ "5. Read files and PDFs when relevant.\n"
270
+ "6. Continue gathering evidence until you are confident.\n\n"
271
+ "If the task references a file, use the task file tool.\n\n"
272
+ "IMPORTANT OUTPUT RULES:\n\n"
273
+ "- Return ONLY the final answer.\n"
274
+ "- Do NOT explain your reasoning.\n"
275
+ "- Do NOT provide analysis.\n"
276
+ "- Do NOT provide step-by-step solutions.\n"
277
+ "- Do NOT provide preambles.\n"
278
+ "- Do NOT provide markdown.\n"
279
+ "- Do NOT provide bullet points.\n"
280
+ "- Do NOT provide quotes unless the answer itself requires quotes.\n"
281
+ "- Do NOT write 'FINAL ANSWER'.\n"
282
+ "- Do NOT write 'The answer is'.\n"
283
+ "- Do NOT write any surrounding text.\n\n"
284
+ "Your entire response must contain only the exact answer.\n\n"
285
+ "Examples:\n\n"
286
+ "Correct:\n"
287
+ "Paris\n\n"
288
+ "Incorrect:\n"
289
+ "The answer is Paris\n\n"
290
+ "Incorrect:\n"
291
+ "FINAL ANSWER: Paris\n\n"
292
+ "Correct:\n"
293
+ "42\n\n"
294
+ "Incorrect:\n"
295
+ "42.\n\n"
296
+ "Correct:\n"
297
+ "1997\n\n"
298
+ "Incorrect:\n"
299
+ "The year is 1997\n\n"
300
+ "If the answer is a number, output only the number.\n\n"
301
+ "If the answer is a name, output only the name.\n\n"
302
+ "If the answer is a date, output only the date.\n\n"
303
+ "If the answer is a phrase, output only the phrase.\n\n"
304
+ "Be precise."
305
  )
306
  )
307
 
 
345
  def __init__(self):
346
  self.graph = graph
347
 
348
+ def __call__(self, task_id: str, question: str) -> str:
349
 
350
  try:
351
+ prompt = (
352
+ f"Task ID: {task_id}\n\n"
353
+ "Question:\n"
354
+ f"{question}"
355
+ )
356
  result = self.graph.invoke(
357
  {
358
  "messages": [
359
+ HumanMessage(content=prompt)
360
  ]
361
  },
362
  config={
363
  "recursion_limit": 30
364
  }
365
  )
366
+ answer = result["messages"][-1].content
367
+ answer = answer.strip()
368
+ if answer.startswith('"') and answer.endswith('"'):
369
+ answer = answer[1:-1]
370
+ return answer.strip()
371
 
372
  except Exception as e:
373
  return f"Agent error: {e}"
 
433
  print(f"Skipping item with missing task_id or question: {item}")
434
  continue
435
  try:
436
+ submitted_answer = agent(task_id, question_text)
437
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
438
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
439
  except Exception as e: