File size: 1,967 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
#!/usr/bin/env python
"""
Fix for the ModuleNotFoundError: No module named 'langchain.tools.render' error.

This script patches the agent/graph.py file to remove the unused import that's
causing the runtime error.
"""

import os
import re
import sys
import logging

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

def patch_graph_file():
    """Patch the agent/graph.py file to remove the problematic import."""
    graph_file = "agent/graph.py"
    
    if not os.path.exists(graph_file):
        logger.error(f"Could not find {graph_file}")
        return False
    
    try:
        with open(graph_file, "r") as f:
            content = f.read()
        
        # Create a backup
        backup_file = f"{graph_file}.bak"
        with open(backup_file, "w") as f:
            f.write(content)
        logger.info(f"Created backup at {backup_file}")
        
        # Remove the problematic import
        pattern = r"from langgraph\.prebuilt import ToolNode\n"
        updated_content = re.sub(pattern, "# Removed problematic import: from langgraph.prebuilt import ToolNode\n", content)
        
        with open(graph_file, "w") as f:
            f.write(updated_content)
        
        logger.info(f"Successfully patched {graph_file}")
        return True
    
    except Exception as e:
        logger.error(f"Error patching file: {str(e)}")
        return False

def main():
    """Main function to run the patch."""
    logger.info("Starting graph.py import patch...")
    
    if patch_graph_file():
        logger.info("Patch applied successfully!")
        logger.info("This fixes the 'ModuleNotFoundError: No module named 'langchain.tools.render'' error")
        logger.info("by removing an unused import from agent/graph.py")
    else:
        logger.error("Failed to apply patch")
        return 1
    
    return 0

if __name__ == "__main__":
    sys.exit(main())