JoachimVC's picture
Upload GAIA agent implementation files for assessment
c922f8b
#!/usr/bin/env python
"""
Script to update the GAIA agent with the fixed version.
This script backs up the original agent.py file and replaces it with the fixed version.
"""
import os
import sys
import shutil
import datetime
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(),
logging.FileHandler("update_agent.log", encoding="utf-8")
]
)
logger = logging.getLogger("update_agent")
def backup_file(file_path):
"""
Create a backup of a file.
Args:
file_path: Path to the file to backup
Returns:
Path to the backup file
"""
if not os.path.exists(file_path):
logger.error(f"File not found: {file_path}")
return None
# Generate backup filename with timestamp
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
backup_path = f"{file_path}.{timestamp}.bak"
try:
shutil.copy2(file_path, backup_path)
logger.info(f"Created backup: {backup_path}")
return backup_path
except Exception as e:
logger.error(f"Error creating backup: {str(e)}")
return None
def update_file(source_path, target_path):
"""
Update a file with the contents of another file.
Args:
source_path: Path to the source file
target_path: Path to the target file
Returns:
True if successful, False otherwise
"""
if not os.path.exists(source_path):
logger.error(f"Source file not found: {source_path}")
return False
try:
shutil.copy2(source_path, target_path)
logger.info(f"Updated file: {target_path}")
return True
except Exception as e:
logger.error(f"Error updating file: {str(e)}")
return False
def main():
"""Update the GAIA agent with the fixed version."""
# Define file paths
original_agent_path = "agent/agent.py"
fixed_agent_path = "agent/agent_fixed.py"
# Backup the original agent file
backup_path = backup_file(original_agent_path)
if not backup_path:
logger.error("Failed to create backup. Aborting update.")
sys.exit(1)
# Update the original agent file with the fixed version
if update_file(fixed_agent_path, original_agent_path):
logger.info("Successfully updated the GAIA agent with the fixed version.")
print(f"Original agent backed up to: {backup_path}")
print(f"Agent updated with fixed version.")
else:
logger.error("Failed to update the GAIA agent.")
sys.exit(1)
if __name__ == "__main__":
main()