Kackle commited on
Commit
e914d7c
·
verified ·
1 Parent(s): 6773149
Files changed (1) hide show
  1. app.py +40 -33
app.py CHANGED
@@ -393,11 +393,7 @@ class SlpMultiAgent:
393
  )
394
 
395
  manager_agent = CodeAgent(
396
- model=OpenAIServerModel(
397
- model_id="gpt-3.5-turbo",
398
- temperature=0.0,
399
- max_tokens=500
400
- ),
401
  tools=[GoogleSearchTool(), MathTool(), FileProcessorTool(), KnowledgeBaseTool()],
402
  managed_agents=[research_agent, solver_agent],
403
  name="ManagerAgent",
@@ -421,29 +417,38 @@ class SlpMultiAgent:
421
  lambda: manager_agent.run(f"""
422
  Question: {short_question}
423
 
424
- CRITICAL: You MUST use the exact format below. Do NOT use markdown code blocks.
425
-
426
- Step 1: Use a tool to get information
427
- Step 2: Provide final answer
 
 
428
 
429
  Available tools:
430
- - google_search(query): Search for information
431
  - math_calculator(expression): Calculate math
 
432
  - knowledge_base(topic): Get knowledge
433
 
434
- FORMAT EXAMPLE:
435
- <code>
436
- result = google_search("your search query here")
437
- final_answer("your answer here")
438
- </code>
 
 
 
 
439
 
440
- RULES:
441
- - Always wrap code in <code> tags, never use ```
442
- - Call tools directly as functions
443
- - End with final_answer("answer")
444
- - Be concise
 
 
 
445
 
446
- Answer the question now using this exact format.
447
  """)
448
  )
449
  break # Success, exit retry loop
@@ -458,29 +463,31 @@ class SlpMultiAgent:
458
  await asyncio.sleep(5) # Wait before general retry
459
  else:
460
  print(f"All attempts failed. Returning default answer.")
461
- return "Unable to process request."
462
 
463
  # If we couldn't get a result after all retries
464
  if result is None:
465
- return "Unable to process request."
466
 
467
 
468
  # Extract clean answer from result
469
  if result and isinstance(result, str):
470
  # Look for final_answer pattern
471
  import re
472
- final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\'\)]', result)
473
  if final_answer_match:
474
- clean_answer = final_answer_match.group(1).strip()
475
- # Ensure we have a meaningful answer, not search results
476
- if clean_answer and not clean_answer.startswith('•') and len(clean_answer) < 500:
477
- return clean_answer
478
 
479
- # If no final_answer found or it's malformed, return a simple fallback
480
- return "Unable to determine specific answer from available information."
 
 
 
 
481
 
482
- # Return fallback if no result
483
- return "Unable to process question."
484
 
485
  def check_reasoning(final_answer, agent_memory):
486
  # Skip expensive validation to save costs
@@ -716,4 +723,4 @@ if __name__ == "__main__":
716
  print("-"*(60 + len(" App Starting ")) + "\n")
717
 
718
  print("Launching Gradio Interface for Enhanced Agent with Google Search & Gemini...")
719
- demo.launch(debug=True, share=False)
 
393
  )
394
 
395
  manager_agent = CodeAgent(
396
+ model=model if not isinstance(model, GeminiModel) else OpenAIServerModel(model_id="gpt-3.5-turbo", temperature=0.0, max_tokens=400),
 
 
 
 
397
  tools=[GoogleSearchTool(), MathTool(), FileProcessorTool(), KnowledgeBaseTool()],
398
  managed_agents=[research_agent, solver_agent],
399
  name="ManagerAgent",
 
417
  lambda: manager_agent.run(f"""
418
  Question: {short_question}
419
 
420
+ CRITICAL INSTRUCTIONS:
421
+ 1. Use tools DIRECTLY, not in code execution
422
+ 2. For factual questions: Use google_search() tool immediately
423
+ 3. For math: Use math_calculator() tool directly
424
+ 4. DO NOT write complex code - use tools instead
425
+ 5. DO NOT call ResearchAgent() or SolverAgent() in code
426
 
427
  Available tools:
428
+ - google_search(query): Search the web
429
  - math_calculator(expression): Calculate math
430
+ - file_processor(action, data): Handle files
431
  - knowledge_base(topic): Get knowledge
432
 
433
+ SIMPLE APPROACH:
434
+ - Call the appropriate tool
435
+ - Get the result
436
+ - Provide final_answer()
437
+
438
+ Example for factual question:
439
+ 1. Call google_search("your query")
440
+ 2. Extract answer from results
441
+ 3. Call final_answer("the answer")
442
 
443
+ NO complex code execution. Use tools directly.
444
+
445
+ Take your time and think every step out, be confident and precise.
446
+
447
+ Google should be able to answer all these questions and you have access to it.
448
+
449
+ They are simple yet tricky questions, so be careful and double check your answers. Make sure to use google_search for any factual question.
450
+
451
 
 
452
  """)
453
  )
454
  break # Success, exit retry loop
 
463
  await asyncio.sleep(5) # Wait before general retry
464
  else:
465
  print(f"All attempts failed. Returning default answer.")
466
+ return "I apologize, but I'm currently experiencing technical difficulties. Please try again later."
467
 
468
  # If we couldn't get a result after all retries
469
  if result is None:
470
+ return "I apologize, but I'm currently experiencing technical difficulties. Please try again later."
471
 
472
 
473
  # Extract clean answer from result
474
  if result and isinstance(result, str):
475
  # Look for final_answer pattern
476
  import re
477
+ final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\'\)]', result) # Fixed regex
478
  if final_answer_match:
479
+ clean_answer = final_answer_match.group(1)
480
+ return clean_answer
 
 
481
 
482
+ # If no final_answer found, try to extract the last meaningful line
483
+ lines = result.strip().split('\n')
484
+ for line in reversed(lines):
485
+ line = line.strip()
486
+ if line and not line.startswith('#') and not line.startswith('###') and len(line) < 200:
487
+ return line
488
 
489
+ # Return the result from the agent
490
+ return result if result else "Unable to determine answer."
491
 
492
  def check_reasoning(final_answer, agent_memory):
493
  # Skip expensive validation to save costs
 
723
  print("-"*(60 + len(" App Starting ")) + "\n")
724
 
725
  print("Launching Gradio Interface for Enhanced Agent with Google Search & Gemini...")
726
+ demo.launch(debug=True, share=False)