File size: 2,725 Bytes
c922f8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/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()