Kackle commited on
Commit
6cd6f36
·
verified ·
1 Parent(s): 8e19d1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -415,7 +415,8 @@ class SlpMultiAgent:
415
  result = await loop.run_in_executor(
416
  None,
417
  lambda: manager_agent.run(f"""
418
- Question: {short_question}
 
419
 
420
  INSTRUCTIONS:
421
  - For every question, you MUST call the most appropriate tool to get the answer.
@@ -424,7 +425,19 @@ class SlpMultiAgent:
424
  - Only call the tool and then call final_answer('...').
425
  - If you cannot answer, call final_answer('I don't know').
426
  - STRICTLY FOLLOW THIS FORMAT. DO NOT OUTPUT ANYTHING ELSE.
427
-
 
 
 
 
 
 
 
 
 
 
 
 
428
  Available tools:
429
  - google_search(query): Search the web
430
  - math_calculator(expression): Calculate math
@@ -433,7 +446,7 @@ class SlpMultiAgent:
433
  - wikipedia_search(query): Search Wikipedia
434
  - code_executor(code): Execute Python code
435
  - web_scraper(url): Scrape web pages
436
-
437
  EXAMPLES:
438
  Q: What is the capital of France?
439
  A: final_answer('Paris')
@@ -451,6 +464,8 @@ class SlpMultiAgent:
451
  A: final_answer('avocado')
452
 
453
  STRICTLY FOLLOW THIS FORMAT. DO NOT OUTPUT ANYTHING ELSE.
 
 
454
  """)
455
  )
456
  break # Success, exit retry loop
@@ -498,16 +513,24 @@ class SlpMultiAgent:
498
  return text.strip()
499
  # Post-process the result to remove code blocks and extract the answer
500
  if result and isinstance(result, str):
 
 
 
501
  cleaned = strip_code_blocks(result)
502
  answer = extract_final_answer(cleaned)
503
  if answer:
 
 
 
504
  return answer
505
  # Fallback: try to extract from the original result
506
  answer = extract_final_answer(result)
507
  if answer:
 
 
508
  return answer
509
  # Return the result from the agent
510
- return result if result else "Unable to determine answer."
511
 
512
  def check_reasoning(final_answer, agent_memory):
513
  # Skip expensive validation to save costs
 
415
  result = await loop.run_in_executor(
416
  None,
417
  lambda: manager_agent.run(f"""
418
+ DO NOT output any code blocks, markdown, triple backticks, <code> tags, or print statements. DO NOT output plans, thoughts, or intermediate steps. DO NOT output anything except a single call to final_answer('...').
419
+ If you do, you will be penalized and your answer will be rejected.
420
 
421
  INSTRUCTIONS:
422
  - For every question, you MUST call the most appropriate tool to get the answer.
 
425
  - Only call the tool and then call final_answer('...').
426
  - If you cannot answer, call final_answer('I don't know').
427
  - STRICTLY FOLLOW THIS FORMAT. DO NOT OUTPUT ANYTHING ELSE.
428
+ - If you reach max steps, call final_answer('I don't know').
429
+
430
+ BAD EXAMPLES (DO NOT DO THIS):
431
+ ```python\nfinal_answer('foo')\n```
432
+ <code>final_answer('foo')</code>
433
+ Thoughts: ...
434
+ Plan: ...
435
+
436
+ GOOD EXAMPLES (DO THIS):
437
+ final_answer('Paris')
438
+ final_answer('4')
439
+ final_answer('I don't know')
440
+
441
  Available tools:
442
  - google_search(query): Search the web
443
  - math_calculator(expression): Calculate math
 
446
  - wikipedia_search(query): Search Wikipedia
447
  - code_executor(code): Execute Python code
448
  - web_scraper(url): Scrape web pages
449
+
450
  EXAMPLES:
451
  Q: What is the capital of France?
452
  A: final_answer('Paris')
 
464
  A: final_answer('avocado')
465
 
466
  STRICTLY FOLLOW THIS FORMAT. DO NOT OUTPUT ANYTHING ELSE.
467
+
468
+ Question: {short_question}
469
  """)
470
  )
471
  break # Success, exit retry loop
 
513
  return text.strip()
514
  # Post-process the result to remove code blocks and extract the answer
515
  if result and isinstance(result, str):
516
+ # If agent reached max steps, return I don't know
517
+ if "Reached max steps" in result:
518
+ return "I don't know"
519
  cleaned = strip_code_blocks(result)
520
  answer = extract_final_answer(cleaned)
521
  if answer:
522
+ # If the answer is still a code block or not a final_answer, fallback
523
+ if answer.startswith('```') or answer.startswith('<code>') or 'final_answer' not in result:
524
+ return "I don't know"
525
  return answer
526
  # Fallback: try to extract from the original result
527
  answer = extract_final_answer(result)
528
  if answer:
529
+ if answer.startswith('```') or answer.startswith('<code>') or 'final_answer' not in result:
530
+ return "I don't know"
531
  return answer
532
  # Return the result from the agent
533
+ return "I don't know"
534
 
535
  def check_reasoning(final_answer, agent_memory):
536
  # Skip expensive validation to save costs