Update agent.py
Browse files
agent.py
CHANGED
@@ -402,61 +402,68 @@ code_agent = ReActAgent(
|
|
402 |
|
403 |
class EnhancedGAIAAgent:
|
404 |
def __init__(self):
|
405 |
-
|
406 |
|
407 |
-
#
|
408 |
-
|
409 |
-
|
410 |
-
|
|
|
|
|
|
|
|
|
|
|
411 |
system_prompt="""
|
412 |
-
You are the main GAIA
|
413 |
|
414 |
Your process:
|
415 |
-
1. THINK: Analyze the GAIA question
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
420 |
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
- Cross-Document Analysis: For multi-document reasoning and synthesis
|
425 |
-
- Python Code Execution: For calculations and data processing
|
426 |
|
427 |
-
|
|
|
|
|
428 |
""",
|
429 |
llm=text_llm,
|
430 |
tools=[
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
code_execution_tool
|
435 |
]
|
436 |
)
|
|
|
437 |
|
438 |
-
|
439 |
question = question_data.get("Question", "")
|
440 |
task_id = question_data.get("task_id", "")
|
441 |
|
442 |
-
# Prepare comprehensive context
|
443 |
context_prompt = f"""
|
444 |
GAIA Task ID: {task_id}
|
445 |
Question: {question}
|
446 |
|
447 |
-
{
|
448 |
|
449 |
Instructions:
|
450 |
-
1. Analyze this GAIA question
|
451 |
-
2.
|
452 |
-
3.
|
453 |
-
4. Synthesize findings into a precise, exact answer
|
454 |
-
5. Ensure your answer format matches GAIA requirements (exact, concise)
|
455 |
|
456 |
-
Begin your
|
457 |
"""
|
458 |
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
|
|
|
402 |
|
403 |
class EnhancedGAIAAgent:
|
404 |
def __init__(self):
|
405 |
+
print("Initializing Enhanced GAIA Agent...")
|
406 |
|
407 |
+
# Vérification du token HuggingFace
|
408 |
+
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
409 |
+
if not hf_token:
|
410 |
+
raise ValueError("HUGGINGFACEHUB_API_TOKEN environment variable is required")
|
411 |
+
|
412 |
+
# Agent coordinateur principal qui utilise les agents spécialisés comme tools
|
413 |
+
self.coordinator = ReActAgent(
|
414 |
+
name="GAIACoordinator",
|
415 |
+
description="Main GAIA coordinator that uses specialist agents as intelligent tools",
|
416 |
system_prompt="""
|
417 |
+
You are the main GAIA coordinator using ReAct reasoning methodology.
|
418 |
|
419 |
Your process:
|
420 |
+
1. THINK: Analyze the GAIA question thoroughly
|
421 |
+
- What type of information is needed?
|
422 |
+
- Are there files to analyze?
|
423 |
+
- Do I need research, analysis, or calculations?
|
424 |
+
|
425 |
+
2. ACT: Use your specialist agents IF RELEVANT
|
426 |
+
- AnalysisAgent: ONLY for documents, images, files, or multimodal content
|
427 |
+
- ResearchAgent: ONLY for web search, scientific papers, factual information
|
428 |
+
- CodeAgent: ONLY for calculations, data processing, mathematical operations
|
429 |
|
430 |
+
3. OBSERVE: Review results from specialist agents
|
431 |
+
4. THINK: Determine if you need more information or can provide final answer
|
432 |
+
5. ACT: Either use another agent or provide final precise answer
|
|
|
|
|
433 |
|
434 |
+
IMPORTANT: Use agents strategically - only when their specific expertise is needed.
|
435 |
+
For simple questions, you can answer directly without using any agents.
|
436 |
+
Always provide EXACT, CONCISE answers as required by GAIA format.
|
437 |
""",
|
438 |
llm=text_llm,
|
439 |
tools=[
|
440 |
+
analysis_agent, # Agent spécialisé comme tool
|
441 |
+
research_agent, # Agent spécialisé comme tool
|
442 |
+
code_agent # Agent spécialisé comme tool
|
|
|
443 |
]
|
444 |
)
|
445 |
+
print("Coordinator agent initialized")
|
446 |
|
447 |
+
def solve_gaia_question(self, question_data: Dict[str, Any]) -> str:
|
448 |
question = question_data.get("Question", "")
|
449 |
task_id = question_data.get("task_id", "")
|
450 |
|
|
|
451 |
context_prompt = f"""
|
452 |
GAIA Task ID: {task_id}
|
453 |
Question: {question}
|
454 |
|
455 |
+
{f"Associated files: {question_data.get('file_name', '')}" if 'file_name' in question_data else 'No files provided'}
|
456 |
|
457 |
Instructions:
|
458 |
+
1. Analyze this GAIA question using ReAct reasoning
|
459 |
+
2. Use specialist agents ONLY when their specific expertise is needed
|
460 |
+
3. Provide a precise, exact answer in GAIA format
|
|
|
|
|
461 |
|
462 |
+
Begin your reasoning process:
|
463 |
"""
|
464 |
|
465 |
+
try:
|
466 |
+
response = self.coordinator.chat(context_prompt)
|
467 |
+
return str(response)
|
468 |
+
except Exception as e:
|
469 |
+
return f"Error processing question: {str(e)}"
|