Update agent.py
Browse files
agent.py
CHANGED
@@ -531,17 +531,17 @@ class EnhancedGAIAAgent:
|
|
531 |
|
532 |
You have access to THREE specialist tools:
|
533 |
|
534 |
-
**1.
|
535 |
- Use for: PDF, Word, CSV, image file analysis
|
536 |
- Capabilities: Extract data from tables/charts, cross-reference documents, semantic search
|
537 |
- When to use: Questions with file attachments, document analysis, data extraction
|
538 |
|
539 |
-
**2.
|
540 |
- Use for: External knowledge, current events, scientific papers
|
541 |
- Capabilities: Auto-routes between ArXiv (scientific) and web search (general), extracts full content
|
542 |
- When to use: Questions requiring external knowledge, factual verification, current information
|
543 |
|
544 |
-
**3.
|
545 |
- Use for: Mathematical calculations, data processing, logical operations
|
546 |
- Capabilities: Generates and executes Python code, handles complex computations, step-by-step problem solving
|
547 |
- When to use: Precise calculations, data manipulation, mathematical problem solving
|
@@ -631,37 +631,51 @@ class EnhancedGAIAAgent:
|
|
631 |
return None
|
632 |
|
633 |
async def solve_gaia_question(self, question_data: Dict[str, Any]) -> str:
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
Question: {question}
|
649 |
-
{'File downloaded: ' + file_path if file_path else 'No files referenced'}
|
650 |
-
|
651 |
-
Analyze this question and provide your reasoning and final answer.
|
652 |
-
"""
|
653 |
-
|
654 |
-
try:
|
655 |
-
from llama_index.core.workflow import Context
|
656 |
-
ctx = Context(self.coordinator)
|
657 |
-
raw_response = await self.coordinator.run(ctx=ctx, user_msg=context_prompt)
|
658 |
-
|
659 |
-
# Post-process to extract exact GAIA format
|
660 |
-
formatted_answer = await self.format_gaia_answer(str(raw_response), question)
|
661 |
-
|
662 |
-
print(f"Formatted answer: {formatted_answer}")
|
663 |
|
664 |
-
|
|
|
|
|
|
|
665 |
|
666 |
-
|
667 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
You have access to THREE specialist tools:
|
533 |
|
534 |
+
**1. analysis_tool** - Advanced multimodal document analysis specialist
|
535 |
- Use for: PDF, Word, CSV, image file analysis
|
536 |
- Capabilities: Extract data from tables/charts, cross-reference documents, semantic search
|
537 |
- When to use: Questions with file attachments, document analysis, data extraction
|
538 |
|
539 |
+
**2. research_tool** - Intelligent research specialist with automatic routing
|
540 |
- Use for: External knowledge, current events, scientific papers
|
541 |
- Capabilities: Auto-routes between ArXiv (scientific) and web search (general), extracts full content
|
542 |
- When to use: Questions requiring external knowledge, factual verification, current information
|
543 |
|
544 |
+
**3. code_tool** - Advanced computational specialist using ReAct reasoning
|
545 |
- Use for: Mathematical calculations, data processing, logical operations
|
546 |
- Capabilities: Generates and executes Python code, handles complex computations, step-by-step problem solving
|
547 |
- When to use: Precise calculations, data manipulation, mathematical problem solving
|
|
|
631 |
return None
|
632 |
|
633 |
async def solve_gaia_question(self, question_data: Dict[str, Any]) -> str:
|
634 |
+
question = question_data.get("Question", "")
|
635 |
+
task_id = question_data.get("task_id", "")
|
636 |
+
|
637 |
+
# Try to download file
|
638 |
+
try:
|
639 |
+
file_path = self.download_gaia_file(task_id)
|
640 |
+
except Exception as e:
|
641 |
+
print(f"Failed to download file for task {task_id}: {e}")
|
642 |
+
file_path = None
|
643 |
+
|
644 |
+
context_prompt = f"""
|
645 |
+
GAIA Task ID: {task_id}
|
646 |
+
Question: {question}
|
647 |
+
{'File downloaded: ' + file_path if file_path else 'No additional files referenced'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
648 |
|
649 |
+
Additionnal instructions to system prompt :
|
650 |
+
1. If a file is available, use the analysis_tool to process it
|
651 |
+
2. If a link is available, use the research_tool to extract the content in it
|
652 |
+
"""
|
653 |
|
654 |
+
try:
|
655 |
+
ctx = Context(self.coordinator)
|
656 |
+
|
657 |
+
# Use streaming to see step-by-step reasoning
|
658 |
+
print("=== AGENT REASONING STEPS ===")
|
659 |
+
handler = self.coordinator.run(ctx=ctx, user_msg=context_prompt)
|
660 |
+
|
661 |
+
full_response = ""
|
662 |
+
async for event in handler.stream_events():
|
663 |
+
if isinstance(event, AgentStream):
|
664 |
+
print(event.delta, end="", flush=True)
|
665 |
+
full_response += event.delta
|
666 |
+
|
667 |
+
# Get the final response
|
668 |
+
raw_response = await handler
|
669 |
+
print("\n=== END REASONING ===")
|
670 |
+
|
671 |
+
# Post-process to extract exact GAIA format
|
672 |
+
formatted_answer = await self.format_gaia_answer(str(raw_response), question)
|
673 |
+
|
674 |
+
print(f"Formatted answer: {formatted_answer}")
|
675 |
+
|
676 |
+
return formatted_answer
|
677 |
+
|
678 |
+
except Exception as e:
|
679 |
+
error_msg = f"Error processing question: {str(e)}"
|
680 |
+
print(error_msg)
|
681 |
+
return error_msg
|