File size: 1,074 Bytes
29f4cdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import List
from langchain_core.tools import tool
import subprocess


@tool
def add_dependencies(dependencies: List[str]) -> str:
    """
    Install the given Python packages into the environment.

    Parameters:
        dependencies (List[str]):
            A list of Python package names to install. Each name must match the 
            corresponding package name on PyPI.

    Returns:
        str:
            A message indicating success or failure.
    """

    try:
        subprocess.check_call(
            ["uv", "add"] + dependencies,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True
        )
        return "Successfully installed dependencies: " + ", ".join(dependencies)
    
    except subprocess.CalledProcessError as e:
        return (
            "Dependency installation failed.\n"
            f"Exit code: {e.returncode}\n"
            f"Error: {e.stderr or 'No error output.'}"
        )
    
    except Exception as e:
        return f"Unexpected error while installing dependencies: {e}"